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

  Write a recursive method named count

Write a recursive method named countBelowThreshold that counts the number of items in the linked list whose data value is smaller than a provided threshold.

  Write a character to the printers output register

Does it make sense to run this printer using interrupt-driven I/O if each character printed requires an interrupt that takes 25 mu sec all-in to service?

  Who is liable in the event of a security breach

Take for example the Windows 10 Operating System which proposed (and used) forced updates.What are the reasons for a user to not want forced updates?

  What were the risks and impact if the implementation failed

What were the implementation requirements? What were the risks and impact if the implementation failed?

  Demonstrate a significant application of technical elements

Your final project in this class is required to be more extensive than the weekly lab projects. Your project should demonstrate a significant application of technical elements and also demonstrate originality and creativity.

  Define the goal of a queuing system

Define the goal of a queuing system. What are the four necessary pieces of information needed to build a queuing system?

  Create a print function for the list that will print node

Create a print function for the list that will print the nodes in order. You will need to create some functions to support this functionality.

  Create a person gui where the application read person file

Create a Person GUI where the application read your Person file when launching the interface.

  Give regular expression for the given statements

All lines that contain the word ‘index' followed by any odd number/digit followed by any even number/digit (ignore 0's).

  Create a temperature demo program

Make sure you take no input in this class and that it does not contain a main method.

  Explain what improvements are currently being made

Analyse two of the three technologies provided (focus virtualisation, cloud computing and green computing).

  Derive all four forms of minimum two-level circuits

Derive all four forms of minimum two-level circuits for P and Q in problem. Problem: For the circuit shown below: For the circuit shown below, express P and Q.

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