C programming- Sequential Program

1. WAP to calculate sum of two numbers

#include <stdio.h>

int main()

{

    int a,b,sum;

 printf("Enter two numbers:”);

 scanf("%d %d", &a,&b);

 sum=a+b;

 printf("Sum= %d", sum);

 return 0;

}

output

Enter two numbers:2

3

Sum= 5

 

#include <stdio.h>

int main()

{

    int a,b,sum;

 printf("Enter two numbers:”);

 scanf("%d %d", &a,&b);

 sum=a+b;

 printf("Sum of %d and %d = %d", a,b,sum);

 return 0;

}

output

Enter two numbers:2

3

Sum of 2 and 3 = 5

 

2.  WAP to calculate the area of a rectangle in c. [Hints: a = l x b]

 #include <stdio.h>

int main()

{

    int b,l,area;

 printf("Enter length and breadth:”);

 scanf("%d %d", &l,&b);

area=l*b;

 printf("area of rectangle = %d", area);

 return 0;

}

output

Enter length and breadth:3

4

area of rectangle = 12

 

3. WAP to calculate the simple interest in c. [Hints: i= (ptr)/100]

#include <stdio.h>

int main()

{

    float p,t,r,si;

 printf("Enter principle,time,rate:”);

 scanf("%f %f %f", &p,&t,&r);

si=(p*t*r)/100;

 printf("simple interest = %f", si);

 return 0;

}

Output

Enter principle,time,rate:1000

2

12

simple interest = 240.000000

 

4. WAP to calculate the average of three number in c. [Hints: avg= (a+b+c)/3]

#include <stdio.h>

int main()

{

    float a,b,c,avg;

 printf("Enter three numbers:”);

 scanf("%f %f %f", &a,&b,&c);

avg=(a+b+c)/3;

 printf("average of three numbers = %f", avg);

 return 0;

}

Output

Enter three numbers:2

8

7

average of three numbers = 5.666667 

 

5.      WAP to calculate the volume of cylinder in c. [Hints: v= pi*r*r*h]

 #include <stdio.h>

int main()

{

    float pi=3.14,r,h,v;

 printf("Enter radius and height:”);

 scanf("%f %f", &r,&h);

v= pi*r*r*h;

 printf("volume of cylinder = %f", v);

 return 0;

}

Output

 

Enter radius and height:2

4

volume of cylinder = 50.240002 

6.  WAP to calculate the area of circle in c. [Hints: a= pi*r*r]

7.  WAP to calculate the circumference of circle in c. [Hints: c= 2pi*r]

8. WAP To convert degree Celsius and convert it into degree Fahrenheit where f=(9*c/5)+32.

9. WAP To find square of given number.

#include <stdio.h>

#include <math.h>

int main()

{

    int n,s;

 printf("Enter a number”);

 scanf("%d", &n);

s=pow(n,2);

 printf("square of %d = %d", n,s);

 return 0;

}

Output

Enter a number2

square of 2 = 4

10. WAP To find square root of given number.

#include <stdio.h>

#include <math.h>

int main()

{

    int n,s;

 printf("Enter a number”);

 scanf("%d", &n);

s=sqrt(n);

 printf("squareroot of %d = %d", n,s);

 return 0;

}

Popular posts from this blog

Computer

Sequential Programs