Get the FREE certificate on C, C++, Java, Python, Perl, PHP, SQL, Linux & Javascript!  

CppBuzz.com
  
Home C C++ Java Python Perl PHP Spring SQL Javascript Linux

You are here : Home » Solved Programs on C++ » C++ program to find sum of n numbers using function

C++ program to find sum of n numbers using function

#include <stdio.h>
#include <conio.h>

int sum (int number);

int main()
{
  int no;

  printf("\n How many numbers? : ");
  scanf("%d", &no);

  printf("\n Sum of the %d numbers is : %d ",no,sum(no));
  
  return 0;
  
}
int sum(int number){

  int i, addition=0;

  for(i=1; i<=number; i++){
    addition += i;
  }
  return addition;
}