Created
September 15, 2017 10:58
-
-
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.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#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