Write a Program for calculating Sum of n numbers using recursion

#include<stdio.h> #include<conio.h> int sum ( int n); void main ( ) { int n , s; printf (“enter a number”); sc...

#include<stdio.h>
#include<conio.h>
int sum ( int n);
void main ( )
{
int n , s;
printf (“enter a number”);
scanf ("%d", & n);
s = sum ( n);
printf (“\n sum of numbers is %d", s);
getch();
}

int sum ( int n)
{
if ( n = =0)
return ( 0);
else
return ( n + sum ( n -1));
}

Out Put:

enter a number 10
sum of numbers is 55

Related

Program for SWAPING OF 2 NUMBERS USING CALL BY VALUE ,CALL BY REFERENCE

#include<stdio.h> #include<conio.h> swap(int x,int y); swap(int *x,int *y); main() {           int a,b,ch;     ...

PROGRAM FOR FINDING BIGGEST OF THREE NUMBERS

#include<stdio.h> #include<conio.h> void main() {  int a,b,c;  clrscr();  printf("\n enter a,b,c values");  scanf("%d%d%d",&a,&b,&c);  if(a&g...

PROGRAM FOR CONVERTING TEMPERATURE

#include<stdio.h> #include<conio.h> void main() {   int c;   float f;   clrscr();   printf("enter c value");   scanf("%d",&c);   f=1.8*c+32.0; ...

Post a Comment

emo-but-icon
:noprob:
:smile:
:shy:
:trope:
:sneered:
:happy:
:escort:
:rapt:
:love:
:heart:
:angry:
:hate:
:sad:
:sigh:
:disappointed:
:cry:
:fear:
:surprise:
:unbelieve:
:shit:
:like:
:dislike:
:clap:
:cuff:
:fist:
:ok:
:file:
:link:
:place:
:contact:

item