Sunday, 27 November 2016

Doubly linked list - IMPLIMENTATION

Tags
#include<stdio.h>
#include<conio.h>
#include<alloc.h>
struct node{
int data;
struct node*next;
struct node*prev;
}*head;
void addbeg(int x)
{
struct node*temp;
temp=(struct node*)malloc(sizeof(struct node));
temp->data=x;
temp->prev=NULL;
temp->next=head;
if(head!=NULL)
{
head->prev=temp;
}
head=temp;
}
void print()
{
struct node*temp;
temp=head;
printf("\n list is:\n");
while(temp!=NULL)
{
printf("%d",temp->data);
temp=temp->next;
}
printf("\n");
}
void main( )
{
head=NULL;
printf("\n how many numbers?\n");
int n,i,x;
scanf("%d",&n);
for(i=0;i<n;i++)
{
printf("\n enter the number");
scanf("%d",&n);
addbeg(x);
print();
}
}
getch();


Thursday, 24 November 2016

linked list-addition in beggining.

Tags
#include<conio.h>
#include<stdio.h>
#include<alloc.h>
struct node
{
int data;
struct node*next;
};
struct node*head;
void insert(int x)
{
struct node*temp=(node*)malloc(sizeof(struct node));
temp->data=x;
temp->link=head;
head=temp;
}
void display()
{
struct node*temp=head;
printf("list is:");
while(temp!=NULL)
{
printf("%d",temp->data);
temp=temp->next;
}
printf("\n");
}
void main()
{
head=NULL;
printf("how many numbers?\n");

int n,i,x;
scanf("%d",&x);
display();
}

getch();
}


Sunday, 13 November 2016

write a program to draw line using DDA line algorithm in c

Tags
#include<stdio.h>
#include<conio.h>
#include<graphics.h>
#include<math.h>
void main()
{
 int x,y,xi,yi,x1,y1,y2,x2,i,s;
clrscr();
 int gd=DETECT,gm;
 initgraph(&gd,&gm,"C:\\tc\\")

 printf("enter value of x1:");
 scanf("%d",&x1);
 printf("enter value of y1:");
 scanf("%d",&y1);
  printf("enter value of x2:");
 scanf("%d",&x2);
 printf("enter value of y2:");
 scanf("%d",&y2);

 dx=x2-x1;
 dy=y2-y1;

 if(abs(dx)>abs(dy))
 {
  s=abs(dx);

 }
 else{
  s=abs(dy);
 }

 xi=dx/s;
 yi=dy/s;

 x=xi;
 y=yi;

 putpixel(xi,yi,4);
    for(i=0;i<s;i++)
    {
     x+=x1;
     y+=y1;
   
     putpixel(x1,y1,4);
   
 }
 closegraph();
 getch();
}

Saturday, 12 November 2016

Input & Output funtions

Tags

Input and output instruction  in c language.



printf() and scanf() are input and output instruction in C language.

Both are written in small alphabets because c is case sensitive language.

printf():- printf() is predefined functions. It is not a keyword.we can use printf() to print text as it is and we also print value of expression or value of variables.

So, printf() is a function in which you can write anything in paranthesis with double codes.

Ex;

main()

{

clrscr();//it erases old content and it clears screen

printf(“anything you want to print \n”);//\n is used as new line character

printf(“sachin”);

getch();//taking one character.

}

Note:-In output screen maximum 80 character print horizontally in one line and and 25 line vertically.



gotoxy(25,13)// this function is used to find your cursor in any area in your output screen.

/* format specifier

%d for integers.

%f for float.

%lf for double.

*/



scanf():-

scanf() is predefined function which is used to take input from user



ex;

main()

{



Int n;

Clrscr();

scanf(“%d”,n);

getch();

}




Saturday, 5 November 2016

insertion sort

Tags
#include<stdio.h>
#include<conio.h>
void main()
{
clrscr();
int n, a[100] , i , k, j, temp , flag=0;
clrscr();
printf("enter no of elements");//taking input from user
scanf("%d",&n);
printf(enter %d integers:\n");
for(i=0;i<n;i++)
{
scanf("%d",&a[i]);
}
for(i=1;i<=n-1;i++)
{
temp=a[i];
for(j=0;j<=i-1;j++)
{
if(a[i]<a[j])
{
for(k=i-1;k>=j;k--)
a[k+1]=a[k];
a[j]=temp;
f=1;
}
if(f==1)
break;
}
}
printf("\n after sorting");
for(i=0;i<n;i++)
printf("%d",a[i]);
getch();
}





Tuesday, 1 November 2016

bubble sort using c

Tags
#include<stdio.h>
#include<conio.h>
void main()
{


int a[20],i,j,temp,n;
printf("\n enter array size");
scanf("%d",&n);
printf("array elements are:\n",n);
for(i=0;i<n:i++)
printf("\n%d",a[i]);
for(i=0;i<=j;i++)
for(i=0;i<=j;i++)
if(a[i]>a[i+1])
{
temp=a[i];
a[i]=a[i+1];
a[i+1]=temp;
}
printf("\n after sorting:\n");
for(i=0;i,n;i++)
printf("\n%d",&a[i]);
}
getch();