I\'ve asked this question 3 times and no one\'s been able to answer it correctly
ID: 3866287 • Letter: I
Question
I've asked this question 3 times and no one's been able to answer it correctly. Your output has to match the example outputs given below. Make sure your output doesn't just work in cmd but all compilers. There are 2 examples below. Spacing, wording, and everything has to be the same. Thanks for your help!
CMPSC 101 LAB 13 - Fun with arrays Write a program that reads 15 numbers (integers) from stdin, then displays the following: The total of the even numbered values (2nd value+ 4th value+ etc..) The total of the odd numbers (1st value + 3rd value + etc...) The total of every 5th number. Note that “even numbered values" mean the 2nd value, 4th value, etc., not “2”, “4". "6", etc. For example: The data is: 0,1,2,3,4,5, 6,7,8,9,10,11,12,13,14 The even values are: 1+3+5+7+9+11+13- 49 The odd values are: 0+2+4+6+8+10+12+14 = 56 Every fifth values are: 4+9+14 = 27 Another example: The data is: 7,3, 9,11,25,47,98,45,76, 21,99,35,67,83,12 The even values are: 3+11+47+45+21+35+83 = 245 The odd values are: 7+9+25+98+76+99+67+12 = 393 Every fifth values are: 25+21+12 -58 Run it 5 times with different data, including the two above examples. Then, following the instructions in the "How to package and submit your labs" video, package up your work. Double check to confirm that the package is complete (i.e., all the header info, the code, the screen shots, the output, etc.), and then submit it to the drop box Next, go back and confirm that the submission is in the drop box!Explanation / Answer
#include <stdio.h>
int main(void) {
// your code goes here
int a[15];
int i,sum=0,sum1=0,sum2=0;
printf("The data is: ");
for(i=1;i<=15;i++)
{
scanf("%d",&a[i]);
}
printf(" ");
printf("The even values are: ");
for(i=2;i<=15;i=i+2)
{
if(i==14)
{
printf("%d ",a[i]);
sum=sum+a[i];
}
else
{
printf("%d+",a[i]);
sum = sum +a[i];
}
}
printf("= %d",sum);
printf(" ");
printf("The odd values are: ");
for(i=1;i<=15;i=i+2)
{
if(i==15)
{
printf("%d ",a[i]);
sum1=sum1+a[i];
}
else
{
printf("%d+",a[i]);
sum1=sum1+a[i];
}
}
printf("= %d",sum1);
printf(" ");
printf("The Fifth value are: ");
for(i=5;i<=15;i=i+5)
{
if(i==15||i==14)
{
printf("%d ",a[i]);
sum2=sum2+a[i];
}
else
{
printf("%d+",a[i]);
sum2=sum2+a[i];
}
}
printf("= %d",sum2);
return 0;
}
output:
The data is: 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15
The even values are:
2+4+6+8+10+12+14 = 56
The odd values are:
1+3+5+7+9+11+13+15 = 64
The Fifth value are:
5+10+15 = 30
Output 1:
The data is: 0 1 2 3 4 5 6 7 8 9 10 11 12 13 14
The even values are:
1+3+5+7+9+11+13 = 49
The odd values are:
0+2+4+6+8+10+12+14 = 56
The Fifth value are:
4+9+14 = 27
output 2:
The data is: 7 3 9 11 25 47 98 45 76 21 99 35 67 83 12
The even values are:
3+11+47+45+21+35+83 = 245
The odd values are:
7+9+25+98+76+99+67+12 = 393
The Fifth value are:
25+21+12 = 58