Creative Commons License Foxbond's Repo

/** (c) 2015 Michał (Foxbond) Chraniuk */
#include <stdio.h>


int suma (int n){
		if (n<=0){
			 return 0;
	  }
		return suma(n/10)+(n % 10);
}

int main (){
		int n;
		do {
			 printf("Podaj n (wieksze od 0): ");
		   scanf("%d", &n);
	  }while(n<0);
		printf("\nSuma cyfr liczby %d = %d\n", n, suma(n));
		getch();
		return 0;
}

> Back