Anda di halaman 1dari 31

WAP that lets user enter a number ,print the next four continous number.

#include<Stdio.h> void main() { int i,j,num; printf("enter a number:"); scanf("%d",&num); for(i=0;i<4;i++) { num++; printf(" %d ",num); } }

WAP to input any character in lower case and print its upper case letter

#include<Stdio.h> void main() { char a,b; printf("enter a character:"); scanf("%c",&a); b=a-32; printf("%c",b); }

WAP that swaps two numbers without using a third variable


#include<stdio.h> void main() { int a,b; printf("enter two numbers:"); scanf("%d %d",&a,&b); a=a+b; b=a-b; a=a-b; printf("%d %d",a,b); }

WAP to find the largest value among any four numbers

#include<stdio.h> void main() { int a,b,c,d,e,f,g; printf("enter 4 nos:"); scanf("%d %d %d %d",&a,&b,&c,&d); e=(a>b)? a:b; f=(c>d)? c:d; g=(e>f)? e:f; printf("the greatest no is:-%d",g); }

WAP a program to find out whether a year is a leap year or not

#include<stdio.h> void main() { int a,b; printf("enter a year:"); scanf("%d",&a); if(a%100==0) { if(a%400==0) { printf("the year is leap year"); } else { printf("the year is not leap year"); } } else { if (a%4==0) { printf("the year is leap year"); } Else { printf("it is not leap year"); } } }

WAP to find the factorial of a number

#include<stdio.h> void main() { int a,d=1; printf("enter 1 no:"); scanf("%d",&a); while(a>1) { d=d*a; a--; } printf("%d",d); }

WAP to find the sum of eseries

/*sum of e series*/ #include<stdio.h> #include<conio.h> void main() { int i=1,j,n; float fact,sum=1.0; clrscr(); printf("How many terms?"); scanf("%d",&n); while(i<=n) { fact=1.0; for(j=1;j<=i;j++) fact=fact*j; sum=sum+i/fact; i++; } printf("\n Sum of series=%f",sum); getch(); }

WAP to print the fibonacci series

/*print Fibonacci series*/ #include<stdio.h> #include<conio.h> void main() { int a,b,c,x; clrscr(); printf("Enter the final term"); scanf("%d",&x); a=0; b=1; printf("%d\t%d",a,b); c=a+b; while(c<=x) { printf("\t%d",c); a=b; b=c; c=a+b; } getch(); }

WAP to find the reverse of the number entered

#include<stdio.h> void main() { int n,a,x=0; printf("enter a no:"); scanf("%d",&a); while(a>0) { n=a%10; x=x*10+n; a=a/10; } printf("%d",x); }

WAP to find whether a number entered is armstrong or not.if the sum of cube of the digits of a number is equal to the number then it is called an armstrong number

#include<stdio.h> #include<math.h> void main() { int a,s=0,n,p; printf("enter a no:"); scanf("%d",&a); p=a; while(a>0) { n=a%10; n=pow(n,3); s=s+n; a=a/10; } if(p==s) { printf("It is an armstrong number"); } else { printf("it is not an armstrong no"); } }

WAP to generat the following pattern* * * * * * ..n

#include<Stdio.h> void main() { int i,j,k; for(i=0;i<3;i++) { for(j=i;j<3;j++) printf(" "); for(k=0;k<=i;k++) { printf("* "); } printf("\n"); } printf("...........n"); }

WAP to generate the following patterA BC DEF .n

#include<stdio.h> void main() { int i,j,k; k=65; for(i=0;i<3;i++) { for(j=0;j<=i;j++) { printf("%c",k); k++; } printf("\n"); } }

WAP to generate prime numbers upto users choice

#include<stdio.h> void main() { int a,b,i,j,f; printf("enter 2 nos:"); scanf("%d %d",&a,&b); for(i=a;i<=b;i++) { f=0; for(j=1;j<=i;j++) { if(i%j==0) { f++; } } if(f==2) { printf("\t%d",i); } } }

WAP to find the hcf of the number entered

/* HCF of number entered*/ #include<stdio.h> #include<conio.h> void main() { int a,b,x,i; clrscr(); printf("Enter Two Number:"); scanf("%d%d",&a,&b); for(i=1;i<a*b;i++) { if(a%i==0 && b%i==0) x=i; } printf("\nHCF of the number is %d",x); getch(); }

Wap to find the lcm of two numbers entered by the user

#include<stdio.h> void main() { int a,b,c=1,d=2; printf("enter 2 nos:"); scanf("%d %d",&a,&b); l1: while(a%d==0&&b%d==0) { a=a/d; b=b/d; c=c*d; } if(a>d) { d++; goto l1; } c=c*a*b; printf("%d",c); }

WAP tofind the sum of even and odd numbers separately kept in an array

#include<stdio.h> void main() { int n[4],i,s=0,g=0; printf(enter 4 nos:); for(i=0;i<4;i++) { scanf(%d,n[i]); } for(i=0;i<4;i++) { tf (n[i]%2==0) { s=s+n[i]; } else { g=g+n[i]; } } printf(sum of odd nos are:%d,g) printf(sum of even nos are:%d,s) } }

WAP for searching a number in an array of 10 elements

#include<stdio.h> void main() { int n[10],i,j,f=0; printf(enter 4 nos:); for(i=0;i<10;i++) { scanf(%d,n[i]); } printf( enter the specific no:); scanf(%d,&j); for(i=0;i<10;i++) { If(j==n[i] { f++; } if(f==1) { printf(found); } Else { printf(not found); } } }

WAP to delete an element at a specified position in an array

#include<stdio.h> void main() { int n[10],a,i; printf("enter 10 nos:"); for(i=0;i<10;i++) { scanf("%d",&n[i]); } printf("enter the array to be deleted:"); scanf("%d",&a); for(i=0;i<10;i++) { if(a==n[i]) { n[i]=n[i+1]; n[i]=0; } if(n[i]!=0) { printf("%d",n[i]); } } }

WAP to insert an element at a specified position in an array

#include<stdio.h>

void main() { int n[10],i,j,a,k; printf("enter 4 nos:"); for(i=0;i<4;i++) { scanf("%d",&n[i]); } printf("enter pos and val:"); scanf("%d %d",&j,&a); for(k=4;k>j;k--) n[k]=n[k-1]; n[k]=a; for(i=0;i<5;i++) { printf("%d",n[i]); } }

WAP for changing all duplicate entries in an array to zero

#include<stdio.h> void main() { int n[10],i,j; printf("enter 10 nos:"); for(i=0;i<10;i++) { scanf("%d",&n[i]); } for(i=0;i<10;i++) { for(j=i+1;j<10;j++) if(n[i]==n[j]) { n[i]=0; n[j]=0; } printf("%d",n[i]); } }

WAP to enter a string and tell whether it is a palindrome or not

/*To check the string palindrom or not*/ #include<stdio.h> #include<conio.h> #include<string.h> void main() { char s[50],r[50]; int i,j; clrscr(); printf("Enter the string"); scanf("%s",s); i=0; j=strlen(s)-1; while(j>=0) { r[i]=s[j]; i++; j--; } r[i]='\0'; if(strcmp(s,r)==0) printf("\n %s is a palindrome string",s); else printf("\n %s is not a palindrome string",s); getch(); }

WAP to enter a string and convert capital letters to small and vice versa

#include<stdio.h> void main() { char a[10]; int i; printf("enter a name:"); scanf("%s",a); for(i=0;a[i]!='\0';i++) { if(a[i]>=97) printf("%c",a[i]-32); else{ printf("%c",a[i]+32);} } }

WAP to find the row sum and coloumn sum in a 2-d array

#include<stdio.h> void main() { int n[4][4],i,j,r=0,c=0; printf("enter 16 nos"); for(i=0;i<4;i++) { for(j=0;j<4;j++) { scanf("%d",&n[i][j]); } } for(i=0;i<4;i++) { printf("\n"); for(j=0;j<4;j++) { printf("%5d",n[i][j]); r=r+n[i][j]; c=c+n[j][i]; } } printf("row sum is%d",r); printf("coloumn sum is%d",c); }

WAP to find the transpose of a matrix

#include<stdio.h> void main() { int m[4][4],n[4][4],i,j; for(i=0;i<4;i++) { printf("Enter the 4 number-\n"); for(j=0;j<4;j++) { scanf("%d",&n[i][j]); } } for(i=0;i<4;i++) { for(j=0;j<4;j++) { m[i][j]=n[j][i]; } } for(i=0;i<4;i++) { for(j=0;j<4;j++){ printf("%10d",n[i][j]); printf("\n"); } printf("Transpose of the array is-\n"); for(i=0;i<4;i++) { for(j=0;j<4;j++){ printf("%10d",m[i][j]); } printf("\n"); } }

WAP to convert a decimal number into binary using function

/*convert decimal to binary using function*/ #include<stdio.h> #include<conio.h> #include<math.h> void binary(int a); void main() { int a=0; clrscr(); printf("Enter decimal number:"); scanf("%d",&a); binary(a); getch(); } void binary(int a) { int c=0,r=0,s=0; while(a!=0) { r=a%2; s=s+r*pow(10,c++); a=a/2; } printf("\n Binary number is %d",s); }

WAP to find the greatest number in an array by passing the array to a function

#include<stdio.h> int fact(int a) { int d=1; while(a>0) { d=d*a; a--; } return d; } void main() { int a; printf("enter a no:"); scanf("%d",&a); a=a*fact(a-1); printf("%d",a); }

WAP to find the factorial of a number using a function

#include<stdio.h> int fact(int a) { int d=1; while(a>0) { d=d*a; a--; } return d; } void main() { int a; printf("enter a no:"); scanf("%d",&a); a=fact(a); printf("%d",a); }

WAP to find the factorial of a number using a recursive function

/*To find factorial using recursive function*/ #include<stdio.h> #include<conio.h> int rec(int x); void main() { int a,fact; printf("Enter any number"); scanf("%d",&a); fact=rec(a); printf("\n Factorial Value=%d",fact); getch(); } int rec(int x) { int f; if(x==1) return(1); else f=x*rec(x-1); return(f); }

WAP to interchange the value of pointers /*interchange the value of pointers*/ #include<stdio.h> #include<conio.h> void main() { int a,b,*d,*e,*c; clrscr(); printf("Value of a & b?"); scanf("%d%d",&a,&b); d=&a; e=&b; printf("\n The value of a & b:%u\t%u",d,e); c=d; d=e; e=c; printf("\n\n The new value of a & b are %u\t%u",d,e); getch(); }

WAP to display the following pattern if the input string is comp using pointer and string

#include<stdio.h> void main() { char n[5]="COMP",*p; int i,j; for(i=0;i<4;i++) { printf("\n"); for(j=0;j<=i;j++) { p=&n[i]; printf("%c",*p); } } }

COMPUTER ASSIGNMENT

NAME-ANIRBAN BASU ROLL-04 DEPT.-COMPUTER SCIENCE AND ENGINEERING COLLEGE-SURENDRA INSTITUTE OF ENGINEERING AND MANAGEMENT

Anda mungkin juga menyukai