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

  Representing text and numbers problem 11 latin alphabetic

representing text and numbers problem 1.1 latin alphabetic characters can be represented using their ascii equivalents.

  Evaluate knowledge necessary to complete technology training

Evaluate the knowledge and skills necessary to complete technology training for a simple task. Write objectives following the guidelines provided.

  How do you run gdb with a program that uses arguments

How do you run gdb with a program that uses arguments? Look up the help feature of gdb to explain the significance of the backtrace and frame commands.

  Make program that displays a digital clock in a window

Write down a program that displays a digital clock in a window using an applet. The clock should show, day of week, date, time, time zone and year.

  Describe a rigorous formulation of the problem

Describe the problem in your own area of expertise highlighting where it is possible to apply one of the computational models - Describe the motivations

  Calculate the minimum required initial velocity

Calculate the minimum required initial velocity for a home run, for baseballs hit at the angles 10°, 20°, 30°, and 40° from the horizontal.

  How should a variable be represented in hardware

When converting to hardware all instructions within a block of code must be completed in parallel. Thank about how to translate the structures into hardware. How should a variable be represented in hardware? An if statement? A Loop

  Describe a set of functions that make use of the twos

Describe a set of functions that make use of the two's complement representation of integers.

  What sources could you use as a source to perform the mbsa

What is the minimum password length enforced by the Password must meet complexity requirements policy? What sources could you use as a source to perform the MBSA security scan?

  What is the efficiency of the link

A block of 200 7-bit ASCII characters (with 1-bit even parity) is to be transmitted over an RS 232 serial link. Calculate the number of bits transmitted and the efficiency of the link if the asynchronous link uses 2 stop bits. What is the efficien..

  Explain by what almost-true claim the number 101 is prime

Calculation shows that 250 = 100 mod 101. Explain by what almost-true claim the number 101 is prime (you need not try possible factorizations of 101).

  Which type of compression would be the most effective

If data has many one type of symbol, which type of compression would be the most effective?

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