-->
Showing posts with label program to get sum of numbers among 'n' numbers. Show all posts
Showing posts with label program to get sum of numbers among 'n' numbers. Show all posts

program to get sum of numbers among 'n' numbers


using turbo C++
-----------------------------------------------------------------------

// program to get sum of  numbers among 'n' numbers
#include <stdio.h>
#include<conio.h>
void main()
{
    int a[100],n,i,sum=0,number_to_be_summed;
    printf("enter total number\n");
    scanf("%d",&n);
    for(i=0;i<n;i++)
    {
        printf("enter number for location=%d",i);
        scanf("%d",&a[i]);
    }
    printf("enter total number to be summed");
    scanf("%d",&number_to_be_summed);
    for(i=0;i<number_to_be_summed;i++)
    {
       
       sum=sum+a[i];
    }
    printf("sum=%d",sum);
    getch();
}


-------------------------------------------------------------------------------------------------------------------
using online compiler/devC++/codeblocks with return concept
---------------------------------------------------------------------------------------------------------------------
// program to get sum of  numbers among 'n' numbers

#include <stdio.h>

int main()
{
    int a[100],n,i,sum=0,number_to_be_summed;
    printf("enter total number\n");
    scanf("%d",&n);
    for(i=0;i<n;i++)
    {
        printf("enter number for location=%d",i);
        scanf("%d",&a[i]);
    }
    printf("enter total number to be summed");
    scanf("%d",&number_to_be_summed);
    for(i=0;i<number_to_be_summed;i++)
    {
       
       sum=sum+a[i];
    }
    printf("sum=%d",sum);
    return 0;
}