1. Write a program that evaluates the following expression and displays the results (remember to use exponential format to display the result):
(3.31 × 10-8 × 2.01 × 10-7) / (7.16 × 10-6 + 2.01 × 10-8)
Answer
#include <stdio.h>
int main() {
double number1 = 3.31e-8;
double number2 = 2.01e-7;
double number3 = 7.16e-6;
double number4 = 2.01e-8;
double result = (number1 * number2) / (number3 + number4);
printf("Result: %e\n", result);
return 0;
}
2. Write a program to input your mid term marks of a subject marked out of 30 and the final exam marks out of 100. Calculate and print the final results. Final Result = Mid Term + 70% of Final Mark
#include <stdio.h>
int main() {
int midTermMarks;
int finalExamMarks;
double finalResult;
printf("Enter mid-term marks [out of 30]: ");
scanf("%d", &midTermMarks);
printf("Enter final exam marks [out of 100]: ");
scanf("%d", &finalExamMarks);
finalResult = midTermMarks + 0.7 * finalExamMarks;
printf("Final Result: %.2f\n", finalResult);
return 0;
}
3.Write a program to input the radius of a sphere and to calculate the volume of the sphere.
Volume = 4/3*pi*radius3
Answer
#include <stdio.h>
int main()
{
float r;
float v;
const PI=3.14;
printf("Enter the radius of the sphere:");
scanf("%f",&r);
v = (4/3)*PI* r*r*r;
printf("Volume of the sphere:%f",v);
return 0;
}
4. To round off an integer i to the next largest even multiple of another integer j, the following formula can be used:
Next_multiple = i + j - i % j
For example, to round off 256 days to the next largest number of days evenly divisible by a week, values of i = 256 and j = 7 can be substituted into the preceding formula as follows:
Next_multiple = 256 + 7 - 256 % 7
= 256 + 7 - 4
= 259
Write a program to find the next largest even multiple for the following values of i and j: (Use keyboard to input values for i and j)
Answer
#include <stdio.h>
int main()
{
int i,j,next_multiple;
printf("Enter the value of an i:");
scanf("%i",&i);
printf("\nEnter the value of an j:");
scanf("%i",&j);
next_multiple=i+j-(i%j);
printf("\nNext largest even multiple=%i",next_multiple);
return 0;
}
0 Comments