C Programming
Program 1.
Declare 5 variables of type long int
Read 5 integers from the user. After you read each one, output it back to the user with the message:
You entered: xxx
Where xxx is the number that they entered.
Add up all the numbers that the user entered and output the sum to the user like this:
The sum of the numbers you entered is: xxx
Find the average of these numbers and output it with 2 places past the decimal:
The average is: xxxx.xx
Copy and paste the output from running your programs, after the code. Running the program multiple times is sometimes required. In general, more demonstration of testing your programs is better than less
#include <stdio.h> int main() { int a,b,c,d,e,sum;; float avg; scanf("%d",&a); printf("You entered %d\n",a); scanf("%d",&b); printf("You entered %d\n",b); scanf("%d",&c); printf("You entered %d\n",c); scanf("%d",&d); printf("You entered %d\n",d); scanf("%d",&e); printf("You entered %d\n",e); sum = a+b+c+d+e; printf("The sum of the numbers you entered is: %d\n",sum); avg = sum/5.0; printf("The average is: %.2f\n",avg); return 0; }
Get Answers For Free
Most questions answered within 1 hours.