Sum of elements of array in C

Q. WAP to take 5 elements as a input from user and display sum of those elements using array in C
==> Code goes like this :
 #include<stdio.h>
int main()
{
    int i,a[5],sum=0;
    printf("Enter 5 elements: ");
    for(i=0;i<5;i++)
    {
    scanf("%d",&a[i]);        // Taking inputs & summing up
    sum+=a[i];
    }
    printf("Sum of elements is: %d",sum);
return 0;       
}


Output:
  










 I have used Dev CPP to compile this program.
If you are using Turbo C++ IDE, then use conio.h in link section after stdio.h
and use getch(); to hold the output screen, just before the end of main function.
If you have any confusion regarding the program, please, comment below.
Happy Coding !
Thank you
 
Share on Google Plus

About Nepali Xoro

Interested in Information Technology, Spreading Knowledge for Nepalease IT Students."Loves Traveling", Listen Music and Surfing web.
    Blogger Comment
    Facebook Comment

0 comments:

Post a Comment