create an array (call it arr) of size 5
In a for loop , use scanf to read 5 numbers into your array
then use another for loop to add the 5 numbers in the array together and print the result.
#include <stdio.h>
int main()
{
double arr[5];
int i;
for(i = 0; i < 5; i++)
{
printf("Enter number #%d: ",i+1);
scanf("%lf", &arr[i]);
}
double total = 0;
for(i = 0; i < 5; i++)
total += arr[i];
printf("\nTotal: %g ", total);
return 0;
}
Comments
Leave a comment