Advertisement
Salman532

Salman Hasan Mim.c

May 19th, 2019
92
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 6.39 KB | None | 0 0
  1. //Exercises
  2. //Problem -1)Write a C program to enter radius of a circle and find its diameter, circumference and area.
  3.  
  4. #include<stdio.h>
  5. int main()
  6. {
  7.     float R,D,C,A;
  8.     printf("Enter radius of circle: ");
  9.     scanf("%f",&R);
  10.     D=2*R;
  11.     C=2*3.1416*R;
  12.     A=3.1416*(R*R);
  13.     printf("Diameter = %f\n",D);
  14.     printf("Circumference = f\n",C);
  15.     printf("Area= %f \n",A);
  16.     return 0;
  17. }
  18.  
  19. //Problem -2) Write a C program to enter temperature in Celsius and convert it into Fahrenheit.
  20.  
  21. #include<stdio.h>
  22. int main()
  23. {
  24.     double C,F;
  25.     printf("Enter temperature in Celsius= ");
  26.     scanf("%lf",&C);
  27.     F = (((C*9)/5)+32);
  28.     printf("The temperature in Fahrenheit is = %.2lf\n",F);
  29.     return 0;
  30. }
  31.  
  32. //Problem -3) Write a C program to enter temperature in Fahrenheit and convert to Celsius.
  33.  
  34. #include<stdio.h>
  35. int main()
  36. {
  37.     double C,F;
  38.     printf("Enter temperature in Fahrenheit = ");
  39.     scanf("%lf",&F);
  40.     C = (((F-32)/9)*5);
  41.     printf("The temperature in Celsius is = %.2lf\n", C);
  42.     return 0;
  43. }
  44.  
  45. //Problem -4) Write a C program to enter base and height of a triangle and find its area.
  46.  
  47. #include<stdio.h>
  48. int main()
  49. {
  50.     double B,H,A;
  51.     printf("Enter Base & Height = ");
  52.     scanf("%lf %lf",&B &H);
  53.     A = 2/(B*H);
  54.     printf("Area of the triangle is : %.2lf\n", A);
  55.     return 0;
  56. }
  57.  
  58. //Problem -5) Write a C program to enter marks of five subjects and calculate total, average and percentage.
  59.  
  60. #include<stdio.h>
  61. int main()
  62. {
  63.     double A,B,C,D,E;
  64.     double T, Av, Pr;
  65.     scanf("%lf %lf %lf %lf %lf", %A,&B,&C,&D,&E);
  66.     T=A+B+C+D+E;
  67.     Av=T/5;
  68.     P=T/5;
  69.     printf("Total Number %.2lf\n",T)
  70.     printf("Average Number is %.2lf\n",Av);
  71.     printf("Percentage of the Number is %.2lf%%\n",P);
  72.     return 0;
  73. }
  74.  
  75. //Problem -6) Write a C program to enter two numbers and perform all arithmetic operations.
  76.  
  77. #include<stdio.h>
  78. int main()
  79. {
  80.     int A,b,sum,sub,mut,mod;
  81.     float div;
  82.     scanf("%d %d", &A,&B);
  83.     sum = A+B;
  84.     sub = A-B;
  85.     mut = A*B;
  86.     mod = A%B;
  87.     div = A/B;
  88.     printf("Sum is : %d\n", sum);
  89.     printf("Subtract is : %d\n", sub);
  90.     printf("Multiple is : %d\n", mut);
  91.     printf("Modulus is : %d\n", mod);
  92.     printf("Divided is : %.2lf\n", div);
  93.     return 0;
  94. }
  95.  
  96. //Problem -7) Write a C program to enter length and breadth of a rectangle and find its perimeter.
  97.  
  98. #include<stdio.h>
  99. int main()
  100. {
  101.     double l,b,p;
  102.     scanf("%lf %lf",&l,&b);
  103.     p=(2*(l+b));
  104.     printf("Perimeter of the rectangle is : %.2lf\n",p);
  105.     return 0;
  106. }
  107.  
  108. //Problem -8) Write a C program to enter length and breadth of a rectangle and find its area.
  109.  
  110. #include<stdio.h>
  111. int main()
  112. {
  113.     double l,b,a;
  114.     scanf("%lf %lf",&l,&b);
  115.     a=(l*b);
  116.     printf("Area of the rectangle is : %.2lf\n",a);
  117.     return 0;
  118. }
  119.  
  120. //Problem -9) Write a C program to enter radius of a circle and find its diameter, circumference and area.
  121.  
  122. #include<stdio.h>
  123. int main()
  124. {
  125.     float R,D,C,A;
  126.     printf("Enter radius of circle: ");
  127.     scanf("%f",&R);
  128.     D=2*R;
  129.     C=2*3.1416*R;
  130.     A=3.1416*(R*R);
  131.     printf("Diameter = %f\n",D);
  132.     printf("Circumference = f\n",C);
  133.     printf("Area= %f \n",A);
  134.     return 0;
  135. }
  136.  
  137. //Problem -10) Write a C program to enter length in centimeter and convert it into meter and kilometer.
  138.  
  139. #include<stdio.h>
  140. int main()
  141. {
  142.     int cm, m, km;
  143.     scanf("%d", &cm);
  144.     m = cm/100;
  145.     km = m/1000;
  146.     printf("Meter = %d\n",m);
  147.     printf("Kilometer = %d\n",km);
  148.  
  149.     return 0;
  150. }
  151.  
  152. //Problem -11) Write a C program to enter temperature in Celsius and convert it into Fahrenheit.
  153.  
  154. #include<stdio.h>
  155. int main()
  156. {
  157.     double C,F;
  158.     printf("Enter temperature in Celsius= ");
  159.     scanf("%lf",&C);
  160.     F = (((C*9)/5)+32);
  161.     printf("The temperature in Fahrenheit is = %.2lf\n",F);
  162.     return 0;
  163. }
  164.  
  165. //Problem -12) Write a C program to enter temperature in Fahrenheit and convert to Celsius.
  166. #include<stdio.h>
  167. int main()
  168. {
  169.     double C,F;
  170.     printf("Enter temperature in Fahrenheit = ");
  171.     scanf("%lf",&F);
  172.     C = (((F-32)/9)*5);
  173.     printf("The temperature in Celsius is = %.2lf\n", C);
  174.     return 0;
  175. }
  176.  
  177. //Problem -13) Write a C program to convert days into years, weeks and days.
  178.  
  179. #include<stdio.h>
  180. int main()
  181. {
  182.     int d;
  183.     float y,w;
  184.     scanf("%d",&d);
  185.     y = d/365;
  186.     w = d/7;
  187.     printf(" Days : %d\n", d);
  188.     printf(" Weeks : %.2lf\n", w);
  189.     printf(" Years : %.2lf\n", y);
  190.    
  191.     return 0;
  192. }
  193.  
  194. //Problem -14) Write a C program to find power of any number x ^ y.
  195.  
  196. #include <stdio.h>
  197. #include <math.h>
  198. int main()
  199. {
  200.     int x, y, z; // z =x^y;
  201.  
  202.     scanf("%d %d", &x,&y);
  203.  
  204.     z = pow(x,y);
  205.  
  206.     printf("%d^%d=%d", x,y,z);
  207.  
  208.     return 0;
  209. }
  210.  
  211. //Problem -15) Write a C program to enter any number and calculate its square root.
  212.  
  213. #include <stdio.h>
  214. #include <math.h>
  215. int main()
  216. {
  217.     int x;
  218.     double sqrx;
  219.     scanf("%d", &x);
  220.  
  221.     sqrx = sqrt(x);
  222.  
  223.     printf("Square root of %d is %.2lf\n", x, sqrx);
  224.    
  225.     return 0;
  226. }
  227.  
  228. //Problem -16) Write a C program to enter two angles of a triangle and find the third angle.
  229.  
  230. #include <stdio.h>
  231. int main()
  232. {
  233.     int a,b,c,d;
  234.     scanf("%d %d",&a,&b);
  235.  
  236.     c = a+b;
  237.     d = 180-c;
  238.  
  239.     printf("Third angle of the triangle is %d\n", d);
  240.  
  241.     return 0;
  242. }
  243.  
  244. //Problem -17) Write a C program to enter base and height of a triangle and find its area.
  245.  
  246. #include<stdio.h>
  247. int main()
  248. {
  249.     double b,h,a;
  250.  
  251.     printf("Enter Base=");
  252.     scanf("%lf",&b);
  253.     printf("Enter Height=");
  254.     scanf("%lf",&h);
  255.  
  256.     a = (b*h)/2;
  257.  
  258.     printf("Area of the triangle is : %.2lf\n", a);
  259.  
  260.     return 0;
  261. }
  262.  
  263. //Problem -18) Write a C program to calculate area of an equilateral triangle.
  264.  
  265. #include <stdio.h>
  266. #include <math.h>
  267. int main()
  268. {
  269.     int x;
  270.     double a;
  271.     scanf("%d", &x);
  272.  
  273.     a = (sqrt(3)/4)*(x*x);
  274.  
  275.     printf("Area of an equilateral triangle is %.2lf\n", a);
  276.  
  277.     return 0;
  278. }
  279.  
  280. //Problem -19) Write a C program to enter marks of five subjects and calculate total, average and percentage.
  281.  
  282. #include<stdio.h>
  283. int main()
  284. {
  285.     double a, b, c, d, e;
  286.     double t,a,p;
  287.     scanf("%lf %lf %lf %lf %lf", &a,&b,&c,&d,&e);
  288.  
  289.     t=a+b+c+d+e;
  290.     a=total/5;
  291.     p=total/5;
  292.  
  293.     printf("Total Number is %.2lf\n",t);
  294.     printf("Average Number is %.2lf\n",a);
  295.     printf("Percentage of the Number is %.2lf%%\n",p);
  296.  
  297.     return 0;
  298. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement