Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- /*
- task_01.c
- https://www.facebook.com/photo/?fbid=254402079891542&set=pcb.385071233009994
- */
- #include <stdio.h>
- void func(int n){
- int i;
- static int last_result=0;
- for(i=0;i<=n;i++){
- last_result = last_result + i;
- printf("\n %2d \t %2d \n", i, last_result);
- }
- }
- void recursive_func(int i, int n){
- static int last_result=0;
- if(i>n)
- return;
- last_result = last_result + i;
- printf("\n %2d \t %2d \n", i, last_result);
- if(i<=n){
- i++;
- recursive_func(i,n);
- }
- }
- int main(){
- int i, n=5, last_result=0;
- printf("\n Without function: \n");
- for(i=0;i<=n;i++){
- last_result = last_result + i;
- printf("\n %2d \t %2d \n", i, last_result);
- }
- printf("\n With function: \n");
- func(5);
- printf("\n With recursive function: \n");
- recursive_func(0,5);
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement