• Follow Us

Sum of N Numbers Program In C: Using Functions

Let’s have a look at the Sum of N Numbers Program In C Using Functions allows the user to enter N integer by using the function.

In C Programming Language, a function is combined with a block of code that can be called or used anywhere in the program by calling the name.

Body of a function starts with{ and ends with } . This is similar to the main function.

C Program To Find Sum of N Numbers Using Functions

#include<stdio.h>
/* Learn C Programming at www.Codetaglance.com */
int Sum_Functions(int N);

int main()
{
  int N, i, Sum = 0;
  
  printf("\nPlease Enter any Integer of your choice\n");
  scanf("%d", &N);
  
  Sum = Sum_Functions(N);
  
  printf("Sum= %d", Sum);
  return 0;
}

int Sum_Functions(int N)
{
	int i, Sum = 0;
	
	if (N == 0)
	{
		return N;
	}
	else
	{
		return (N* (N + 1) / 2);
	}
	
}

Output:

Please Enter any Integer of your choice

501

Sum= 6

 

Leave a Reply

Your email address will not be published. Required fields are marked *

Shopping cart