#include <stdio.h>
#include <conio.h>
int main()
{
int num, sum = 0, i, array[10];
printf("\n How many numbers you want to add?\n");
scanf("%d", &num);
printf("\n Enter %d integers:", num);
for (i = 1; i <= num; i++)
{
scanf("%d", &array[i]);
sum = sum + array[i];
}
printf("\n Sum of all elements of an array = %d\n", sum);
return 0;
getch();
}
Run:
Previous Next
#include <conio.h>
int main()
{
int num, sum = 0, i, array[10];
printf("\n How many numbers you want to add?\n");
scanf("%d", &num);
printf("\n Enter %d integers:", num);
for (i = 1; i <= num; i++)
{
scanf("%d", &array[i]);
sum = sum + array[i];
}
printf("\n Sum of all elements of an array = %d\n", sum);
return 0;
getch();
}
Run:
Previous Next
No comments:
Post a Comment