In: Computer Science
Write a program which uses a while loop to add the following numbers: 5, 52, 31, and 65 and output the sum of those numbers. Your output should look like this: The sum of (list the numbers) is ( give the result). //In C language
Upload a screen shot of your program and the results of running the program.
From the question, I am taking that the numbers are present in an array of size 4. Coding platform used is CodeBlocks.
Here is the screen shot of the code in C as well as the running program.
#include <stdio.h>
#include <stdlib.h>
int main()
{
int arr[4] = {5,52,31,65};
int i=0, sum=0;
while(i<4){
sum+= arr[i];
i++;
}
printf("The sum of %d, %d, %d, %d is %d.
",arr[0],arr[1],arr[2],arr[3],sum);
return 0;
}