WAP which will input only 2 nos. Also input your choice : If choice = 1 then display sum of 2 nos, If choice=2 display substract, If choice=3 display Multiplication, If choice=4 Division, if choice=5 Display Power of 2 nos ? #include <stdio.h> #include <math.h> main() { float a,b,c; int op; clrscr(); printf("Enter 2 nos"); scanf("%f %f",&a,&b); printf("Enter your option: 1=sum: 2=sub: 3=mul: 4=Div: 5=pow"); scanf("%d",&op); switch(op) { case 1: c=a+b;break; case 2: c=a-b;break; case 3: c=a*b;break; case 4: c=a/b;break; case 5: c=pow(a,b);break; default: printf("Your choice is wrong"); exit(); } printf("Result is %.2f",c); getch(); } 2. WAP to find a number is odd or even, prime or not, armstrong or not, factorial ? #include<stdio.h> // use for printf, scanf function #include
// use for getch,clrscr function #include<stdlib.h> // use for exit function #include<math.h> // use for pow function void main() { int i,a,ch,f,t2; do { clrscr(); printf("\n\n\t\t\t Main Menu"); printf("\n\nPress 1 to Factorial of a number"); printf("\nPress 2 to check a number is prime or not"); printf("\nPress 3 to check a number is odd or even"); printf("\nPress 4 to check of a number is armstrong or not"); printf("\nPress any other number to exit..."); printf("\n\nEnter you choice : "); scanf("%d",&ch); if(ch>0 && ch<5) {
printf("\n\nEnter a number = "); scanf("%d",&a); } switch(ch) { case 1: printf("\n\n Factorial of %d are \n",a); for(i=1;i<=a;i++) { if ( a%i==0) printf(" %d ",i); } break ; case 2: f=0; printf("\n\n Prime checking...... \n"); for(i=2;i<pow(a,.5)+1;i++) { if ((a%i)==0) f=1; } if (f==1) printf("\n%d is not prime number... ",a); else printf("\n%d is prime number... ",a); break; case 3: printf("\n\n Odd or Even checking...... \n"); if ((a%2)==0) printf("\n%d is even number... ",a); else printf("\n%d is odd number... ",a); break; case 4: f=0; t2=0; printf("\n\n Armstrong checking...... \n"); i=a; while(i!=0) { t2=t2+pow((i%10),3); i=i/10; } if (a==t2) printf("\n%d is Armstrong number... ",a); else printf("\n%d is not Armstrong number... ",a); break; default: exit(0); }; printf("\n\n\n\nPress any key to contiune........"); getch(); }while(ch>0 && ch<5); }
Loop 1. Calculate & Display Sum + Multiplication of Multiple Nos (1+2+3+4+5....) ? #include <stdio.h> #include <math.h> main() { int i,n,s=0,m=1; clrscr(); printf("Enter no of terms : "); scanf("%d",&n); printf("The series are :"); for(i=1;i<=n;i++) printf("%4d",i); for(i=1;i<=n;i++) { s=s+i; m=m*i; } printf("\nSum is %d",s); printf("\nMul is %d",m); getch(); } 2. Calculate & Display Sum + Multiplication of Odd Nos ? #include <stdio.h> #include <math.h> main() { int i,n,s=0,m=1; clrscr(); printf("Enter no of terms : "); scanf("%d",&n); printf("The series are :"); for(i=1;i<=n;i++) printf("%4d",2*i-1); for(i=1;i<=n;i++) { s=s+(2*i-1); m=m*(2*i-1); } printf("\nSum is %d",s); printf("\nMul is %d",m); getch(); } 3. Lucas Series #include <stdio.h> main() { int a=0,b=1,c=1,i,n,t; clrscr(); printf("Enter no of terms : "); scanf("%d",&n); printf("The Lucas series is : %4d %4d %4d",a,b,c);
for(i=4;i<=n;i++) { t=a+b+c; printf("%4d",t); a=b; b=c; c=t; } getch(); } 4. Display N nos in the following format ? #include <stdio.h> main() { int i,n,j; clrscr(); printf("Enter no of terms : "); scanf("%d",&n); for(i=1;i<=n;i++) { for(j=i;j main() { int i,n,j; clrscr(); printf("Enter no of terms : "); scanf("%d",&n); for(i=1;i<=n;i++) { for(j=i;j main() {
1 12 123 1234
A A BC A B C D E
int a[100],i,n,s=0; float av; clrscr(); printf("Enter no of terms : "); scanf("%d",&n); printf("Enter elements"); for(i=0;i main() { int a[100],i,n,m; clrscr(); printf("Enter no of terms : "); scanf("%d",&n); printf("Enter elements"); for(i=0;im) m=a[i]; printf("\n Max no is %d",m); getch(); } 3. 25 nos are entered through keyboard. Count how many nos are Positive and Negative ? #include <stdio.h> main() { int a[25],i,pos=0,neg=0; clrscr(); printf("Enter elements"); for(i=0;i<=24;i++) scanf("%d",&a[i]); for(i=0;i<=24;i++) if(a[i]>=0) pos++; else neg++; printf("\n Positive no is %d",pos); printf("\n Negative no is %d",neg); getch(); }
4. Display array in ascending order ? #include <stdio.h> main() { int a[100],i,n,j,t; clrscr(); printf("Enter no of terms"); scanf("%d",&n); printf("Enter elements"); for(i=0;ia[j]) { t=a[i]; a[i]=a[j]; a[j]=t; } printf("\n The Ascending Order is :"); for(i=0;i main() { long int a,s=0; clrscr(); printf("Enter no :"); scanf("%ld",&a); printf("The Reverse No is :"); while(a!=0) { s=s+(a%10); printf("%ld",a%10); a=a/10; } printf("\nSum is %ld",s); getch(); } 6. WAP which will input many nos. Search by any no & count how many times that no. appear? #include <stdio.h> main() { int a[100],i,n,m,t=0; clrscr(); printf("Enter no of terms:"); scanf("%d",&n); printf("Enter elements"); for(i=0;i
printf("Enter no to search"); scanf("%d",&m); for(i=0;i main() { char a[100],b[100]; int i,l,j=0; clrscr(); printf("Enter string:"); gets(a); l=strlen(a); for(i=l-1;i>=0;i--) { b[j]=a[i]; j++; } b[j]='\0'; printf("Reverse String is : "); puts(b); printf("Length is : %d",l); getch(); } 8. Character Ascending ? #include <stdio.h> #include <string.h> main() { char a[100][20],t[20]; int i,j,n; clrscr(); printf("Enter how many name"); scanf("%d",&n); printf("Enter name one by one :"); for(i=0;i<=n;i++) gets(a[i]); for(i=0;i0) { strcpy(t,a[i]); strcpy(a[i],a[j]); strcpy(a[j],t); } printf("Name in ascending order"); for(i=0;i<=n;i++) puts(a[i]); printf("\n");
getch(); } String 1. WAP which will input a string calculate No. of vowel, No. of Blank Spaces, No of alphabets, No. of Digit, No. of Special Character of that string ? #include <stdio.h> main() { int i,l=0,v=0,d=0,b=0; char a[100]; clrscr(); printf("Enter character: "); gets(a); for(i=0;a[i]!='\0';i++) { if(toupper(a[i])=='A' || toupper(a[i])=='E' || toupper(a[i])=='I' || toupper(a[i])=='O' || toupper(a[i])=='U') v++; if(toupper(a[i])>='A' && toupper(a[i])<='Z') l++; if(a[i]>='0' && a[i]<='9') d++; if(a[i]==' ' && a[i+1]!=' ') b++; } printf("vowel is: %d",v); printf("\nNo of alphabet %d",l); printf("\n No of digit %d",d); printf("\n No of Blank Spaces %d",b); printf("\nSpecial Character=%d",i-d-l-b); getch(); } 2. WAP which will input amal kumar halder . Display like A.K.HALDER ? #include <stdio.h> #include <string.h> main() { char a[100]; int i,l,x,y; clrscr(); printf("Enter String:"); gets(a); l=strlen(a); for(i=1;i
} printf("short form is : %c.",toupper(a[0])); printf("%c.",toupper(a[x+1])); for(i=y+1;i #include <string.h> main() { char a[100],b[100]; int i,l,j=0; clrscr(); printf("Enter String:"); gets(a); l=strlen(a); for(i=l-1;i>=0;i--) { b[j]=a[i]; j++; } b[j]='\0'; if(strcmpi(a,b)==0) printf("String is Palindram"); else printf("Not Palindram"); getch(); } 3. WAP which will change the case of a character (Upper to lower or vice versa) ? #include <stdio.h> #include <string.h> main() { char a[80]; int i; clrscr(); printf("Enter Character: "); gets(a); for(i=0;a[i]!='\0';i++) if(a[i]>='A' && a[i]<='Z') printf("%c",a[i]+32); else if(a[i]>='a' && a[i]<='z') printf("%c",a[i]-32); getch(); }
(For Lower Case) (For Upper Case)
Function 1. WAP which will input any no. Find the frequency of any particular no ? #include <stdio.h> main() {
int a[80],i,n,m,c=0; clrscr(); printf("Enter no of terms: "); scanf("%d",&n); printf("Enter elements"); for(i=0;i main() { int n,f; clrscr(); printf("Enter no: "); scanf("%d",&n); f=fact(n); printf("Factorial is %d",f); getch(); } fact(int n) { if(n==1) return(1); else return(n*fact(n-1)); } 3. Sum of Even Nos ? #include <stdio.h> main() { int n,s; clrscr(); printf("Enter no: "); scanf("%d",&n); s=sum(n); printf("sum is %d",s); getch(); } sum(int n) {
if(n==1) return(1); else return((2*n-1)+sum(n-1)); } 4. GCD of 2 Nos ? #include <stdio.h> main() { int a,b,p,g; clrscr(); printf("Enter 2 nos: "); scanf("%d %d",&a,&b); if(a main() { long int a; clrscr(); printf("Enter the no: "); scanf("%ld",&a); rev(a); getch(); } rev(long int a) { if(a==0) return; else printf("%ld",a%10); return(rev(a/10)); } 6. Enter radius of a sphere. Calculate area & perimeter ? #include <stdio.h> #include <math.h> main() {
int r; float a,p; clrscr(); printf("Enter radius: "); scanf("%d",&r); a=area(r); p=peri(r); printf("Area is %.2f",a); printf("Perimeter is %.2f",p); getch(); } area(int r) { float a; a=22/7.0*r*r; return(a); } peri(int r) { float p; p=2*22/7.0*r; return(p); } 7. Fibonacci Series ? #include <stdio.h> main() { int a=1,b=0,i=0; printf("Fibonacci Series is :"); fibo(a,b,i); getch(); } fibo(int a,int b,int i) { if(i==25) return; else { printf("%4d",a+b); return(fibo(b,a+b,++i)); } } 8. Character Reverse ? #include <Stdio.h> main() { char a[30]; int l; clrscr(); printf("Enter string: "); gets(a); l=strlen(a); printf("Reverse String is :"); rev(a,l);
getch(); } rev(char a[],int l) { if(l==0) return; else { printf("%c",a[l-1]); return(rev(a,--l)); } } 9. Input Ratan Saha . Display Saha Ratan #include <stdio.h> main() { char a[30]; clrscr(); printf("Enter string: "); gets(a); name(a); getch(); } name(char a[]) { int i,b; for(i=0;a[i]!='\0';i++) if(a[i]==' ') b=i; printf("The Name is : "); for(i=b+1;a[i]!='\0';i++) printf("%c",a[i]); printf(" "); for(i=0;i #include main() { int *a,n,i; clrscr(); printf("Enter no of terms:"); scanf("%d",&n); a=(int *)(malloc(sizeof(int)*n)); printf("Enter Element: "); for(i=0;i
for(i=0;i #include main() { int *a,i,n,m; clrscr(); printf("Enter no of terms: "); scanf("%d",&n); a=((int*)malloc(sizeof(int)*n)); printf("Enter elements"); for(i=0;i*m) *m=*(a+i); return; } 3. WAP which will input 2 string ? Display it in the 3rd String (Concatenate) ? #include <stdio.h> #include main() { char *s1,*s2,*s3; clrscr(); s1=malloc(20); s2=malloc(20); s3=malloc(40); printf("Enter 1st String: ");
gets(s1); printf("Enter 2nd String: "); gets(s2); join(s1,s2,s3); printf("\n1st String is %s",s1); printf("\n2nd String is %s",s2); printf("\n3rd String is %s",s3); getch(); } join(char *s1, char *s2, char *s3) { while(*s1!='\0') { *s3=*s1; s1++; s3++; } while(*s2!='\0') { *s3=*s2; s2++; s3++; } *s3='\0'; return; } 4. Input 2 string. Compare both of them. (1st string>2nd string)- Result 1 (1st string<2nd string)- Result –1 (1st string=2nd string)- Result 0 #include <stdio.h> #include main() { char *s1,*s2; int l; s1=malloc(20); s2=malloc(20); printf("Enter 1st"); gets(s1); printf("Enter 2nd"); gets(s2); l=rev(s1,s2); printf("Result is %d",l); getch(); } rev(char *s1,char *s2) { int l1=0,l2=0,l; for(l1=0;*(s1+l1)!='\0';l1++) for(l2=0;*(s2+l2)!='\0';l2++) { if(l1>l2) l=1; else if(l1
else l=0; } return(l); } 6. Input a string. Create another string which contain reverse of 1st string ?
#include <stdio.h> #include <string.h> #include main() { char s1[20],*s2; s2=malloc(20); printf("Enter string"); gets(s1); rev(s1,s2); printf("Original string %s",s1); printf("\nReverse string %s",s2); getch(); } rev(char *s1,char *s2) { int i,l; l=strlen(s1); for(i=l-1;i>=0;i--) { *s2=*(s1+i); *s2++; } *s2='\0'; } Alltrim #include <stdio.h> #include main() { char *s1; clrscr(); s1=malloc(20); printf("enter a string:"); gets(s1); printf("original is @%s@",s1); printf("\nalltril is @%s@",allt(s1)); getch(); } allt(char *s1) { int l,i; while(*s1==' ') s1++; l=strlen(s1); for(i=l-1;i>=0;i--)
if(*(s1+i)!=' ') break; *(s1+i+1)='\0'; return(s1); } Structure #include <stdio.h> struct atanu { int r; char nm[30]; char cr[10]; int s[3]; int t; }new; main() { int i,n; clrscr(); printf("Enter Roll:"); scanf("%d",&new.r); fflush(stdin); printf("Enter Name:"); gets(new.nm); printf("Enter Course:"); gets(new.cr); printf("Enter Marks:"); new.t=0; for(i=0;i<3;i++) { scanf("%d",&new.s[i]); new.t=new.t+new.s[i]; } printf("Roll is:%d",new.r); printf("\nName is:"); puts(new.nm); printf("\nCourse is:"); puts(new.cr); printf("\nSubjects are:"); for(i=0;i<3;i++) printf("%4d",new.s[i]); printf("\nTotal is %4d",new.t); getch(); } 2. #include <stdio.h> struct atanu { int r; char nm[20]; char cr[20];
int s[4]; int t; char g; }new[30]; main() { int i,j,n; printf("Enter no of record:"); scanf("%d",&n); for(i=0;i240) new[i].g='A'; else if(new[i].t<240&&new[j].t>200) new[i].g='B'; else new[i].g='F'; } printf("Roll\t Name\t Course\t Sub1\t Sub2\t Sub3\t Total\t Grade\n"); for(i=0;i typedef struct atanu {
char cd[6]; char nm[20]; float bal; }atanu; main() { atanu new; FILE *f; int n,i; clrscr(); f=fopen("atanu.txt","w"); printf("enter no of records"); scanf("%d",&n); for(i=0;i #include typedef struct atanu { int data; struct atanu *link; }node; node *head; main() { int op=0; while(op!=5) { printf("\n1.Create 2.Insert 3.Delete 4.Display 5. Exit"); scanf("%d",&op); switch(op) { case 1: create(); break; case 2: insert(); break;
case 3: delete(); break; case 4: display(); } } } create() { int x; node *p; printf("Enter any value(0 to stop)"); scanf("%d",&x); p=(node *) malloc(sizeof(node)); head=p; while(x!=0) { p->data=x; printf("Enter any Value"); scanf("%d",&x); if(x==0) break; p->link=(node*) malloc(sizeof(node)); p=p->link; } p->link=NULL; return; } insert() { node *p,*new; int x,y; printf("Enter any value"); scanf("%d",&x); printf("Enter element after insert"); scanf("%d",&y); p=head; while(p->data!=y && p->link!=NULL) p=p->link; new=(node *) malloc(sizeof(node)); if(p->data==y) { new->data=x; new->link=p->link; p->link=new; } return; } delete() { int x; node *p,*q;
printf("Enter element to be deleted"); scanf("%d",&x); if(head->data==x) { head=head->link; return; } p=head; while(p->data!=x && p->link!=NULL) { q=p; p=p->link; } if(p->data==x) { q->link=p->link; free(p); } else printf("Data is not found"); return; } display() { node *p; p=head; printf("The Elements are"); while(p!=NULL) { printf("%4d",p->data); p=p->link; } return; }