Sum Of Digit Using Recursion and Non Recursion function In C Program Tamil


#include<stdio.h>
#include<conio.h>
int sum(int);   //without recursion
int rsum(int);  //with recursion
void main()
{
	int s,rs;
	int n;
	clrscr();
	printf("\n Enter the Number :");
	scanf("%d",&n);		//www.tutorjoes.com
	s=sum(n);	//without rercusion
	printf("\n Sum of Digits with out Recursion :%d",s);
	rs=rsum(n);     //with recursion
	printf("\n Sum of digits using Recursion :%d",rs);
	getch();
}
int sum(int num)
{
	int remainder,sum=0;
	while(num>0)
	{
		remainder=num%10;	//calculating remainder
		sum=sum+remainder;
		num=num/10; 	 //last digit removed
	}
	return(sum);
}
int rsum(int num)
{
	int sum=0;
	int remainder;                   // www.tutorjoes.com
	if(num!=0)
	{
		remainder=num%10;	//calculation remainder
		sum=remainder+rsum(num/10);	//function calling
	}
	return sum;
}

Login To Download Source Code

Leave a Comment:

Login To Comment

List Of Programs


Goto Examples

Operators

Looping

Number Conversion

Pattern Design

Arrays

Matrix Examples

Sorting Examples

String Function

Change Case

String In C

Maths Functions

User Defined Functions

Recursive Functions

Pointer

Structure

File Concept

Calender Programming