Вы находитесь на странице: 1из 42

Q 1-

WAP to Add two Number ?

/* addition of two numbers of int datatype*/ #include<stdio.h> #include<conio.h> void main() { int a,b,c;

printf("enter the value of a:"); scanf("%d",&a); printf("enter the value of b:"); scanf("%d",&b); c=a+b; printf("value of c:%d",c); getch(); }

Q 2-

Wap To Get sum of two number using Array ?

/* sum of five element by using array*/ #include<stdio.h> #include<conio.h> void main() { int a[5],i,sum=0; clrscr(); for(i=0;i<=4;i++) { printf("\nenter element:"); scanf("%d",&a[i]); } for(i=0;i<=4;i++) { sum=sum+a[i]; } printf("\n the sum of five element is %d",sum); getch(); }

Q3-

Wap to Add two Matrixes ?

#include<stdio.h> #include<conio.h> void main() { int a[4][4],b[4][4],c[4][4],i,j,p,q; clrscr(); printf("enter the order of matrix\n"); scanf("%d%d",&p,&q); printf("matrix can be added\n"); printf("enter the elements of the matrix a"); for(i=0;i<p;i++) for(j=0;j<q;j++) scanf("%d",&a[i][j]); printf("enter the elements of the matrix b"); for(i=0;i<p;i++) for(j=0;j<q;j++) scanf("%d",&b[i][j]); printf("the sum of matrix a and b\n"); for(i=0;i<p;i++) for(j=0;j<q;j++) c[i][j]=a[i][j]+b[i][j]; for(i=0;i<p;i++)

{ for(j=0;j<q;j++) { printf("%d\t",c[i][j]); } printf("\n"); } getch(); }

Q 4-

Wap to Know Whether entered number is Armstrong or not ?

#include<stdio.h> #include<conio.h> void main() { int num,i,sum,rem; clrscr(); for(i=1;i<=500;i++) { num=i; sum=0; while(num>0) { rem=num%10; sum=sum+rem*rem*rem; num=num/10; } if(i==sum) printf("\nnumber is armastrong=%d",i); } getch(); }

Q 5- wap to Passing an Array to a function ?

/* passing array to function */ #include<stdio.h> #include<conio.h> void main() { int large(int a[10]); int ar[10]; int l,i; clrscr(); for(i=0;i<=9;i++) { printf("\nenter %d element\t",i+1); scanf("%d",&ar[i]); } l=large(ar); printf("\nlargest element is %d",l); getch(); } int large(int a[10]) { int big,i; big=0;

for(i=1;i<=9;i++) { if(a[i]>big) { big=a[i]; } } return big; }

Q 6-

Wap to sort an array in ascending order ?

#include<stdio.h> #include<conio.h> void main() { int arr[10],i,j,temp; clrscr(); printf("\nenter the element of the array:"); for(i=0;i<10;i++) scanf("%d",&arr[i]); for(i=0;i<10;i++) for(j=i+1;j<10;j++) { if(arr[i]>arr[j]) { temp=arr[i]; arr[i]=arr[j]; arr[j]=temp; } } printf("\nsorted array is :"); for(i=0;i<10;i++) printf("%d\t",arr[i]); printf("\n"); getch(); }

Q 7-

Wap to understand the use of Break Statement ?

#include<stdio.h> #include<conio.h> void main() { int i,n; clrscr(); printf("enter the value"); scanf("%d",&n); for(i=1;i<=n;i++) { if(i==5) { printf("i understand the use of break\n"); break; } printf("number: %d\n",i); } printf("\n"); getch(); }

Q 8-

Wap to Swap Two number using Pointer ?

#include<stdio.h> #include<conio.h> void swap(int *x,int *y); void main() { int a,b; clrscr(); printf("\nenter the 1st number:"); scanf("%d",&a); printf("\nenter the 2nd number:"); scanf("%d",&b); swap(&a,&b); printf("\nafter the function execution:"); printf("\na=%d",a); printf("\nb=%d",b); getch(); } void swap(int *x,int *y) { int temp; temp=*x; *x=*y; *y=temp;

10

printf("\nthe swapped value"); printf("\na=%d",*x); printf("\nb=%d",*y); }

11

Q9-

Wap To swap two number By function (Call by value ) ?

/*call by value*/ #include<stdio.h> #include<conio.h> void main() { void swap(int x,int y); int a,b; clrscr(); printf("\nenter the first number:"); scanf("%d",&a); printf("\nenter the second number:"); scanf("%d",&b); swap(a,b); printf("\nafter the function execution"); printf("\na=%d",a); printf("\nb=%d",b); getch(); } void swap(int x,int y) { int temp; temp=x; x=y;

12

y=temp; printf("\nthe swapped value:"); printf("\na=%d",x); printf("\nb=%d",y); }

13

Q 10-

wap to Understand The CONTINUE statement ?

#include<stdio.h> #include<conio.h> void main() { int i,n; clrscr(); printf("\nenter the value"); scanf("%d",&n); for(i=1;i<=n;i++) if(i==3) { printf(" i understand\n"); continue; } printf("number:%d\n",i);} printf("\n); getch(); }

14

Q 11-

Wap to convert the value of km into meter,centi meter, inch and feet ?

#include<stdio.h> #include<conio.h> void main() { int cm,m,km; float inch,ft; clrscr(); printf("\nenter the value of km:"); scanf("%d",&km); m=km*100; cm=m*100; inch=cm/2.54; ft=inch/12; printf("\nthe value of m,cm,inch,ft=\n%d\n%d\n%f\n%f",m,cm,inch,ft); getch(); }

15

Q 12-

wap to Know how many number is negative and Positive are I entered in array ?

#include<stdio.h> #include<conio.h> void main() { int a[5],n,c_pos=0,c_neg=0,i; clrscr(); printf("enter the size of array\n"); scanf("%d",&n); printf("enter the element of array\n"); for(i=0;i<n;i++) scanf("%d",&a[i]); for(i=0;i<n;i++) { if(a[i]<0) c_neg++; else c_pos++; } printf("there are %d negative numbers in the array\n",c_neg); printf("there are %d positive numbers in the array\n",c_pos); getch(); }

16

Q 13- Wap to know the factorial of entered number ?

#include<stdio.h> #include<conio.h> void main() { int n,i; long int fact=1; printf("enter the number"); scanf("%d",&n); if(n<0) printf("number is negative"); else { while(n>1) { fact=fact*n; n--;

}} printf("%ld",fact); getch(); }

17

Q 14-

Wap to know the largest number in array ?

#include<stdio.h> #include<conio.h> void main() { int large(int a[5]); int ar[5]; int l,i; clrscr(); for(i=0;i<=4;i++) { printf("\n enter element\t"); scanf("%d",&ar[i]); } l=large(ar); printf("\n largest element is =%d",l); getch(); } int large(int a[5]) { int big,i; big=0; for(i=1;i<=4;i++) {

18

if(a[i]>big) { big=a[i]; } } return big; }

19

Q 15-

wap to know the factorial of given number using function ?

#include<stdio.h> #include<conio.h> int fact(int n); void main() { int num; int f; clrscr(); printf("\n enter a number:"); scanf("%d",&num); f=fact(num); printf("\n fact=%d",f); getch(); } int fact(int n) { int fc; int i; fc=1; for(i=n;i>=1;i--) fc=fc*i; return fc; }

20

Q 16- Wpa to know the fcctorial of given number using function ?

#include<stdio.h> #include<conio.h> void fact(int n); void main() { int num; clrscr(); printf("\n enter a number:"); scanf("%d",&num); fact(num); getch(); } void fact(int n) { int fc; int i; fc=1; for(i=n;i>=1;i--) fc=fc*i; printf("\n the output is: %d",fc); }

21

Q 17- Wap to print fibbonoci Series ?

#include<stdio.h> #include<conio.h> void main() { int a=0;int b=1;int c; int i,n;

printf("\nenter the number of terms:"); scanf("%d",&n);

for(i=1;i<=n-2;i++) { c=a+b; printf("%d%d%d",a,b,c); a=b; b=c;

} getch(); }

22

Q 18- Wap to whether given number is Odd or Even using file handling ?

#include<stdio.h> #include<conio.h> void main() { FILE *f1,*f2,*f3; int num,i; clrscr(); printf("content of data file\n"); f1=fopen("data","w"); for(i=1;i<=30;i++) { scanf("%d",&num); if(num==-1)break; putw(num,f1); } fclose(f1); f1=fopen("data","r"); f2=fopen("odd","w"); f3=fopen("even","w"); while((num=getw(f1))!=EOF) { if(num%2==0)

23

putw(num,f3); else putw(num,f2); } fclose(f1); fclose(f2); fclose(f3); f2=fopen("odd","r"); f3=fopen("even","r"); printf("\n\ncontents of odd file \n\n"); while((num=getw(f2))!=EOF) printf("%4d",num); printf("\n\ncontents of even file\n\n"); while((num=getw(f3))!=EOF) printf("%4d",num); fclose(f2); fclose(f3); getch(); }

24

Q 19-

Wap to know the number is odd or even by goto statement ?

#include<stdio.h> #include<conio.h> void main() { int n; printf("enter the value"); scanf("%d",&n); if(n%2==0) goto even; else goto odd; even: printf("number is even"); goto end; odd: printf("number is odd"); goto end; end: printf("\n"); getch(); }

25

Q 20- Wap to Add two n umber of int data type ?

/* addition of two numbers of int datatype*/ #include<stdio.h> #include<conio.h> void main() { int bs,da,hra; float gross_sal; clrscr(); printf("\nenter basic salary"); scanf("%d",&bs); da=(40*bs)/100; hra=(20*bs)/100; gross_sal=bs+da+hra; printf("value of gross salary : %f\n",gross_sal); getch(); }

26

Q 21-

Wap to get largest element in an Array ?

/* largest element in an array*/ #include<stdio.h> #include<conio.h> void main() { int a[5],i,c; clrscr(); for(i=0;i<=4;i++) { printf("\nenter the element"); scanf("%d",&a[i]); } c=a[0]; for(i=1;i<=4;i++) { if(c<a[i]) { c=a[i]; } } printf("\nthe largest element is %d",c); getch(); }

27

Q 22- Wap to Print * ** *** ****

#include<stdio.h> #include<conio.h> void main() { int i,j,k;/* where i,j,k denotes no. of rows,space and columns resp.*/ int a=3;/* this line indicates the maximum no. of space*/ clrscr(); for(i=1;i<=4;i++) { for(j=1;j<=a;j++) { printf(" "); } for(k=1;k<=i;k++) { printf("*"); } printf("\n");

28

a=a-1; } getch();

29

Q 23-

Wap to free the allocated memory of a variable ?

#include<stdio.h> #include<conio.h> #include<alloc.h> #include<stdlib.h> void main() { int n,*ptr; int i; clrscr(); printf("\nenter number of integer to be entered"); scanf("%d",&n); ptr=(int*)malloc(n*sizeof(int)); if(ptr==0) { printf("\nmemory not allocated","aborting!!!"); exit(1); } else for(i=0;i<n;i++) { printf("\nenter %d element",i+1); scanf("%d",&ptr[i]); }

30

for(i=0;i<n;i++) { printf("\n%d",ptr[i]); } printf("\nDONE!!!!"); free (ptr); getch(); }

31

Q 24- Wap to enter the onfo. Of Student using Structure ? #include<stdio.h> #include<conio.h> struct student { int roll_no; char name[20]; struct date { int day; int month; int year; }b; }a; void main() { clrscr(); printf("\nenter the name & roll no,date of birth\n"); scanf("%d",&a.roll_no); gets(a.name); printf("\n"); scanf("%d%d%d",&a.b.day,&a.b.month,&a.b.year); printf("\n%d\n%s\n%d-%d-%d",a.roll_no,a.name,a.b.day,a.b.month,a.b.year); getch(); }

32

#include<stdio.h> #include<conio.h> void main() { int a,n,s=0,r; clrscr(); printf("\nenter the number:"); scanf("%d",&n); a=n; while(n>0) { r=n%10; s=s*10+r; n=n/10; } if(s==a) printf("\nthe number is palindrome"); else printf("\nthe number is not palindrome"); getch(); }

33

Q 25- wap of Enter number using pointer ?

#include<stdio.h> #include<conio.h> void main() { char z='b'; float x=125.5; int y=75;

int *a; char *b; float *c; a=&y; b=&z; c=&x; printf("%d%c%f",a,b,c); getch(); }

34

Q 26- Wap to Understand the use of sizeof() operater ?

#include<stdio.h> #include<conio.h> main() { int age=30; float height=5.98; char a='B';

int *p=&age; float *p1=&height; char *p2=&a;

printf("\nThe %d\t%d",sizeof(p),sizeof(*p)); printf("\nThe %d\t%d",sizeof(p1),sizeof(*p1)); printf("\nThe %d\t%d\n",sizeof(p2),sizeof(*p2)); }

35

Q 27- Wap to know whether entered number is prime or not ?

#include<stdio.h> #include<conio.h> void main() { int n,i; int c=0; clrscr(); printf("\nenter the number:"); scanf("%d",&n); for(i=1;i<=n;i++) { if(n%i==0) c=c+1; } if(c==2) printf("\nnumber is prime"); else printf("\nnumber is not prime"); getch(); }

36

Q 28- Wap to print the wolt. of given thing ?

#include<stdio.h> #include<conio.h> void main() { clrscr(); printf("\n\tphilips\t40w\t60w\t30w"); printf("\n\tbajaj\t45w\t50w\t35w"); printf("\n\tsamsung\t35w\t45w\t40w"); getch(); }

37

Q 29- Wap to know the address of given variable ?

#include<stdio.h> #include<conio.h> void main() { int a=87; int *p=&a; float b=4.5; float *p1=&b; clrscr(); printf("\nvalue of p=address of a=%u",p); printf("\nvalue of p1=address of b=%u",p1); printf("\naddress of p=%u",&p); printf("\naddress of p1=%u",&p1); printf("\nvalue of a=%d%d%d",a,*p,*(&a)); printf("\nvalue of b=%f%f%f",b,*p1,*(&b)); getch(); }

38

Q 30- Wap to know the fact. Of given number using recursion ?

#include<stdio.h> #include<conio.h> void main() { int fact(int n); int num,f; clrscr(); printf("\n enter the number:"); scanf("%d",&num);

f=fact(num); printf("\n factorial is =%d",f); getch(); } int fact(int n) { if(n==0) return 1; else return(n*fact(n-1));

39

Q 31- Wap to know the Power of given number using function ?

#include<stdio.h> #include<conio.h> void main() { int fact(int a,int n); int p,x,m; printf("\n enter the value of x:"); scanf("%d",&x); printf("\n enter the power:"); scanf("%d",&m); p=power(x,m); printf("%d raised the power to the power %d is:%d",m,x,p); getch(); } int power(int a,int n) { if(n==0) return 1; else return(a*power(a,n-1)); }

40

Q 32 Wap to print the Reverse of Given Number ?

#include<stdio.h> #include<conio.h> void main() { int n,s=0,r; clrscr(); printf("\nenter the number:"); scanf("%d",&n); while(n>0) { r=n%10; s=s*10+r; n=n/10; } printf("\nthe reverse number is %d",s); getch(); }

41

42

Вам также может понравиться