# Program to take input for 10 elements using an array, display all the elements also calculate and print sum of all the elements.

Solution with out using functions
Solution using functions without passing arguments
Solution using functions and by passing arguments

## Program to take input for 10 elements using an array, display all the elements also calculate and print sum of all the elements.

### Problem In Hand

To take input for 10 elements using an array further display all the elements amd also calculate and print sum of all the elements

### Process and Solution Of Problem

* Using a for loop(any loop can be used) we take input for 10 elements
* Further we use for loop to display all the elements and calculate sum of all the elements as the elements are traversed.

### Program/Source Code

```#include <stdio.h>

int main()
{
int a[10],i,s=0;
/* input */
for(i=0;i<10;i++)
{
printf("Enter %d element ",i);
scanf("%d",&a[i]);
}
/* display */
for(i=0;i<10;i++)
{
printf("%d\n",a[i]);
s=s+a[i];
}
printf("Sum = %d",s);
return 0;
}
```

### Program Explanation

• As we have to take input for 10 elements we declare an array of size 10.
• memory locations are created from 0 to 9 i.e. a[0] to a[9].
• Now using a for loop we take input for elements
• further we use for loop again to dislay the elements and as elements are traversed their values are added to a variable s. (s=s+a[i];)
• And after the full traversal the sum of all the elements is calculated in variable “s”.
• Now we display the value of variable “s” .

## Output:

Enter 0 element 1
Enter 1 element 2
Enter 2 element 3
Enter 3 element 4
Enter 4 element 5
Enter 5 element 6
Enter 6 element 7
Enter 7 element 8
Enter 8 element 9
Enter 9 element 10
1
2
3
4
5
6
7
8
9
10
Sum = 55

## Output:

Enter 0 element 2
Enter 1 element 1
Enter 2 element 5
Enter 3 element 6
Enter 4 element 9
Enter 5 element 2
Enter 6 element 10
Enter 7 element 2
Enter 8 element 5
Enter 9 element 45
2
1
5
6
9
2
10
2
5
45
Sum = 87

### Interview Questions

C Programming
C++ Programming
Class 11 (Python)
Class 12 (Python)
C Language
C++ Programming
Python

C Interview Questions
C++ Interview Questions
C Programs
C++ Programs

Important Pages