Sie sind auf Seite 1von 16

PRACTICALS TO WRITE

1.WAP to find area of circle


#include<stdio.h>
void main()
{
float Ar,rad; // Declaration of variables
rad=2.5; //Assignment of value of radius
Ar=3.14*rad*rad; //calculating area of circle
printf(AREA OF CIRCLE IS: %f,Ar); //printing the value of Area calculated
getch();
} //end of main() function
2.WAP to cal. area of sphere
#include<stdio.h>
void main()
{
float Ar_sphr,rad;
rad=2.5;
Ar_sphr=4*3.14*rad*rad;
printf(AREA OF SPHERE IS: %f,Ar_sphr);
getch();
}
3.WAP to cal area of triangle
#include<stdio.h>
void main()
{
float Ar_traingle,b,ht;
printf(ENTER BASE AND HEIGHT OF TRAINGLE);
scanf(%f%f,&b,&ht);
Ar=(b*ht)/2;
printf(AREA OF TRAINGLE IS: %f,Ar_traingle);
getch();
}
4.WAP to calculate circumference of circle
#include<stdio.h>
void main()
{
float C,rad;
printf(ENTER THE RADIUS OF CIRCLE);
scanf(%f,&rad)
C=2*3.14*rad;
printf(CIRCUMFERANCE OF CIRCLE IS: %f,C);
getch();
}



5.WAP to find area of rectangle .
#include<stdio.h>
void main()
{
float len,b,Ar_rect;
printf(ENTER LENGTH AND BREADTH OF RECTNGLE:);
scanf(%f%f,&len,&b);
Ar_rect=len*b;
printf(AREA OF RECTANGLE IS: %f,Ar_rect);
getch();
}

6.WAP to calculate Simple Interest .
#include<stdio.h>
void main()
{
float P,R,T,SI;
printf(ENTER PRINCIPLE AMOUNT:);
scanf(%f,&P);
printf(ENTER RATE:);
scanf(%f,&R);
printf(ENTER TIME:);
scanf(%f,&T);
SI=(P*R*T)/100;
printf(SIMPLE INTEREST IS: %f,SI);
getch();
}

7.WAP to cal .surface area & volume of sphere
#include<stdio.h>
#define PI 3.14
void main()
{
float Ar_sphr,rad,Vol_sphr;
printf(ENTER RADIUS OF SPHERE);
scanf(%f,&rad);
Ar_sphr=4*PI*rad*rad;
Vol_sphr=(4*PI*rad*rad*rad)/3;
printf(AREA OF SPHERE IS=%f and VOLUME OF SPHERE IS=%f ,Ar_sphr,Vol_sphr);
getch();
}



8.WAP to cal vol of cone.
#include<stdio.h>
#define PI 3.14
void main()
{
float Vol_cone,rad,h;
printf(ENTER RADIUS AND HEIGHTOF CONE);
scanf(%f%f,&rad,&h);
Vol_cone=(PI*rad*rad*h)/3;
printf(VOLUME OF CONE IS=%f ,Vol_cone);
getch();
}
9.WAP to cal. Total surface area of a cuboid.
#include<stdio.h>
void main()
{
float l,b,h,TSA;
printf(ENTER LENGTH,BREADTH AND HEIGHT OF CONE);
scanf(%f%f%f,&l,&b,&h);
TSA=(2*(l*b+b*h+h*l));
printf(TSA OF CUBOID IS=%f ,TSA);
getch();
}

10. WAP to add, sub,multiply,divide two no.s
#include<stdio.h>
void main()
{
float num1,num2,add,sub,mul,div;
printf(ENTER TWO NUMBERS);
scanf(%f%f,&num1,&num2);
add=num1+num2;
sub=num1-num2;
mul=num1*num2;
div=num1/num2;
printf(\nADDITION IS %f \n DIFFERENCE IS %f \n MULTIPLICATION IS %f \n DIVISION IS %f ,
add,sub,mul,div);
getch();
}





11. WAP to convert Fahrenheit into Celsius temperature degree (F=1.8*C+32)
C/100=(F-32)180
#include<stdio.h>
void main()
{
float F,C;
printf(ENTER degree FAHREINHEIT );
scanf(%f, &F);
C=9*(F-32)/5;
printf(%f FAHRENHEIT in degree CELCIUS IS=%f ,F,C);
getch();
}


12. WAP to find greatest of 2 no.s
#include<stdio.h>
void main()
{
float num1,num2;
printf(ENTER NUM1 AND NUM2);
scanf(%f%f,&num1,&num2);
if(num1>num2)
{
printf(NUM1 IS GREATER);
}
else
{
printf(NUM2 IS GREATER);
}
getch();
}








13. WAP to find greatest of 3 no.s using nested if
#include<stdio.h>
void main()
{
float num1,num2;
printf(ENTER NUM1 ,NUM2 AND NUM3);
scanf(%f%f%f,&num1,&num2,&num3);
if(num1>num2)
{
if(num1>num3)
{
printf(NUM1 IS GREATER);
}
else
{
printf(NUM3 IS GREATER);
}
else
{
if(num2>num3)
{
printf(NUM2 IS GREATER);
}
else
{
printf(NUM3 IS GREATER);
}
}
getch();
}
14. WAP to check whether a person is eligible for voting or no.
#include<stdio.h>
void main()
{ int age;
printf(ENTER AGE OF A PERSON);
scanf(%d,&age);
if(age>=18)
{
printf(YOU ARE ELIGIBLE FOR VOTING);
}
else
{
printf(YOU ARE NOT ELIGIBLE FOR VOTING);
}
getch();
}
15.WAP to find sum of its digits.
#include<stdio.h>
void main()
{ long num,n;
int sum=0,n1;
printf(ENTER ANY NUMBER\n);
scanf(%d,&num);
n=num; // to preserve the value of num
while(n>0)
{
n1=n%10;
n=n%10;
sum=sum+n1;
}
printf(NUM IS: %ld\n,num);
printf(SUM OF ITS DIGITS IS:%d,sum);
getch();
}

16. WAP to enter day 1-7 and print the corresponding day using swith case .
#include<stdio.h>
void main()
{
int n ; //clrscr();
printf("ENTER CHOICE");
scanf("%d",&n);
switch(n)
{
case 1:
printf("monday");
break;
case 2:
printf("tuesday");
break;
case 3:
printf("wednesday");
break;
case 4:
printf("thursday");
break;
case 5:
printf("friday");
break;
case 6:
printf("satarday");
break;
case 7:
printf("sunday");
break;

default:
printf("wrong choice");

}
printf("\n");
getch();
}
17. WAP to calculate percentage and print the corresponding grade of a student.
#include<stdio.h>
void main()
{
float m1,m2,m3,m4,m5;
float per;
printf(ENTER MARKS OF 5 SUBJECTS);
scanf(%f%f%f%f%f,&m1,&m2,&m3,&m4,&m5);
per=((m1+m2+m3+m4+m5)/5)*100;
if(per>=75)
{
printf(HONORS);
}
else if(per>=65)
{
printf(FIRST DIVISION);
}
else if(per>=50)
{
printf(SECOND DIVISION);
}
else if(per>=40)
{
printf(THIRD DIVISION);
}
else
{ printf(FAIL);
}
getch();
}







18. WAP to check that number is even or odd.
#include<stdio.h>
void main()
{
int num;
printf(ENTER NUMBER);
scanf(%d,&num);
if(num%2==0)
{
printf(NUM1 IS EVEN);
}
else
{
printf(NUM2 IS ODD);
}
getch();
}
19.WAP to print 1 to 10 using for loop,while loop & do-while loop .
#include<stdio.h>
void main()
{
int i;
for(i=1;1<=10;i++) // using for loop
{
printf(%2d,i);
}
getch();
}
// using while loop
#include<stdio.h>
void main()
{
int i=1;
while(i<=10)
{
printf(%2d,i);
i++;
}
getch();
}
// using do-while loop
#include<stdio.h>
void main()
{
int i=1;
do
{
printf(%2d,i);
i++;
} while(i<=10);
getch();
}

20.WAP to swap two no.s
#include<stdio.h>
void main()
{
int num1,num2,temp;
printf(ENTER 2 NUMBERS);
scanf(%d%d,&num1,&num2);
printf(NUM1=%d & NUM2 =%d :,num1,num2);
temp=num1;
num1=num2;
num2=temp;
printf(AFTER SWAPPING NUM1=%d & NUM2 =%d :,num1,num2);
getch();
}
.
21. WAP to print the fibbonacci series
0,1,1,2,3,5,8,....n terms
#include<stdio.h>
void main()
{
int prev=0,nxt,curr=1,n,count=2;
printf(ENTER THE NUMBER OF TERMS);
scanf(%d,&n);
printf(%d %d,prev,nxt);
while(count<n)
{
nxt=prev+curr;
printf(%dnxt);
count++;
prev=curr;
curr=nxt;
}
printf(\n);
getch();
}



22. WAP to print following sum of series
1/1! + 2/2!+ 3/3!+......n terms
#include<stdio.h>
void main()
{
int n,t,fact,i,j;
int sum=0;
printf(ENTER No. OF TERMS);
scanf(%d,&n);
for(i=1;i<=n;i++) // loop for executing up to nth term times
{
fact=1;
for(j=1;j<=i;j++) //loop for finding factorial
{
fact=fact*j;
}
t=i/fact;
sum=sum+t;
}
printf(SUM OF SERIES IS %f,sum);
getch();
}
23.WAP to print multiplication table from 1 to 10.
#include<stdio.h>
#define COLMAX 10
#define ROWMAX 10
void main()
{
int R,C,Y;
R=1;
printf(MULTIPLICATION TABLE);
do // outer loop begins
{ C=1;
do //inner loop begins
{
Y=R*C;
printf(%4d,Y);
C=C+1;
} while(C<=COLMAX); // inner loop ends
printf(\n);
R=R+1;
} while(R<=ROWMAX); // outer loop ends
getch();
}


24.WAP to find sum of series


#include<stdio.h>
void main()
{
float n,t,i;
float sum=0;
printf(ENTER No. OF TERMS);
scanf(%d,&n);
for(i=1;i<=n;i++)
{
t=i/((i+1)*(i+2));
sum=sum+t;
}
printf(SUM OF SERIES IS %f,sum);
getch();
}

25. WAP to print the following pattern
1
1 2
1 2 3
1 2 3 4
#include<stdio.h>
void main()
{
int n,i,j;
printf(ENTER No. OF TERMS);
scanf(%d,&n);
for(i=1;i<=n;i++) //outer loop for rows
{
for(j=1;j<=i;j++) // inner loop for columns
{
printf(%2d,j);
}
printf(\n);
getch();
}





26. WAP to print the following pattern.
1
1 2
1 2 3
1 2 3 4
#include<stdio.h>
void main()
{
int n,i,j,k;
printf(ENTER No. OF TERMS);
scanf(%d,&n);
for(i=1;i<=n;i++) //loop for rows
{
for(j=n;j>i;j--) //loop for printing space
{
printf( );
}
for(k=1;k<=i;k++) //loop for printing value
{
printf(%2d,k);
}
printf(\n);
getch();
}
27. WAP to sort 'n' numbers in ascending order.
#include<stdio.h>
void main()
{
int arr[10],n,temp,k;
printf(ENTER SIZE OF ARRAY );
scanf(%d,&n); // size should be< =10
for(i=0;i<n;i++)
{
scanf(%d,&arr[i]);
}
for(j=0;j<n-1;j++)
{
for(i=1;i<n-j-1;i++)
{
if(arr[i]>arr[i+1])
{
temp=arr[i];
arr[i]=arr[i+1];
arr[i+1]=temp;
}
}
printf(\n ARRAY OF ELEMENTS AFTER SORTING)
for(i=0;i<n;i++)
{
printf(%d,&arr*i+);
}
printf(\n);
getch();
}
28. WAP perform matrix addition using 2D arrays.
C
ij
=A
ij
+ B
ij
#include<stdionh>
void main()
{
float A[10][10],B[10][10],C[10][10];
int n,m,I,j;
printf(\nENTER SIZE OF MATRICES as m,n);
scanf(%d%d,&m,&n);
printf(\nENTER %d elements of matrix A row-wise ,m*n);
for(i=0;i<m;i++)
{
for(i=0;j<n;j++)
{
scanf(%f,&A*i+*j+);
}
}
printf(\nENTER %d elements of matrix B row-wise ,m*n);
for(i=0;i<m;i++)
{
for(i=0;j<n;j++)
{
scanf(%f,&B*i+*j+);
}
}
for(i=0;i<m;i++)
{
for(i=0;j<n;j++)
{
C[i][j]=A[i][j]+B[i][j];
}
}
printf(\nSUM OF A+B matrix is:);
for(i=0;i<m;i++)
{
for(i=0;j<n;j++)
{ printf(%7.2f,&C*i+*j+); }
printf(\n);
} getch();
}
29. WAP to create a structure with tag as STUDENT having the following members & read the values
using scanf() & display values
FIELD NAME

DATA TYPE
Name String

Department String
Roll No. Integer
Mark

Integer



#include<stdio.h>
#include<string.h>
struct STUDENT
{
char name[25];
int Roll_no;
int marks;
char dept[20];
};
void main()
{
struct STUDENT stud1;
clrscr();
printf("ENTER STUDENT NAME");
gets(stud1.name);
printf("\nENTER BRANCH");
gets(stud1.dept);
//scanf("%s",&stud1.name);
printf("\nENTER STUDENT ROLLNO.");
scanf("%d",&stud1.Roll_no);
printf("\nENTER STUDENT MARKS");
scanf("%d",&stud1.marks);
printf("\nSTUDENT DETAILS");
printf("\n\nNAME OF STUDENT::%s",stud1.name);
printf("\nSTUDENT BRANCH::%s",stud1.dept);
printf("\nROLL NO. OF STUDENT::%d",stud1.Roll_no);
printf("\nMARKS OBTAINED ::%d",stud1.marks);
getch();
}





30.WAP to swap two numbers using call by reference
#include<stdio.h>
#include<conio.h>
void main( )
{
int a,b;
void swap(int *,int *);
printf(Enter two values :);
scanf(%d%d,&a,&b);
printf(Values before swapping: a=%d,b=%d,a,b);
swap(&a,&b);
printf(Values after swapping : a=%d, b=%d,*p,*p1);
getch( );
}
void swap(int *x,int *y)
{
int t;
t=*x;
*x=*y;
*y=t;
}

31.WAP to swap two numbers using call by value

#include<stdio.h>
#include<conio.h>
void main( )
{
int a,b;
void swap(int *,int *);
printf(Enter two values :);
scanf(%d%d,&a,&b);
printf(Values before swapping: a=%d,b=%d,a,b);
swap(a,b);
printf(Values after swapping : a=%d, b=%d,*p,*p1);
getch( );
}
void swap(int x,int y)
{
int t;
t=x;
x=y;
y=t;
}




32.WAP to reverse a number
#include<stdio.h>
int rev(int n);
int s=0;
void main()
{
int n,r;
printf("enter a number:");
scanf("%d",&n);
r=rev(n);
printf("reverse of %d is=%d",n,r);
getch();
}

int rev(int n)
{
if(n==0)
return 0;
else
{
s=s*10+n%10;
rev(n/10);
}
return s;
}

Das könnte Ihnen auch gefallen