C Online Compiler
Example: Sum of Two Numbers in C using Array
C
C++
C#
Java
Python
PHP
main.c
STDIN
Run
// Sum of Two Numbers in C using Array #include <stdio.h> int main() { int sum = 0, s = 0; printf("Enter the number of inputs: "); scanf("%d", &s); // To store the numbers int numbers[s]; // To store the input values into the Array printf("\nEnter the %d integer values:\n", s); for (int i = 0; i < s; i++) { scanf("%d", &numbers[i]); sum += numbers[i]; } // Final output printf("\nResult:: "); for (int i = 0; i < s; i++) { printf("%d", numbers[i]); if (i < s - 1) printf(" + "); } printf(" = %d\n", sum); return 0; }
5 23 34 2 54 98
Output
Clear
ADVERTISEMENTS