Skip to content

Instantly share code, notes, and snippets.

@sanikamal
Created September 15, 2017 10:58
Show Gist options
  • Save sanikamal/35c31579b124cea44942f7f71fb334dc to your computer and use it in GitHub Desktop.
Save sanikamal/35c31579b124cea44942f7f71fb334dc to your computer and use it in GitHub Desktop.
C program to print the sum of all the elements of an array.
#include <stdio.h>
int main(void) {
int N, i;
scanf("%d", &N);
int numArray[N]; // Define an array of four integers
// Get inputs for the array elements
for (i=0;i<N; i++) {
scanf("%d", &numArray[i]);
}
int sum = 0;
//the logic to add these integers
for(i=0;i<N;i++){
sum +=numArray[i];
}
printf("%d\n",sum); // Print the sum
return 0;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment