1. Write a C program that will convert Second into Minute and Hour.
2. Write a C program that will enter marks of three Quizzes calculate the mean
of this marks. (Mean and Total)
3. Write a C program to find (x+b)2
output.
4. Write a C program to enter base and height of a triangle and find its area.
5. Write a C program to calculate area of an equilateral triangle.
1. Write a C program that will convert Second into Minute and Hour.
#include <stdio.h>
int main() {
int sec, h, m, s;
printf("Input seconds: ");
scanf("%d", &sec);
h = (sec/3600);
m = (sec -(3600*h))/60;
s = (sec -(3600*h)-(m*60));
printf("H:M:S - %d:%d:%d\n",h,m,s);
getchar();
getchar();
return 0;
}
2. Write a C program that will enter marks of three Quizzes calculate the meanof this marks. (Mean and Total)
#include <stdio.h>
int main()
{
int q1, q2, q3,total=0;
float mean;
printf("Enter three quizzes: ");
scanf("%d %d %d", &q1, &q2, &q3);
total=(q1 + q2 + q3);
mean = total/3.0;
printf("The total is: %d\n", total);
printf("The mean is: %.2f", mean);
getchar();
getchar();
return 0;
}
3. Write a C program to find (x+b)2 output.
#include <stdio.h>
int main()
{
float x,b,result;
printf("Enter x and b: ");
scanf("%f %f", &x, &b);
result= (x+b)*(x+b);
printf("(%.2f + %.2f)^2 = %.2f\n", x,b,result);
getchar();
getchar();
return 0;
}
4. Write a C program to enter base and height of a triangle and find its area.
#include <stdio.h>
int main()
{
float base,height,area;
printf("Enter a base of a triangle: ");
scanf("%f",&base);
printf("Enter a height of a triangle: ");
scanf("%f",&height);
area = 0.5*base * height;
printf("The area of a triangle: %.2f\n",area);
getchar();
getchar();
return 0;
}
5. Write a C program to calculate area of an equilateral triangle.
#include <stdio.h>
#include <cmath>
int main()
{
float side,area;
printf("Enter a side of a triangle: ");
scanf("%f",&side);
area = (sqrt(3.0)/4.0)* side*side;
printf("The area of a triangle: %.2f\n",area);
getchar();
getchar();
return 0;
}
Comments
Leave a comment