You are on page 1of 91

Excel Dip.Coll.

first sem

programming in c

Pra:1 W.A.P that will print your mailing address in the following form First line:Name Second line:Door name,street Third line:city,pincode. #include<stdio.h> #include<conio.h> void main() { clrscr(); printf("Dhara Randeria"); printf("\n Plot no-316, shrinagar"); printf("\n G'nagar-382012"); getch(); } O/p: Dhara randeria Plot no-316,shrinagar Gnagar-382012

Page 1

Excel Dip.Coll.

first sem

programming in c

Pra:2 W.A.P using one print statement to print the following pattern. * ** *** **** #include<stdio.h> #include<conio.h> void main() { clrscr(); printf("* \n ** \n *** \n ****"); getch(); } O/P: * ** *** ****

Page 2

Excel Dip.Coll.

first sem

programming in c

Pra:3 W.A.P that will print addition of two numbers and that two numbers . #include<stdio.h> #include<conio.h> void main() { int a,b,c; clrscr(); printf("enter first no:\n"); scanf("%d",&a); printf("enter second no:\n"); scanf("%d",&b); c=a+b; printf("addition of two no.is %d",c); getch(); } o/p: enter first no:3 enter second no:2 addition of two no is 5

Page 3

Excel Dip.Coll.

first sem

programming in c

Pra:4 W.A.P to find the average of three numbers read from the user. #include<stdio.h> #include<conio.h> void main() { int a,b,c; int average; clrscr(); printf("enter first no:\n"); scanf("%d",&a); printf("enter second no:\n"); scanf("%d",&b); printf("enter third no:\n"); scanf("%d",&c); average=(a+b+c)/3; printf("\n average is =%d",average); getch(); } O/P enter first no:1 enter second no:2 enter third no:3 average is =2

Page 4

Excel Dip.Coll.

first sem

programming in c

Pra:5 W.A.P to calculate volume and area of the cylinder using v=pi*r*r and a=pi*r*h. #include<stdio.h> #include<conio.h> #define pi 3.142 void main() { float r,volume,area,h; clrscr(); printf("enter the radius:"); scanf("%f",&r); printf("enter the hight:"); scanf("%f",&h); volume=(pi*r*r*h); printf("\n volume of cylinder %f",volume); area=pi*r*r; printf("\n area of cylinder %f",area); getch(); } O/P: enter the radius:2 enter the hight:2 volume of cylinder 25.136000 area of cylinder 12.568000

Page 5

Excel Dip.Coll.

first sem

programming in c

Pra:6 W.A.P to convert temperature from Fahrenheit to Celsius using c=(f-32)/1.8. #include<stdio.h> #include<conio.h> void main() { float f,c; clrscr(); printf("fahrenhit="); scanf("%f",&f); c=(f-32)/1.8; printf("\n celcius=%f",c); getch(); } O/p: Fahrenhit=50 celcius=10.000000

Page 6

Excel Dip.Coll.

first sem

programming in c

Pra:7 W.A.P to calculate 10% of bonus of salary and print the net salary. #include<stdio.h> #include<conio.h> void main() { float salary; clrscr(); printf("enter the salary \n"); scanf("%f",&salary); salary=salary+(salary*0.10); printf("%f",salary); getch(); } O/P: enter the salary 100 110.000000

Page 7

Excel Dip.Coll.

first sem

programming in c

Pra:8 W.A.P to calculate the simple interest using principal, interest rate,year(S.I=(p*r*y)/100). #include<stdio.h> #include<conio.h> void main() { float p,r,y,si; clrscr(); printf("principal="); scanf("%f",&p); printf("Interest="); scanf("%f",&r); printf("year="); scanf("%f",&y); si=(p*r*y)/100; printf("si=%f",si); getch(); } O/P: principal=100 Interest =2 year=4 si=8.000000

Page 8

Excel Dip.Coll.

first sem

programming in c

Pra:9 W.A.P that take number of days from keyboard and calculate the number of days, months and years using % operator. #include<stdio.h> #include<conio.h> void main() { int year,days,month; clrscr(); printf("enter the day:"); scanf("%d",&days); month=days/30; year=days/365; days=days/30; printf("\n the month: %d",month); printf("\n the year: %d",year); printf("\n the day: %d",days); getch(); } O/P: enter the day:365 the month:12 the year:1 the day:12

Page 9

Excel Dip.Coll.

first sem

programming in c

Pra:10 W.A.P to find sum of three digit numbers using % operator(Ex.Number=123 then 1+2+3=6). #include<stdio.h> #include<conio.h> void main() { int no,sum,c1,c2,c3,c4; clrscr(); printf("\n \n enter your value of no:"); scanf("%d",&no); c1=no/10; c2=no%10; c3=c1/10; c4=c1%10; sum=c2+c3+c4; printf("\n \n your answer is : %d",sum); getch(); } O/P: enter your value of no:123 your answer is :6

Page 10

Excel Dip.Coll.

first sem

programming in c

Pra:11 W.A.P that displays the ASCII value of entered number. #include<stdio.h> #include<conio.h> void main() { char a; clrscr(); printf("enter your character:"); scanf("%c",&a); printf("%d",a); getch(); } O/P: enter your character: a 97

Page 11

Excel Dip.Coll.

first sem

programming in c

Pra:12 W.A.P to swap the value of two variable by using third variable. #include<stdio.h> #include<conio.h> void main() { int a,b,c; clrscr(); printf("enter the value of a:"); scanf("%d",&a); printf("enter the value of b:"); scanf("%d",&b); c=a; a=b; b=c; printf("a=%d\n b=%d",a,b); getch(); } o/p: enter the value of a:1 enter the value of b:2 a=2 b=1

Page 12

Excel Dip.Coll.

first sem

programming in c

Pra:13 W.A.P to swap the value of two variables without using third variable. #include<stdio.h> #include<conio.h> void main() { int a,b; clrscr(); printf("enter the value of a:"); scanf("%d",&a); printf("enter the value of b:"); scanf("%d",&b); a=a+b; b=a-b; a=a-b; printf("a=%d\n b=%d",a,b); getch(); } o/p: enter the value of a:13 enter the value of b:20 a=20 b=13

Page 13

Excel Dip.Coll.

first sem

programming in c

Pra:14 W.A.P to find the largest number among three numbers. #include<stdio.h> #include<conio.h> void main() { int a,b,c; clrscr(); printf("enter the value of a:"); scanf("%d",&a); printf("enter the value of b:"); scanf("%d",&b); printf("enter the value of c:"); scanf("%d",&c); if(a>b) { if(a>c) { printf("%d is max.",a); } else { printf("%d is max.",c); } } else { if(b>c) { printf("%d is max.",b); } else { printf("%d is max.",c); } }
Page 14

Excel Dip.Coll.

first sem

programming in c

getch(); } O/P: enter the value of a:4 enter the value of b:9 enter the value of c:6 9 is max.

Page 15

Excel Dip.Coll.

first sem

programming in c

Pra:15 W.A.P to find the largest number among three numbers using ternary operator. #include<stdio.h> #include<conio.h> void main() { int a,b,c,max; clrscr(); printf("enter the value of a:"); scanf("%d",&a); printf("enter the value of b:"); scanf("%d",&b); printf("enter the value of c:"); scanf("%d",&c); max=(((a>b)?((a>c)?a:c):(b>c)?b:c)); printf("%d is max.",max); getch(); } O/P: enter the value of a:12 enter the value of b:15 enter the value of c:14 15 is max.

Page 16

Excel Dip.Coll.

first sem

programming in c

Pra:16 W.A.P that display whether the entered number is even or odd. #include<stdio.h> #include<conio.h> void main() { Int n; clrscr(); printf("enter no:\n"); scanf("%d",&n); if(n%2==0) printf("even no."); else printf("odd no."); getch(); } Out put;Enter the no: 44 Even no

Page 17

Excel Dip.Coll.

first sem

programming in c

Pra:17 W.A.P that give demonstration of marks using if else ladder. #include<stdio.h> #include<conio.h> void main() { int marks; clrscr(); printf("enter the value of marks"); scanf("%d",& marks); if(marks>=70) { printf("distinction"); } else if(marks>=60&&marks<70) { printf("first class"); } else if(marks>=50&&marks<60) printf("second class"); else if(marks>=35&&marks<50) printf("pass class"); else if(marks<35) printf("fail"); getch(); } OUTPUT Enter the marks=71 Distinction

Page 18

Excel Dip.Coll.

first sem

programming in c

Pra:18 W.A.P to check whether the entered year is leap year or not. #include<stdio.h> #include<conio.h> void main() { Int y; clrscr(); printf("enter year:\n"); scanf("%d",&y); if(y%4==0) printf("leap year"); else printf("not leap year ."); getch(); } OUTPUT Enter the year:1999 Not leap year

Page 19

Excel Dip.Coll.

first sem

programming in c

Pra:19 W.A.P to check whether particular character is in upper case or in lower case. #include<stdio.h> #include<conio.h> void main() { char c; clrscr(); printf("enter character:\n"); scanf("%c",&c); if(c>=65 && c<=90) printf("Character is Uppercase."); else if(c<=122 && c>=97) printf("Character is Lowercase."); else printf("Special Symbol and digit."); getch(); } O/p: enter character:S Character is Uppercase.

Page 20

Excel Dip.Coll.

first sem

programming in c

Pra:20 W.A.P to display 1 to 10 numbers using while loop. #include<stdio.h> #include<conio.h> void main() { int a; clrscr(); a=0; while(a<10) { a=a+1; printf("%d\n",a); } getch(); }

O/P: 1 2 3 4 5 6 7 8 9 10

Page 21

Excel Dip.Coll.

first sem

programming in c

Pra:21 W.A.P that display odd numbers between 1 to 50. #include<stdio.h> #include<conio.h> void main() { int i; clrscr(); printf("Odd number for between 1 to 50: "); i=1; while(i<=50) { printf("\n%d",i); i+=2; } getch(); } Output: 1 3 5 7 9 11 13 15 17 19 21 23 25 27 29 31
Page 22

Excel Dip.Coll.

first sem

programming in c

33 35 37 39 41 43 45 47 49

Page 23

Excel Dip.Coll.

first sem

programming in c

Prac 22: W.A.P find sum of ten numbers. #include<stdio.h> #include<conio.h> void main() { int sum,n; clrscr(); printf("enter the value of sum:"); sum=0; n=1; while(n<=10) { sum=sum+n; n++; } printf("%d",sum); getch(); } o/p: enter the value of sum: 55

Page 24

Excel Dip.Coll.

first sem

programming in c

Prac 23: W.A.P. to print multiplication table. (Ex. enter no 2 then 2*1=2,2*2=4,..2*10=20). #include<stdio.h> #include<conio.h> void main() { int num,n; clrscr(); printf("enter the value of num:"); scanf("%d",&num); n=1; while(n<=10) { printf("\n %d*%d=%d",num,n,num*n); n++; } getch(); } o/p: enter the value of num:5 5*1=5 5*2=10 5*3=15 5*4=20 5*5=25 5*6=30 5*7=35 5*8=40 5*9=45 5*10=50

Page 25

Excel Dip.Coll.

first sem

programming in c

Prac 24: W.A.P. that read a character from keyboard and print its reverse case. #include<stdio.h> #include<conio.h> void main() { char c; clrscr(); printf("enter the character:"); scanf("%c",&c); if(c>=65 && c<=90) { c=c*3; printf("reverse case is %c",c); } else if(c>=97 && c<=122) { c=c-32; printf("reverse case is %c",c); } else printf("Invaid character"); getch(); } O\p: Enter the character:r Reverse case is R

Page 26

Excel Dip.Coll.

first sem

programming in c

Prac 25: W.A.P. to find a factorial number of entered number. #include<stdio.h> #include<conio.h> void main() { int num,i,fact=1; clrscr(); printf("enter number"); scanf("%d",&num); for(i=1;i<=num;i++) { fact=fact*i; printf("factorial of %d number is %d\n",i,fact);} getch(); } o/p: enter num:5 factorial of 1 number is 1 factorial of 2 number is 2 factorial of 3 number is 6 factorial of 4 number is 24 factorial of 5 number is 120

Page 27

Excel Dip.Coll.

first sem

programming in c

Prog 26: W.A.P. to print the following pattern using for loop. 1 22 333 4444 55555 #include<stdio.h> #include<conio.h> void main() { int i,j,; clrscr(); for(i=0;i<=5;i++) { for(j=0;j<i;j++) { printf(" %d",i); } printf("\n"); } getch(); } O/P: 1 22 333 4444 55555

Page 28

Excel Dip.Coll.

first sem

programming in c

Prac 27: W.A.P. to print the following pattern using for loop. * ** *** **** ***** #include<stdio.h> #include<conio.h> void main() { int i,j,n; clrscr(); for(i=5;i>=1;i--) { for(j=1;j<=i;j++) { printf("*"); } printf("\n"); } getch(); } O/P: * ** *** **** *****

Page 29

Excel Dip.Coll.

first sem

programming in c

Pra 28: W.A.P. to print the following pattern using for loop. 1 12 123 1234 12345 #include<stdio.h> #include<conio.h> void main() { int i,j,n; clrscr(); printf("How many lines:\n"); scanf("%d",&n); for(i=1;i<=n;i++) { for(j=1;j<=i;j++) { printf("%d",j); } printf("\n"); } getch(); } O/P: How many lines:5 1 12 123 1234 12345
Page 30

Excel Dip.Coll.

first sem

programming in c

Pra 29: W.A.P. to print the following pattern using for loop. 1 23 456 7 8 9 10 #include<stdio.h> #include<conio.h> void main() { int i,j,n,m=1; clrscr(); printf("How many lines:\n"); scanf("%d",&n); for(i=1;i<=n;i++) { for(j=1;j<=i;j++) { printf("%3d",m); m++; } printf("\n"); } getch(); } O/P: How many lines:4 1 23 456 7 8 9 10
Page 31

Excel Dip.Coll.

first sem

programming in c

Pra 30: W.A.P. to print the following pattern using for loop. 1 01 101 0101 10101 #include<stdio.h> #include<conio.h> void main() { int i,j,n; clrscr(); printf("How many lines:\n"); scanf("%d",&n); for(i=1;i<=5;i++) { for(j=1;j<=i;j++) if(i%2==0 && j%2==0||j%2==1 && i%2==1) printf("1"); else printf("0"); printf("\n"); } getch(); } O/P: How many lines:5 1 01 101 0101 10101
Page 32

Excel Dip.Coll.

first sem

programming in c

Pra 31: W.A.P. to print the following pattern using for loop. 1 121 12321 1234321 123454321 #include<stdio.h> #include<conio.h> void main() { int i,j,k,n; clrscr(); printf("How many lines:\n"); scanf("%d",&n); for(i=1;i<=n;i++) { for(k=1;k<=n-i;k++) { printf(" "); } for(j=1;j<=i;j++) printf("%d",j); for(k=i-1;k>=1;k--) printf("%d",k); printf("\n"); } getch(); } O/P: 1 121 12321 1234321 123454321
Page 33

Excel Dip.Coll.

first sem

programming in c

Pra32: W.A.P. to print the following pattern using for loop. 1 2 2 3 3 3 4 4 4 4 5 5 5 5 5 #include<stdio.h> #include<conio.h> void main() { int i,j,k,n; clrscr(); printf("How many lines:\n"); scanf("%d",&n); for(i=1;i<=n;i++) { for(k=1;k<=n-i;k++) { printf(" "); } for(j=1;j<=i;j++) { printf("%d ",i); /* one space after %d */ } printf("\n"); } getch(); }
O/P:

How many lines:5 1 2 2 3 3 3 4 4 4 4 5 5 5 5 5


Page 34

Excel Dip.Coll.

first sem

programming in c

Pra 33: W.A.P. to find sum of(1/1!)+(1/2!)+..up to entered number. #include<stdio.h> #include<conio.h> void main() { int fact=1,i,n,j; float sum=0; clrscr(); printf("Enetr n:\n"); scanf("%d",&n); for(i=1;i<=n;i++) { fact=1; for(j=1;j<=i;j++) { fact=fact*j; } sum=sum+1.0/fact; } printf("Answer=%f",sum); getch(); } O/P: Enetr n: 4 sum=1.708

Page 35

Excel Dip.Coll.

first sem

programming in c

Pra 34: W.A.P. to find division of given number. #include<stdio.h> #include<conio.h> void main() { int i,no; clrscr(); printf("Enetr no:4"); scanf("%d",&no); for(i=1;i<=no;i++) { if(no%i==0) { printf("%d ",i); /* One Space After %d */ } } getch(); } O/P Enter no:6 1236

Page 36

Excel Dip.Coll.

first sem

programming in c

Pra 35: W.A.P. to print the Fibonacci series. #include<stdio.h> #include<conio.h> void main() { int a=1,b=1,c,d,n; clrscr(); printf("Enetr terms:\n"); scanf("%d",&d); printf("%d ",a); /* One Space After %d */ printf("%d ",b); /* One Space After %d */ for(n=1;n<d;n++) { c=a+b; a=b; b=c; printf("%d ",c); /* One Space After %d */ } getch(); } O/p: Enetr terms:5 112358

Page 37

Excel Dip.Coll.

first sem

programming in c

Pra 36: W.A.P. to find reverse number of entered number #include<stdio.h> #include<conio.h> void main() { int r=0,ans=0,a; clrscr(); printf("Enetr a:\n"); scanf("%d",&a); while(a>0) { r=a%10; ans=ans*10+r; a=a/10; } printf("ans=%d ",ans); getch(); } O/P: Enetr a: 1 2 3 321

Page 38

Excel Dip.Coll.

first sem

programming in c

Pra 37: W.A.P. to check whether a particular number is palindrome or no.(ex. Num=303 then palindrome,num =123 then not) #include<stdio.h> #include<conio.h> #include<string.h> void main() { char s[20]; int i,j,flag=0; clrscr(); printf("Enetr string:\n"); scanf("%s",s); for(i=0,j=strlen(s)-1;i<strlen(s)/2;++i,--j) { if(s[i]!=s[j]) { flag=1; break; } } if(flag==0) printf("Palindrome"); else printf("Not Palindrome"); getch(); } O/P: Enter string: hello Not Palindrome Or Enter string: Malayalam Palindrome

Page 39

Excel Dip.Coll.

first sem

programming in c

Pra 38: W.A.P. to print multiplication table. 123..10 234.20 1020..100 #include<stdio.h> #include<conio.h> void main() { int i,j,y; clrscr(); for(i=1;i<=10;i++) { for(j=1;j<=10;j++) { y=i*j; printf("%d ",y);/*Spaceis after %d*/ } printf("\n"); } getch(); }

Page 40

Excel Dip.Coll.

first sem

programming in c

O/P: 1 2 3 4 5 6 7 8 9 10 2 4 6 8 10 12 14 16 18 20 3 6 9 12 15 18 21 24 27 30 4 8 12 16 20 24 28 32 36 40 5 10 15 20 25 30 35 40 45 50 6 12 18 24 30 36 42 48 54 60 7 14 21 28 35 42 49 56 63 70 8 16 24 32 40 48 56 64 72 80 9 18 27 36 45 54 63 72 81 90 10 20 30 40 50 60 70 80 90 100

Page 41

Excel Dip.Coll.

first sem

programming in c

Pra 39: W.A.P. to enter the five element using array and print it on the screen. #include<stdio.h> #include<conio.h> void main() { int i,a[5]; clrscr(); printf("enter the five no\n"); for(i=0;i<5;i++) { scanf("%d",&a[i]); } printf("The values are\n"); for(i=0;i<5;i++) { printf("%d\n",a[i]); } getch(); } O/P: Enetr the five no: 1 2 3 4 5 The value are: 1 2 3 4 5
Page 42

Excel Dip.Coll.

first sem

programming in c

Pra40: W.A.P. to find a root of entered number. #include<stdio.h> #include<conio.h> #include<math.h> void main() { float a,x; clrscr(); printf("enter the value of a:\n"); scanf("%f",&a); x=sqrt(a); printf("Answer=%2.2f",x); getch(); } O/P: enter the value of a:5 Answer=5.00

Page 43

Excel Dip.Coll.

first sem

programming in c

Pra 41: W.A.P. to find the largest number out of 10 numbers. #include<stdio.h> #include<conio.h> #include<math.h> void main() { int num[10],i,max=0,n; clrscr(); printf("How many elements?\n"); scanf("%d",&n); printf("enter %d elements\n",n); for(i=0;i<n;i++) { scanf("%d",&num[i]); if(num[i]>max) { max=num[i]; } } printf("Maximum=%d",max); getch(); }
O/P: How many elements?10 Enter 10 elements 10 20 30 40 50 60 100 70 80 90 Maximum=100
Page 44

Excel Dip.Coll.

first sem

programming in c

Pra 42: W.A.P. to find the sum and average of the different numbers. #include<stdio.h> #include<conio.h> #include<math.h> void main() { int a[5],sum=0,i; float avg; clrscr(); printf("enter the five no:\n"); for(i=0;i<5;i++) { scanf("%d",&a[i]); } for(i=0;i<5;i++) { sum=sum+a[i]; } printf("sum=%d\n",sum); avg=sum/5; printf("avg=%.2f\n",avg); getch(); } O/P: enter the five no:5 1 2 3 4 5 Sum=15 Avg=3.00
Page 45

Excel Dip.Coll.

first sem

programming in c

Pra 43: W.A.P. to arrange the number in ascending and descending order. #include<stdio.h> #include<conio.h> void main() { int i,j,k,a[5],n; clrscr(); printf("enter the five no\n"); for(i=0;i<5;i++) { scanf("%d",&a[i]); } for(i=0;i<5;i++) ` { for(j=i+1;j<5;j++) { if(a[i]>a[j]) { k=a[i]; a[i]=a[j]; a[j]=k; } } } printf("The ascendind no is\n"); for(i=0;i<5;i++) { printf("%d\n",a[i]); } printf("The descending no is\n");
Page 46

Excel Dip.Coll.

first sem

programming in c

for(i=4;i>=0;i--) { printf("%d\n",a[i]); } getch(); } O/P: Enter the five no 20 50 10 40 30 The ascending no is 10 20 30 40 50 The descending no is 50 40 30 20 10

Page 47

Excel Dip.Coll.

first sem

programming in c

Pra 44: W.A.P. to enter two dimensional array(or matrix) and print it on the screen. #include<stdio.h> #include<conio.h> void main() { int a[3][3],i,j; clrscr(); printf("enter the matrix\n"); for(i=0;i<3;i++) { for(j=0;j<3;j++) { scanf("%d",&a[i][j]); } } printf("Matrix is\n"); for(i=0;i<3;i++) { printf("\n"); for(j=0;j<3;j++) { printf("%d\t",a[i][j]); } } getch(); }

Page 48

Excel Dip.Coll.

first sem

programming in c

o/p: Enter the matrix: 1 2 3 4 5 6 7 8 9 Matrix is 123 456 789

Page 49

Excel Dip.Coll.

first sem

programming in c

Prog 45: W.A.P. to print the transpose matrix. #include<stdio.h> #include<conio.h> void main() { int a[3][3],i,j,c[3][3]; clrscr(); printf("enter the matrix\n"); for(i=0;i<3;i++) { for(j=0;j<3;j++) { scanf("%d",&a[i][j]); } } printf("Transpose Matrix is\n"); for(i=0;i<3;i++) { printf("\n"); for(j=0;j<3;j++) { printf("%d\t",a[j][i]); } } getch(); }

Page 50

Excel Dip.Coll.

first sem

programming in c

O/P: Enter the matrix: 1 2 3 4 5 6 7 8 9 Matrix is 147 258 369

Page 51

Excel Dip.Coll.

first sem

programming in c

Pra46: W.A.P. for addition of two matrices. #include<stdio.h> #include<conio.h> void main() { int a[3][3],b[3][3],c[3][3],i,j; clrscr(); printf("enter the first matrix\n"); for(i=0;i<3;i++) { printf("\n"); for(j=0;j<3;j++) { scanf("%d",&a[i][j]); } } printf("enter the second matrix\n"); for(i=0;i<3;i++) { printf("\n"); for(j=0;j<3;j++) { scanf("%d",&b[i][j]); } } for(i=0;i<3;i++) { for(j=0;j<3;j++) { c[i][j]=a[i][j]+b[i][j]; } } printf("addition of Matrix is\n"); for(i=0;i<3;i++) {
Page 52

Excel Dip.Coll.

first sem

programming in c

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

Page 53

Excel Dip.Coll.

first sem

programming in c

O/P: Enter the first matrix 5 4 2 1 2 3 7 8 9 Enter second matrix 2 5 6 4 3 1 1 2 3 Addition of matrix is 7 9 8 5 5 4 8 10 12

Page 54

Excel Dip.Coll.

first sem

programming in c

Pra 47: W.A.P. to reverse the string. #include<stdio.h> #include<conio.h> void main() { char s1[20],s2[20]; int len,i,j; clrscr(); printf("enter a string:\n"); scanf("%s",s1); len=0; while(s1[len]!='\0') { len++; } for(i=0,j=len-1;i<len;++i,--j) { s2[j]=s1[i]; } s2[len]='\0'; printf("Reverse string:%s",s2); getch(); } O/p: Enter a string: hello Reverse String:olleh

Page 55

Excel Dip.Coll.

first sem

programming in c

Pra 48: W.A.P. to print the following output. C CP CPR CPRO CPROG CPROGR CPROGRA CPROGRAM #include<stdio.h> #include<conio.h> #include<string.h> void main() { char c,d; char string[8]="cprogram"; clrscr(); for(c=0;c<=7;c++) { d=c+1; printf("%.8*s\n",d,string); } getch(); } O/P:
C CP CPR CPRO CPROG CPROGR CPROGRA CPROGRAM
Page 56

Excel Dip.Coll.

first sem

programming in c

Pra 49: W.A.P. Function for addition of two numbers. #include<stdio.h> #include<conio.h> void sum(int a,int b); void main() { int i,j; clrscr(); printf("Given two integer numbers:"); scanf("%d %d",&i,&j); sum(i,j); getch(); } void sum(int a,int b) { int c; c=a+b; printf("sum of %d and %d=%d",a,b,c); } O/p: Give two integer numbers: 2 3 Sum of 2 and 3=5

Page 57

Excel Dip.Coll.

first sem

programming in c

Pra50: W.A.P. function to calculate the simple interest. #include<stdio.h> #include<conio.h> void main() { float interest(float,float,float); float pri,rate,year; clrscr(); printf("enter the amount,rate,year\n"); scanf("%f %f %f",&pri,&rate,&year); interest(pri,rate,year); printf("\n"); getch(); } float interest(float p,float r,float n) { float simple; simple=(p*r*n)/100; printf("simple interest is %f",simple); return 0; } o/p: Enter the amount,rate,year 5000 10 2 Simple interest is 1000.000000

Page 58

Excel Dip.Coll.

first sem

programming in c

Pra51: W.A.P. function for squaring two number. #include<stdio.h> #include<conio.h> void main() { int number; int result; int sq(int); clrscr(); printf("enter the number\n"); scanf("%d",&number); result=sq(number); printf("the result of the number is %d",result); getch(); } int sq(int number) { int res; res=number*number; return(res); } o/p: enter the number 4 The result of the number is 16

Page 59

Excel Dip.Coll.

first sem

programming in c

Pra 52: W.A.P. function raise a number to a power. #include<stdio.h> #include<conio.h> void main() { int number,raise; float result; float power(int,int); clrscr(); printf("enter the number & raise\n"); scanf("%d %d",&number,&raise); result=power(number,raise); printf("the result of the number is %.2f",result); getch(); } float power(int num,int r) { int i; float res=1.0; for(i=0;i<r;i++) { res=num*res; } return(res); } o/p: Enter the number a raise 5 4 The result of the number is 625.00

Page 60

Excel Dip.Coll.

first sem

programming in c

Pra 53: W.A.P. function swap to interchange the value of variable. #include<stdio.h> #include<conio.h> void swap(int a,int b) { int temp; temp=a; a=b; b=temp; printf("After swap function the vlue of a=%d and b=%d",a,b); } void main() { clrscr(); int a=10,b=20; printf("before swap functin the value of a=%d and b=%d\n",a,b); swap(a,b); getch(); } O/p: Before swap functin the value of a=10 and b=20 After swap function the vlue of a=20 and b=10

Page 61

Excel Dip.Coll.

first sem

programming in c

Pra54. Create the function to check whether the entered charceter is in uppercase or in lower case. #include<stdio.h> #include<conio.h> void main() { int islow(char); char chr; clrscr(); printf("enter the charcter\n"); scanf("%c",&chr); if(islow(chr)) printf("the character is lowercase\n"); else printf("the character is uppercase\n"); getch(); } int islow(char ch) { if(ch>='a' && ch<='z') return (1); else return 0; } O/P: Enter ths character K The character is uppercase

Page 62

Excel Dip.Coll.

first sem

programming in c

Pra55. Using recursion method find the factorial of number.

#include<stdio.h> #include<conio.h> void main() { int j; clrscr(); for(j=1;j<8;j++) printf("factorial of %d is=%d\n",j,factorial(j)); getch(); } factorial(int n) { int fact; if(n==0) return(1); else fact=n*factorial(n-1); return(fact); } O/P: Factorial no of 1 is=1 Factorial no of 2 is=2 Factorial no of 3 is=6 Factorial no of 4 is=24 Factorial no of 5 is=120 Factorial no of 6 is=720 Factorial no of 7 is=5040

Page 63

Excel Dip.Coll.

first sem

programming in c

Pra56. W.A.P. to generate fibonacci series using recursion function. #include<stdio.h> #include<conio.h> void main() { int fibo(int); int f,n,i; clrscr(); printf("enter the limit of fibonacci series:\n"); scanf("%d",&n); for(i=0;i<n;i++) { f=fibo(i); printf("%d\n",f); getch(); } getch(); } int fibo(int no) { int x,y; if(no==0) { return(0); } if(no==1) { return(1); } else { x=fibo(no-1);
Page 64

Excel Dip.Coll.

first sem

programming in c

y=fibo(no-2); return(x+y); } } O/P: enter the limit of fibonacci series:10 0 1 1 2 3 5 8 13 21 34

Page 65

Excel Dip.Coll.

first sem

programming in c

Pra57. W.A.P. recursion function to print the given string in reverse case . #include<stdio.h> #include<conio.h> #include<string.h> void main() { void revstr(char[]); char str[80]; clrscr(); printf("enter a string:\n"); scanf("%[^\n]",str); revstr(str); printf("%s",str); getch(); } void revstr(char s[]) { int i,j; char temp; for(i=0,j=strlen(s)-1;i<strlen(s)/2;++i,--j) { temp=s[i]; s[i]=s[j]; s[j]=temp; } } O/P: Enter a string: Shakti itkahs

Page 66

Excel Dip.Coll.

first sem

programming in c

Pra58. W.A.P. function to which gives maximum from 1-D array. #include<stdio.h> #include<conio.h> void main() { int arr[10],n,i; int max(int[],int); clrscr(); printf("How many elements?\n"); scanf("%d",&n); printf("enter %d elements below\n",n); for(i=0;i<n;i++) { scanf("%d",&arr[i]); } printf("MAXIMUM=%d",max(arr,n)); getch(); } int max(int m[],int l) { int maximum=0,i; for(i=0;i<l;i++) { if(m[i]>maximum) maximum=m[i]; } return maximum; }

Page 67

Excel Dip.Coll.

first sem

programming in c

O/P How many elements?5 Enter 5 elements below 11 56 9 65 8 Maximum=65

Page 68

Excel Dip.Coll.

first sem

programming in c

Pra59. W.A.P. function to sort a list of names in alphabetical order. #include<stdio.h> #include<conio.h> #include<string.h> void main() { void sortname(char[10][80],int); char names[10][80],i,n; clrscr(); printf("How many names?\n"); scanf("%d",&n); printf("Enter %d names below\n",n); for(i=0;i<n;i++) { scanf("%s",names[i]); } sortname(names,n); printf("\n sorted names\n"); for(i=0;i<n;i++) { printf("%s\n",names[i]); } getch(); } void sortname(char s[10][80],int n) { char temp[80],i,j; for(i=0;i<n-1;i++) {
Page 69

Excel Dip.Coll.

first sem

programming in c

for(j=i+1;j<n;j++) { if(strcmpi(s[i],s[j])>0) {strcpy(temp,s[i]); strcpy(s[i],s[j]); strcpy(s[j],temp); } } } O/P: How many names?5 Enter 5 names below Dhara Bina Amruta Pinakini Komal Sorted names Amruta Bina Dhara Komal Pinakini

Page 70

Excel Dip.Coll.

first sem

programming in c

Pra60: W.A.P to print the addres and value of variable. #include<stdio.h> #include<conio.h> void main() { char ch='a'; float f1=30.5; int i=50; clrscr(); printf("Name\t\t Value\t\tAddress\n"); printf("ch\t\t%c\t\t %X\n",ch,&ch); printf("f1\t\t%f\t\t %X\n",f1,&f1); printf("i\t\t %d\t\t %X\n",i,&i); getch(); } O/P: Name Value Address Ch a FFF5 F1 30.500000 FFF0 I 50 FFEE

Page 71

Excel Dip.Coll.

first sem

programming in c

Pra61 W.A.P. to illustrate the use of pointer in arithmetic opertaions. #include<stdio.h> #include<conio.h> void main() { char ch='a',*cptr; float f1=30.5,*fptr; int i=50,*iptr; clrscr(); cptr=&ch; fptr=&f1; iptr=&i; printf("\n char float int"); printf("%x %x %x\n",cptr,fptr,iptr); cptr++; fptr++; iptr++; printf("After increment operation"); printf("\n char float int\n"); printf("%x %x %x\n",cptr,fptr,iptr); cptr--; fptr--; iptr--; printf("After decrement operation"); printf("\n char float int\n"); printf("%x %x %x\n",cptr,fptr,iptr); cptr=cptr+2; fptr=fptr+2; iptr=iptr+2;
Page 72

Excel Dip.Coll.

first sem

programming in c

printf("After decrement operation"); printf("\n char float int\n"); printf("%x %x %x\n",cptr,fptr,iptr); cptr=cptr+2; fptr=fptr+2; iptr=iptr+2; printf("After adding by number 2"); printf("\n char float int\n"); printf("%x %x %x\n",cptr,fptr,iptr); cptr=cptr-4; fptr=fptr-4; iptr=iptr-4; printf("After decrementing by number 4"); printf("\n char float int\n"); printf("%x %x %x\n",cptr,fptr,iptr); getch(); }

Page 73

Excel Dip.Coll.

first sem

programming in c

O/P: Char Fff5 After Char Fff6 After Char Fff5 After Char Fff7 After Char Fff3

float int fff0 ffee increment operation float int fff4 ffe0 decrement operation float int fff0 ffee adding by number 2 float int fff8 ffe2 decremeting by number 4 float int fff8 ffea

Page 74

Excel Dip.Coll.

first sem

programming in c

Pra62 W.A.P. to Access the array element using pointer. #include<stdio.h> #include<conio.h> void main() { int a[10],i,n; int *ptr; clrscr(); ptr=a; printf("How many numbers?\n"); scanf("%d",&n); printf("Give numbers:\n"); for(i=0;i<n;i++) { scanf("%d",&ptr); ptr++; } ptr=a; printf("Array elements are:\n"); for(i=0;i<n;i++) { printf("%d\n",*ptr); ptr++; } getch(); }

Page 75

Excel Dip.Coll.

first sem

programming in c

O/P: How many numbers? 4 Give numbers 1 2 4 3 Array elements are: 1 2 4 3

Page 76

Excel Dip.Coll.

first sem

programming in c

Pra63 W.A.P. that exchange two integer using function with pointer arguments. #include<stdio.h> #include<conio.h> void main() { int a=10,b=20; void exchange(int*,int*); clrscr(); printf("Before exchange function:a=%d b=%d\n",a,b); exchange(&a,&b); printf("After exchange function:a=%d b=%d\n",a,b); getch(); } void exchange(int*p1,int*p2) { int temp; temp=*p1; *p1=*p2; *p2=temp; }

O/P: Before exchange function:a=10 b=20 After exchange function:a=20 b=10

Page 77

Excel Dip.Coll.

first sem

programming in c

Pra64 W.A.P. using pointer to compute the sum of the elements stored in array. #include<stdio.h> #include<conio.h> void main() { int *p,sum,i; int x[]={2,6,4,8,9}; i=0; p=x; clrscr(); printf("enter the vlaue of \n"); printf("i *p p address\n"); sum=0; while(i<5) { printf("[%d] %d %u\n",i,*p,p); sum=sum+*p; i++,p++; } printf("sum=%d\n",sum); printf("address of sum=%u\n",&sum); getch(); }

Page 78

Excel Dip.Coll.

first sem

programming in c

O/P: Enter the value i *p p address [0] 2 170 [1] 6 172 [2] 4 174 [3] 8 176 [4] 9 178 Sum=29 Address of sum=65524

Page 79

Excel Dip.Coll.

first sem

programming in c

Pra65 W.A.P. using pointer to print the address and value of string. #include<stdio.h> #include<conio.h> void main() { char *str; clrscr(); str="hello"; printf("string is %s\n",str); printf("address is %d\n",str); getch(); } O/P: String is hello Address is 170

Page 80

Excel Dip.Coll.

first sem

programming in c

Pra66 W.A.P. using pointer in direction,print the variable value. #include<stdio.h> #include<conio.h> void main() { int i=1; int *p,**q,***r; clrscr(); p=&i; q=&p; r=&q; printf("\n the value of i=%d",i); printf("\n the value of p=%d",*p); printf("\n the value of q=%d",**q); printf("\n the value of r=%d",***r); getch(); } O/P: The value of i=1 The value of p=1 The value of q=1 The value of r=1

Page 81

Excel Dip.Coll.

first sem

programming in c

Pra67 W.A. function to reverse the string and find the length of string using pointer. #include<stdio.h> #include<conio.h>

void main() { char str[100]; int i,n,count=0; char *cptr; clrscr(); printf("enter some string\n"); gets(str); cptr=str; while(*cptr!='\0') { count++; cptr++; } printf("lengeth of string %s is =%d\n",str,count); cptr--; printf("reverse of string %s is",str); while(count>0) { putchar(*cptr); count--; cptr--; } getch();
Page 82

Excel Dip.Coll.

first sem

programming in c

} O/P: Enter some string Excel Length of string excel is =5 Reverse of string Excel is lecxE

Page 83

Excel Dip.Coll.

first sem

programming in c

Pra68 W.A.P. that reads and prints student information.

#include<stdio.h> #include<conio.h> void main() { struct student { int rollno; char name[20]; char address[20]; char city[20]; int age; }; struct student s1; clrscr(); printf("give roll number\n"); scanf("%d",&s1.rollno); fflush(stdin); printf("give name\n"); gets(s1.name); printf("give address\n"); gets(s1.address); printf("give city\n"); gets(s1.city); printf("give age\n"); scanf("%d",&s1.age);
Page 84

Excel Dip.Coll.

first sem

programming in c

printf("Roll Number=%d,Name=%s,address=%s\n",s1.rollno,s1.name,s1.address); printf("City=%s,age=%d\n",s1.city,s1.age); getch(); } O/P: Give roll number 101 Give name Dhara Give address Shri nagar Give city Gnagar Give age 24 Roll number=101, Name=Dhara, Address=Shri nagar City=Gnagar, Age=24

Page 85

Excel Dip.Coll.

first sem

programming in c

Pra69 W.A.P. using nested structure and display employee information like emp no.,emp name and full address of the employee.

#include<stdio.h> #include<conio.h> void main() { struct address { int hno; char streetname[10]; char city[10]; }; struct employee { int no; char name[10]; struct address add; }emp1; clrscr(); printf("enter the no of employee\n"); scanf("%d",&emp1.no); fflush(stdin); printf("enter the name of employee\n"); scanf("%s",emp1.name); fflush(stdin); printf("enter the address of employee with hno,streetname & city\n");
Page 86

Excel Dip.Coll.

first sem

programming in c

scanf("%d",&emp1.add.hno); fflush(stdin); scanf("%s",&emp1.add.streetname); fflush(stdin); scanf("%s",&emp1.add.city); fflush(stdin); printf("the employee data is\n"); printf("empno \t empname \t empaddress\n"); printf("%d\t",emp1.no); printf("%s\t",emp1.name); printf("\t %d",emp1.add.hno); printf(",%s ",emp1.add.streetname); printf(",%s\n",emp1.add.city); getch(); } O/P: Enter the no of employee 105 Enter the name of employee Chintan Enter the address of employee with hno,streetname & city 316, shri nagar Vastrapur Abad The employee data is Empno Empname Empaddress 105 Chintan 316, shri nagar,Vastrapur,Abad

Page 87

Excel Dip.Coll.

first sem

programming in c

Pra70 Create a record of a student with roll number,name and coureses using union.find which course is selected #include<stdio.h> #include<stdlib.h> #include<conio.h> struct student { int no; char name[10]; union course { int major; char minor[10]; }courseno; }stud; void main() { char c; clrscr(); printf("enter the rollno\n"); scanf("%d",&stud.no); fflush(stdin); printf("enter the student name\n"); scanf("%d",&stud.name); fflush(stdin); printf("enter the M for major &m for minor\n"); scanf("%c",&c); fflush(stdin);
Page 88

Excel Dip.Coll.

first sem

programming in c

if(c=='M') { printf("enter the course('1')\n"); scanf("%d",&stud.courseno.major); fflush(stdin); if(stud.courseno.major==1) printf("the course is IT"); else printf("the course is computer"); } else { printf("the course is other"); } getch(); }

O/P: Enter the rollno 11 Enter the student name Dhara Entr rhe M for major &m for minor M Enter the course(1) 1 The course is IT

Page 89

Excel Dip.Coll.

first sem

programming in c

Page 90

Excel Dip.Coll.

first sem

programming in c

Page 91

You might also like