#include <stdio.h>
int main()
{
int number[5];
char choice;
int sum;
int product;
printf("Input five whole numbers:\n");
printf("--------------------------\n\n");
for(int i =1;i<=5;i++)
{
printf("Enter number %d:\n",i);
scanf("%d",&number[i]);
}
printf("\nThe five numbers are: {");
for(int i =1;i<=5;i++)
{
printf(" %d",number[i]);
if(i!=5)
{
printf(", ");
}
}
printf(" }");
printf("\n\nWould you like to sum or multiply the elements (s/m)?\n");
scanf(" %c",&choice);
switch(choice)
{
case 's':
printf("The sum of ");
for(int i =1;i<=5;i++)
{
printf("%d ",number[i]);
if(i!=5)
{
printf("+ ");
}
sum += number[i];
}
printf("is %d",sum);
break;
case 'm':
printf("The multiplication of ");
for(int i =1;i<=5;i++)
{
printf("%d ",number[i]);
if(i!=5)
{
printf("* ");
}
product *= number[i];
}
printf("is %d",product);
break;
}
return 0;
}
Preview:
downloadDownload PNG
downloadDownload JPEG
downloadDownload SVG
Tip: You can change the style, width & colours of the snippet with the inspect tool before clicking Download!
Click to optimize width for Twitter