EXERCİSE 3/ lab sheet 7 (arrays)
Mon Dec 12 2022 17:27:56 GMT+0000 (Coordinated Universal Time)
Saved by
@Mohamedshariif
#include <stdio.h>
#include <stdlib.h>
/*Exercise 3
Write a C code that will ask the user to enter 10 numbers, store them in an array. Then calculate the sum of elements in the array and print the result on the screen.*/
//calculate sum of all element in the array
int main() {
int arr[10];
int i,j;
for(int i=0;i<=9;i++)
{
printf("please enter an elemet %d: ", i+1);
scanf("%d",&arr[i]);
}
int sum=0;
for(int i=0;i<=9;i++)
{
sum=sum+arr[i];
}
printf("the sum of all element in the array are: %d\n",sum);
return 0;
}
content_copyCOPY
Comments