Posts

Showing posts from April, 2015

Circular Queue using Linked List ....

#include<stdio.h> #include<conio.h> typedef struct circular { int val; struct circular *next; }cir; cir *createnode(cir *,int ); void enqueue(cir **,int); int dequeue(cir **); int isempty(cir *); int peek(cir *); void disp(cir *); void main()  {  cir *h=NULL;  int v,p;  while(1)  {  printf("\n 1.insert \n2.delete \n3.peek \n4.display \n5.exit");  printf("enter the choice");  scanf("%d",&p);  switch(p)  {  case 1:printf("enter the value"); scanf("%d",&v); enqueue(&h,v); break;  case 2:printf("deleted value is:"); scanf("%d",&v); break;  case 3:printf("front value: "); scanf("%d",&v); break;  case 4:printf("display the value"); disp(h); break;  case 5: exit(0);  default:printf("not a proper choice");  }  }  }  cir *createnode(cir *h,int v)  {  cir *ptr,*temp;  temp=(cir*)malloc(sizeof(c...

Polynomial Addition using Linked List

#include<stdio.h> #include<stdlib.h> typedef struct poly { int coff,powr; struct poly *next; }pl; void addnode(pl **, int ,int); void creatpoly(pl **); void addpoly(pl *,pl *,pl **); void display(pl *); void main() { int n; pl *pl1,*pl2,*pl3; pl1=pl2=pl3=NULL; clrscr(); printf("\nEnter 1st Polynomial\n"); creatpoly(&pl1); display(pl1); printf("\nEnter 2nd Polynomial\n"); creatpoly(&pl2); display(pl2); printf("\nSum Poly\n"); addpoly(pl1,pl2,&pl3); display(pl3); getch(); } void creatpoly(pl **ptr) {    int cof,pow,temp=10;    char ch;    while(1)    { printf("\nEnter Coff of X : "); scanf("%d",&cof); printf("\nEnter Powr of X : "); scanf("%d",&pow); if(pow<temp) addnode(ptr,cof,pow); else { printf("\nPower must be lesser than the previous term :"); continue; } temp=pow; printf("\nDo you ...

Queue using structure

#include<stdio.h> #include<conio.h> #include<stdlib.h> #define max 50 typedef struct queue    {     int ar[max];     int rear,front;    }qu;      void enqueue(qu *ps,int a);    int dequeue(qu *ps);    int isempty(qu *ps);    int isfull(qu *ps);    int peek(qu *ps);    void disp(qu *ps);    void init(qu *ps);      int main()    {     qu q;     int x,val;     init(&q);     while(1)      {     printf("press \n 1.enter\n2.delete\n3.Peek\n4.Display\n5.Exit\n");     scanf ("%d",&x);     switch(x)      {       case 1: if(!isfull(&q))              {               printf("ente...

Operations of Linear Linked List ...

#include<stdio.h> #include<conio.h> #include<stdlib.h> typedef struct linked {     int val;     struct linked *next; }lnk; lnk *create(lnk*,int); lnk *insertbefore(lnk*,int); void insertafter(lnk*,int); lnk *del(lnk*,int); void disp(lnk*); void main() {     lnk *h=NULL;     int v,ch;     while(1)     { printf("\n===================================="); printf("\n1)Create\n2)Insert Before\n3)Insert After\n4)Delete\n5)Display\n6)Exit"); printf("\n===================================="); printf("\n\nEnter your choice:"); scanf("%d",&ch); switch(ch) {    case 1: printf("\nEnter the value you want to enter:");    scanf("%d",&v);    h=create(h,v);    break;    case 2: printf("\nEnter the value before which you want to Insert:");    scanf("%d", &v);    h=insertbefore(h,v); ...

Highest total marks holder using Structure

#include<stdio.h> #include<conio.h> struct Student {        int roll;        char name[25];        char addr[25];        int mark[5];        int total;        float avg;        char grad;        };       int checkHighest(struct Student [],int); void getVal(struct Student [],int); void printDetail(struct Student [],int); int main() {      struct Student std[50];      int m,t,i;          printf("\nEnter the number of students :");      scanf("%d",&m);      printf("\nEnter the student details : ");          getVal(std,m);              printf("\nStudent details : ");      for(i=0;i<m;i++)      ...

Highest marks in a particular subject using structure ....

#include<stdio.h> #include<conio.h> struct Student {        int roll;        char name[25];        char addr[25];        int mark[5];        int total;        float avg;        char grad;        };       void getVal(struct Student [],int); void printDetail(struct Student [],int); int checkSubHighest(struct Student [],int,int); int main() {      struct Student std[50];      int m,t,i,p;          printf("\nEnter the number of students :");      scanf("%d",&m);      printf("\nEnter the student details : ");          getVal(std,m);              printf("\nStudent details : ");      for(i=0;i<m;i++)   ...

use of malloc() function ....

#include<stdio.h> #include<conio.h> int main() {      int *ptr,n,i;          printf("Enter the number of elements : ");      scanf("%d",&n);          ptr=(int *)malloc(n*sizeof(int));      printf("Enter the elements : ");          for(i=0;i<n;i++)      scanf("%d",(ptr+i));          printf("Elements are : ");      for(i=0;i<n;i++)      printf("%d",*(ptr+i));      system("pause");  } input: Enter the number of elements : 4 Enter the elements : 2 3 4 ouput :  Elements are : 2 3 4

use of calloc() function ....

#include<stdio.h> #include<conio.h> int main() {      int *ptr,n,i;          printf("Enter the number of elements : ");      scanf("%d",&n);          ptr=(int *)calloc(n,sizeof(int));      printf("Enter the elements : ");          for(i=0;i<n;i++)      scanf("%d",(ptr+i));          printf("Elements are : ");      for(i=0;i<n;i++)      printf("%d",*(ptr+i));      system("pause");  } input: Enter the number of elements : 4 Enter the elements : 2 3 4 ouput :  Elements are : 2 3 4 Result analysis : this code will help you to understand the use of calloc(). this function takes two parameters one is the number of elements and second is the size of the datatype. here I have used 'n' as the number of variable purpose. ...
write a c program to insert values into an array without pressing enter key after each digit.... #include<stdio.h> int sumdig(); void main() { clrscr(); printf("Summation is : %d",sumdig()); getch(); } int sumdig() { int s=0,i=0,ar[10],j; char ch; printf("Enter the values: "); while(1) { ch=getche(); if(ch==13) break; ar[i++]=ch-'0'; } for(j=0;j<i;j++) { s=s+ar[j]; } clrscr(); return s; } input: Enter the values : 231 output: Summation is : 6 result analysis:    while(1) means the loop will be executed infinite times if we don't put any stop condition. It will take one element from the keyboard and put them into a character variable called 'ch'. Here 0,1,2 ....9 ... will be treated as character. To convert them into integer we need to subtract ASCII value of the '0' from the character. (ie. ASCII value of '1' is 49 . If we subtract ASCII value of '0' means 48 from 49 i...

Password Checking in C

how to write a password checking program in C: int password(); void main() { if(password()) printf("U r a valid user"); else printf("U r not a valid user"); } int password() {    char ch,str[50]; int i=0; printf("enter ur password : "); while(1) {         ch=getch();                 if(ch==13)         break;          printf("*");         str[i++]=ch;         }               str[i]='\0';         if(strcmp(str,"kumar")) return 0; else return 1; } Input : Enter ur password : ***** output : U r a valid user result analysis: whenever u r pressing a character/key getch() will be invoked. the character will be stored into ch. then the character will be transferred to the str[] one by one and during this operation * will be printed on t...

scanf function

What scanf function do? void main() { int a,b; printf("%d,%d,%d",scanf("%d %d",&a,&b)); } run this program in Turbo C compiler ... Input: 12 23 Output : 2 23 12 Result Analysis : scanf function accept number(s) from the keyboard and store them into a stack. From left to right the accepted values will be stored into stack. scanf will also store the total number of format string used in the scanf (i.e 2). due to stack the top most value will be 2 next value will be 23 and the value at the bottom will be 12. | 2 | ---- |23| ---- |12| ---- stack will look like above figure.