Answer to Question #303794 in C for lhanz

Question #303794

Write a program that will input 20 values to array BSIT and to sum up the content of all even index. Print array BSIT and the sum of all even index.

1
Expert's answer
2022-02-28T08:30:15-0500
#include <stdio.h>

int main()
{
    int number, sum;
    int BSIT[20];

    sum = 0;
    printf("Enter array: \n");
    for (int i=0; i<20; i++)
        scanf("%d", &BSIT[i]);
    printf("\nArray:\n");
    for (int i=0; i<20; i++)
        printf("%d ", BSIT[i]);
    for (int i=1; i<20; i=i+2)        // if index start from 0 - for (int i=0; i<20; i=i+2)
        sum += BSIT[i];
    printf("\nSum of all even index: %d", sum);
}   

Need a fast expert's response?

Submit order

and get a quick answer at the best price

for any assignment or question with DETAILED EXPLANATIONS!

Comments

No comments. Be the first!

Leave a comment

LATEST TUTORIALS
New on Blog
APPROVED BY CLIENTS