Sunday 15 December 2013

C Program to find Sum of N Numbers using Recursion

#include < stdio.h>

void display(int);

int main()
{
int num, result;

printf("Enter the Nth number: ");
scanf("%d", &num);
display(num);
return 0;
}

void display(int num)
{
static int i = 1;

if (num == i)
{
printf("%d \n", num);
return;
}
else
{
printf("%d ", i);
i++;
display(num);
}
}

Output

 Enter the Nth number:  10 
1 2 3 4 5 6 7 8 9 10

For More Details Please Visit Ictjobs.info

No comments: