Practice Set 1
unknown
c_cpp
a month ago
1.5 kB
2
Indexable
Never
// Program 1 #include <stdio.h> int main() { int a; printf("Enter value of A: "); scanf("%d", &a); printf("A: %d\n", a); int b; printf("Enter value of B: "); scanf("%d", &b); printf("B: %d\n", b); int c = a * b; printf("C: %d", c); return 0; } // Program 2 #include <stdio.h> #define PI 3.14 int main() { double radius, area; // Input radius printf("Enter the radius of the circle: "); scanf("%lf", &radius); // Calculate area area = PI * radius * radius; // Output result printf("The area of the circle is: %.2f\n", area); return 0; } // Program 3 #include <stdio.h> int main() { double celsius, fahrenheit; // Input Celsius temperature printf("Enter temperature in Celsius: "); scanf("%lf", &celsius); // Convert to Fahrenheit fahrenheit = (celsius * 9/5) + 32; // Output result printf("Temperature in Fahrenheit: %.2f\n", fahrenheit); return 0; } // Program 4 #include <stdio.h> int main() { double principal, rate, time, simpleInterest; // Input values printf("Enter the principal amount: "); scanf("%lf", &principal); printf("Enter the rate of interest (per annum): "); scanf("%lf", &rate); printf("Enter the time period (in years): "); scanf("%lf", &time); // Calculate simple interest simpleInterest = (principal * rate * time) / 100; // Output result printf("The simple interest is: %.2f\n", simpleInterest); return 0; }
Leave a Comment