Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- //Exercises
- //Problem -1)Write a C program to enter radius of a circle and find its diameter, circumference and area.
- #include<stdio.h>
- int main()
- {
- float R,D,C,A;
- printf("Enter radius of circle: ");
- scanf("%f",&R);
- D=2*R;
- C=2*3.1416*R;
- A=3.1416*(R*R);
- printf("Diameter = %f\n",D);
- printf("Circumference = f\n",C);
- printf("Area= %f \n",A);
- return 0;
- }
- //Problem -2) Write a C program to enter temperature in Celsius and convert it into Fahrenheit.
- #include<stdio.h>
- int main()
- {
- double C,F;
- printf("Enter temperature in Celsius= ");
- scanf("%lf",&C);
- F = (((C*9)/5)+32);
- printf("The temperature in Fahrenheit is = %.2lf\n",F);
- return 0;
- }
- //Problem -3) Write a C program to enter temperature in Fahrenheit and convert to Celsius.
- #include<stdio.h>
- int main()
- {
- double C,F;
- printf("Enter temperature in Fahrenheit = ");
- scanf("%lf",&F);
- C = (((F-32)/9)*5);
- printf("The temperature in Celsius is = %.2lf\n", C);
- return 0;
- }
- //Problem -4) Write a C program to enter base and height of a triangle and find its area.
- #include<stdio.h>
- int main()
- {
- double B,H,A;
- printf("Enter Base & Height = ");
- scanf("%lf %lf",&B &H);
- A = 2/(B*H);
- printf("Area of the triangle is : %.2lf\n", A);
- return 0;
- }
- //Problem -5) Write a C program to enter marks of five subjects and calculate total, average and percentage.
- #include<stdio.h>
- int main()
- {
- double A,B,C,D,E;
- double T, Av, Pr;
- scanf("%lf %lf %lf %lf %lf", %A,&B,&C,&D,&E);
- T=A+B+C+D+E;
- Av=T/5;
- P=T/5;
- printf("Total Number %.2lf\n",T)
- printf("Average Number is %.2lf\n",Av);
- printf("Percentage of the Number is %.2lf%%\n",P);
- return 0;
- }
- //Problem -6) Write a C program to enter two numbers and perform all arithmetic operations.
- #include<stdio.h>
- int main()
- {
- int A,b,sum,sub,mut,mod;
- float div;
- scanf("%d %d", &A,&B);
- sum = A+B;
- sub = A-B;
- mut = A*B;
- mod = A%B;
- div = A/B;
- printf("Sum is : %d\n", sum);
- printf("Subtract is : %d\n", sub);
- printf("Multiple is : %d\n", mut);
- printf("Modulus is : %d\n", mod);
- printf("Divided is : %.2lf\n", div);
- return 0;
- }
- //Problem -7) Write a C program to enter length and breadth of a rectangle and find its perimeter.
- #include<stdio.h>
- int main()
- {
- double l,b,p;
- scanf("%lf %lf",&l,&b);
- p=(2*(l+b));
- printf("Perimeter of the rectangle is : %.2lf\n",p);
- return 0;
- }
- //Problem -8) Write a C program to enter length and breadth of a rectangle and find its area.
- #include<stdio.h>
- int main()
- {
- double l,b,a;
- scanf("%lf %lf",&l,&b);
- a=(l*b);
- printf("Area of the rectangle is : %.2lf\n",a);
- return 0;
- }
- //Problem -9) Write a C program to enter radius of a circle and find its diameter, circumference and area.
- #include<stdio.h>
- int main()
- {
- float R,D,C,A;
- printf("Enter radius of circle: ");
- scanf("%f",&R);
- D=2*R;
- C=2*3.1416*R;
- A=3.1416*(R*R);
- printf("Diameter = %f\n",D);
- printf("Circumference = f\n",C);
- printf("Area= %f \n",A);
- return 0;
- }
- //Problem -10) Write a C program to enter length in centimeter and convert it into meter and kilometer.
- #include<stdio.h>
- int main()
- {
- int cm, m, km;
- scanf("%d", &cm);
- m = cm/100;
- km = m/1000;
- printf("Meter = %d\n",m);
- printf("Kilometer = %d\n",km);
- return 0;
- }
- //Problem -11) Write a C program to enter temperature in Celsius and convert it into Fahrenheit.
- #include<stdio.h>
- int main()
- {
- double C,F;
- printf("Enter temperature in Celsius= ");
- scanf("%lf",&C);
- F = (((C*9)/5)+32);
- printf("The temperature in Fahrenheit is = %.2lf\n",F);
- return 0;
- }
- //Problem -12) Write a C program to enter temperature in Fahrenheit and convert to Celsius.
- #include<stdio.h>
- int main()
- {
- double C,F;
- printf("Enter temperature in Fahrenheit = ");
- scanf("%lf",&F);
- C = (((F-32)/9)*5);
- printf("The temperature in Celsius is = %.2lf\n", C);
- return 0;
- }
- //Problem -13) Write a C program to convert days into years, weeks and days.
- #include<stdio.h>
- int main()
- {
- int d;
- float y,w;
- scanf("%d",&d);
- y = d/365;
- w = d/7;
- printf(" Days : %d\n", d);
- printf(" Weeks : %.2lf\n", w);
- printf(" Years : %.2lf\n", y);
- return 0;
- }
- //Problem -14) Write a C program to find power of any number x ^ y.
- #include <stdio.h>
- #include <math.h>
- int main()
- {
- int x, y, z; // z =x^y;
- scanf("%d %d", &x,&y);
- z = pow(x,y);
- printf("%d^%d=%d", x,y,z);
- return 0;
- }
- //Problem -15) Write a C program to enter any number and calculate its square root.
- #include <stdio.h>
- #include <math.h>
- int main()
- {
- int x;
- double sqrx;
- scanf("%d", &x);
- sqrx = sqrt(x);
- printf("Square root of %d is %.2lf\n", x, sqrx);
- return 0;
- }
- //Problem -16) Write a C program to enter two angles of a triangle and find the third angle.
- #include <stdio.h>
- int main()
- {
- int a,b,c,d;
- scanf("%d %d",&a,&b);
- c = a+b;
- d = 180-c;
- printf("Third angle of the triangle is %d\n", d);
- return 0;
- }
- //Problem -17) Write a C program to enter base and height of a triangle and find its area.
- #include<stdio.h>
- int main()
- {
- double b,h,a;
- printf("Enter Base=");
- scanf("%lf",&b);
- printf("Enter Height=");
- scanf("%lf",&h);
- a = (b*h)/2;
- printf("Area of the triangle is : %.2lf\n", a);
- return 0;
- }
- //Problem -18) Write a C program to calculate area of an equilateral triangle.
- #include <stdio.h>
- #include <math.h>
- int main()
- {
- int x;
- double a;
- scanf("%d", &x);
- a = (sqrt(3)/4)*(x*x);
- printf("Area of an equilateral triangle is %.2lf\n", a);
- return 0;
- }
- //Problem -19) Write a C program to enter marks of five subjects and calculate total, average and percentage.
- #include<stdio.h>
- int main()
- {
- double a, b, c, d, e;
- double t,a,p;
- scanf("%lf %lf %lf %lf %lf", &a,&b,&c,&d,&e);
- t=a+b+c+d+e;
- a=total/5;
- p=total/5;
- printf("Total Number is %.2lf\n",t);
- printf("Average Number is %.2lf\n",a);
- printf("Percentage of the Number is %.2lf%%\n",p);
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement