1. Write a program that does the following:
a. Prompts the user to input five floating-point numbers (real numbers).
b. Prints the five floating-point numbers.
c. Adds the five floating-point numbers.
d. Prints the sum and average of the five floating-point numbers.
Case I: Complete the program by using any number of variables.
Case II: Complete the program just by using two variables- #include<stdio.h>
- int main(){
- double a,b,c,d,e,f,g;
- printf("case1\n");
- printf("please input five real number\n");
- printf("No.1:");
- scanf(" %lf", &a);
- printf("\nNo.2:");
- scanf(" %lf", &b);
- printf("\nNo.3:");
- scanf(" %lf", &c);
- printf("\nNo.4:");
- scanf(" %lf", &d);
- printf("\nNo.5:");
- scanf(" %lf", &e);
- printf("\n The five number: %lf %lf %lf %lf %lf", a, b, c, d, e);
- f = a+b+c+d+e;
- g = f/5;
- printf("\n sum: %lf", f);
- printf("\n average: %lf", g);
- printf("\n\n\ncase2\n");
- printf("please input five real number\n");
- printf("No.1:");
- scanf(" %lf", &a);
- printf("\nNo.1 is %lf",a);
- printf("\n\nNo.2:");
- scanf(" %lf", &b);
- printf("\nNo.2 is %lf",b);
- a = a+b;
- printf("\n\nNo.3:");
- scanf(" %lf", &b);
- printf("\nNo.3 is %lf",b);
- a = a+b;
- printf("\n\nNo.4:");
- scanf(" %lf", &b);
- printf("\nNo.4 is %lf",b);
- a = a+b;
- printf("\n\nNo.5:");
- scanf(" %lf", &b);
- printf("\nNo.5 is %lf",b);
- a = a+b;
- b = a/5;
- printf("\n sum: %lf", a);
- printf("\n average: %lf", b);
- return 0;
-
- }
複製代碼 |