For Example:-
super digit of 9875 will be calculated as:
#include<stdio.h>
#include<conio.h>
int recSum(int n);
void main()
{
int n,ans;
printf("\n Enter number: ");
scanf("\n%d",&n);
ans=recSum(n);
printf("\n Sum:=%d",ans);
getch();
}
int recSum(int n1)
{
int rem,sum=0;
if(n1==0)
return 0;
else
{
rem=n1%10;
sum=rem+recSum(n1/10);
}
if(sum>9)
{
n1=sum;
sum=recSum(n1);
}
return sum;
}
super digit of 9875 will be calculated as:
super-digit(9875) = super-digit(9+8+7+5)
= super-digit(29)
= super-digit(2+9)
= super-digit(11)
= super-digit(1+1)
= super-digit(2)
= 2.
-----------------------------------------------------------------------------------------------------------------------#include<stdio.h>
#include<conio.h>
int recSum(int n);
void main()
{
int n,ans;
printf("\n Enter number: ");
scanf("\n%d",&n);
ans=recSum(n);
printf("\n Sum:=%d",ans);
getch();
}
int recSum(int n1)
{
int rem,sum=0;
if(n1==0)
return 0;
else
{
rem=n1%10;
sum=rem+recSum(n1/10);
}
if(sum>9)
{
n1=sum;
sum=recSum(n1);
}
return sum;
}
Great
ReplyDeleteThank you for sharing Amazing Blog. It's providing very useful guideline for Engineering students.
ReplyDeleteget more: Programming Language in C
Thank you so much..!
Delete