The sum will be displayed 55.
10+9+8+7+6+5+4+3+2+1=55
The main source code of the program is given below:
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include<stdio.h> | |
#include<conio.h> | |
int sum(int); | |
int main() | |
{ | |
int num,total; | |
printf("enter the number upto which sum is to be find"); | |
scanf("%d",&num); | |
total=sum(num); | |
printf("total sum upto the entered number =%d",total); | |
getch(); | |
} | |
int sum(int n) | |
{ | |
if (n==0) | |
return n; | |
else | |
return (n+sum(n-1)); | |
} |
0 comments :
Post a Comment