I am trying to make a recursive program that prints out
the numbers from 1-100 without using any iterations such
as loops, but every-time it just keeps printing out 5050..?
#include<stdio.h>
#include<stdlib.h>
int counter(int num);
int sum=0;
int main(){
int result, num=100;
result = counter(num);
printf("%d", result);
system("PAUSE");
return 0;
}
int counter(int num){
if (num==0)
return sum;
else{
sum = sum+num; //<--- If I change the num to 1 it just prints 100 not all the numbers from 1-100
counter(--num);}
return (sum);
}
Thanks for yourr help!