Function to Add First n Numbers
In this program we are going to use function to add first n numbers from zero to n using C programming.
To learn basics of function in C programming Click Here.
Example :
#include<stdio.h> #include<conio.h>
//Declaration of addN() funtion int addN(int x); void main() { int x; clrscr(); printf("\nEnter a number:"); scanf("%d",&x);
//calling addN() function printf("\nSum of first %d Numbers = %d",x,addN(x)); getch(); }
//Definition o addN() function int addN(int n) { int i,sum=0; for(i=1;i<=n;i++) sum+=i; return sum; } |
Output :

For More GTU C Programming Lab Experiments Click Here