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

  Mathematics in computing

Binary search tree, and postorder and preorder traversal Determine the shortest path in Graph

  Ict governance

ICT is defined as the term of Information and communication technologies, it is diverse set of technical tools and resources used by the government agencies to communicate and produce, circulate, store, and manage all information.

  Implementation of memory management

Assignment covers the following eight topics and explore the implementation of memory management, processes and threads.

  Realize business and organizational data storage

Realize business and organizational data storage and fast access times are much more important than they have ever been. Compare and contrast magnetic tapes, magnetic disks, optical discs

  What is the protocol overhead

What are the advantages of using a compiled language over an interpreted one? Under what circumstances would you select to use an interpreted language?

  Implementation of memory management

Paper describes about memory management. How memory is used in executing programs and its critical support for applications.

  Define open and closed loop control systems

Define open and closed loop cotrol systems.Explain difference between time varying and time invariant control system wth suitable example.

  Prepare a proposal to deploy windows server

Prepare a proposal to deploy Windows Server onto an existing network based on the provided scenario.

  Security policy document project

Analyze security requirements and develop a security policy

  Write a procedure that produces independent stack objects

Write a procedure (make-stack) that produces independent stack objects, using a message-passing style, e.g.

  Define a suitable functional unit

Define a suitable functional unit for a comparative study between two different types of paint.

  Calculate yield to maturity and bond prices

Calculate yield to maturity (YTM) and bond prices

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