15a I need help writing this C program (not C++) Please use horizontal and verti
ID: 3624900 • Letter: 1
Question
15a I need help writing this C program (not C++) Please use horizontal and vertical spacingWrite a simple C program that will:
Declare an integer variable and give it an initial value of zero.
Declare a ten element integer array named myarray.
Using a printf/scanf pair in a for loop, input integers into the ten elements of the array.
Use a second for loop to compute the sum of the ten values, storing the result in an appropriately named variable.
Use a single printf to display "The sum is: " followed by the value your program computed as the sum. End the line with a newline character.
Explanation / Answer
#include<stdio.h>
#include<conio.h>
int main()
{
int a=0,sum=0; // Declare an integer variable and give it an initial value of zero.
int myarray[10]; //Declare a ten element integer array named myarray.
//Using a printf/scanf pair in a for loop, input integers into the ten elements of the array.
for(a=0; a<10; a++)
{
printf("Enter the element %d ",(a+1));
scanf("%d",&myarray[a]);
}
//Use a second for loop to compute the sum of the ten values,
// storing the result in an appropriately named variable.
for(a=0; a<10; a++)
{
sum = sum + myarray[a];
}
printf("The Sum is %d ",sum);
printf(" ");
getch();
return 0;
}
Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.