Sum of N Numbers Program In C: Using Functions

This Sum of N numbers program in C Programming allows the user to enter N integer by using the 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 of Natural N= %d", Sum);
  return 0;
}

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

 

Leave a Reply

Shopping cart