Online Courses
Free Tutorials  Go to Your University  Placement Preparation 
0 like 1 dislike
862 views
in GTU B.E. (CSE-I-Sem) Programming For Problem Solving Lab by Goeduhub's Expert (7.1k points)

Write a program that defines a function to add first n numbers using C programming

Goeduhub's Top Online Courses @Udemy

For Indian Students- INR 360/- || For International Students- $9.99/-

S.No.

Course Name

 Coupon

1.

Tensorflow 2 & Keras:Deep Learning & Artificial Intelligence || Labeled as Highest Rated Course by Udemy

Apply Coupon

2.

Complete Machine Learning & Data Science with Python| ML A-Z Apply Coupon

3.

Complete Python Programming from scratch | Python Projects Apply Coupon
    More Courses

1 Answer

0 like 0 dislike
by Goeduhub's Expert (7.1k points)
edited by
 
Best answer

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 :

Output of above program showing sum of first 10 numbers


For More GTU C Programming Lab Experiments Click Here

3.3k questions

7.1k answers

394 comments

4.6k users

Related questions

 Goeduhub:

About Us | Contact Us || Terms & Conditions | Privacy Policy || Youtube Channel || Telegram Channel © goeduhub.com Social::   |  | 
...