Find the sum of first n natural numbers using recursion

Assignment Help Computer Engineering
Reference no: EM132196175

Write a C program to find the sum of first n natural numbers using recursion. The user inputs the value of n.

This is what I have but my program keeps crashing. Please comment new code:

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

int add(n);

int main()
{

int n;

printf("Enter an positive integer");
scanf("%d",n);

printf("Sum=%d",add(n));

return 0;
}

int add(int n)
{

if(n!=0)

return n + add(n-1); /* recursive call */

}

Reference no: EM132196175

Questions Cloud

Construct three to four paragraphs using given information : You will construct three to four paragraphs comprised of five to seven sentences each. Each paragraph should be between 150-200 words.
Emulate a simple clock that shows current time on the host : Write a C program to emulate a simple clock that shows current time on the host' s display through the TeraTerm Emulator.
How author can be used as a christian witness : Prayerfully reflect upon the literature and share how author D. H. Lawrence can be used as a Christian witness or salvific tool to fulfill the Great Commission.
Examine the behaviour of the mpk : The marginal product of capital is given by a Y/K. Setting TFP and L 1, examine the behaviour of the MPK as it varies between 0.3 and 1.
Find the sum of first n natural numbers using recursion : Write a C program to find the sum of first n natural numbers using recursion. The user inputs the value of n.
Which offers a choice in how she may receive her prize : If the interest rate is 10% per annum, compounded annually, which of the following prizes has the highest present value?
Write about the protagonist and the war : Think about the book "A Long Way Gone", write about the protagonist and the war. The Movie "How to Make an American Quilt" delves into several characters'.
What is the value of stock today : After that, the firm expects to maintain a constant dividend growth rate of 2% per year. What is the value of this stock today if the required return is 14%?
How much do you need to invest today : If you deposit money now, you can earn 7% per annum with a 50% probability, 6% with a 25% probability and 8% with a 25% probability.

Reviews

Write a Review

 

Computer Engineering Questions & Answers

  How the estimated budget is as close to reality as possible

How important is it to be accurate with respect to the estimated budget and actual budget of a project.

  Find out what tasks are assigned to each phase

A project includes Analysis, Definition, Design, Implementation, Maintenance, and Support phases. How do we determine what tasks are assigned to each phase.

  Which of the methods would best handle recursion

In some architectures, this address is stored in a register, and in many it is stored on a stack. Which of these methods would best handle recursion? Explain your answer.

  Create a program to find the number of intersecting pairs

Create a program to find the number of intersecting pairs among a set of N random lines, each line generated with random integer coordinates between 0 and 1000.

  Store this information in a string known as date

Write down a C program that accepts a month and day (for example, June 14) from the keyboard as input. Store this information in a string called date.

  Discuss what are the limitations of this metric

What is the ROSI calculation? How is it used to evaluate cybersecurity technologies? What are the limitations of this metric

  Demonstrate your achievement of these goals

SIT 384 Data Analytics for Cyber Security - explain each step of the procedure of classification, and the performance results for your classifiers.

  Which loop arrangement be best for accessing an array

Which loop arrangement be best for accessing an array.

  Explain the difference between a weak and strong entity set

Explain the difference between a weak and a strong entity set. Define the concept of aggregation. Give two examples of where this concept is useful.

  Calculate average time for each sorting method to sort array

Calculates the average time for each sorting method to sort the 1,000 arrays. Prints the average time for each sorting method to the console.

  Write a function that converts an input of some integer

Write a function that converts an input of some integer number of inches into outputs of integer numbers of yards, feet, and inches. Do not write a main function. Your function does not do cin or cout.

  What about spam outside the united states

What recourse do users have if they are wronged in activities such as gambling and if the servers are physically located outside the United States?

Free Assignment Quote

Assured A++ Grade

Get guaranteed satisfaction & time on delivery in every assignment order you paid with us! We ensure premium quality solution document along with free turntin report!

All rights reserved! Copyrights ©2019-2020 ExpertsMind IT Educational Pvt Ltd