-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathscope.c
More file actions
51 lines (36 loc) · 824 Bytes
/
Copy pathscope.c
File metadata and controls
51 lines (36 loc) · 824 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
# include<stdio.h>
// C Variable Scope
// There are the local variable scope and the global variable scope
//the global are declared outside while the local are found within the body of code
// RECURSION
/*
void recurse(){
.........
recurse();
......
int main(){
.... //// to prevent the infinite recursion of the function we use an if else loop
recurse();
.....
return 0;
}
}
*/
/// program is going to add a number with all positive integers before it.
/// say number is 5, sum= 5+4+3+2+1+0 =15
// check github repository
int sum(int n);
int main(){
int number,result;
printf("Enter a positive number.");
scanf("%d",&number);
result= sum(number);
printf("sum = %d",result);
return 0;
}
int sum(int n){
if (n !=0){
// sum() function calls itself
return n+sum(n-1);
}
}