C programming examples with output
Condensing A Number into Single Digit
Program
#include<stdio.h>
#include<conio.h>
main()
{
int r,i,j,s;
int a[10];
long n;
clrscr();
printf("Enter any number : ");
scanf("%ld",&n);
do
{
s=0;i=0;
while(n>0)
{
r=n%10;
a[i]=r;
s=s+r;
i++;
n=n/10;
}
--i;
if(i!=0)
n=s;
if(i==0 || i==1)
{
printf("single digit= %d",n);
break;
}
}while(i>0);
getch();
}
Output:
Enter any number:9876543221
((9+8+7+6+5+4+3+2+1)=(45)=(4+5)=9)
single digit=9
Enter any number:32190
single digit=6
Enter any number:1092387456
single digit=9
Best Budget Laptop For Web Developers 2019
Condensing A Number into Single Digit
Program
#include<stdio.h>
#include<conio.h>
main()
{
int r,i,j,s;
int a[10];
long n;
clrscr();
printf("Enter any number : ");
scanf("%ld",&n);
do
{
s=0;i=0;
while(n>0)
{
r=n%10;
a[i]=r;
s=s+r;
i++;
n=n/10;
}
--i;
if(i!=0)
n=s;
if(i==0 || i==1)
{
printf("single digit= %d",n);
break;
}
}while(i>0);
getch();
}
Output:
Enter any number:9876543221
((9+8+7+6+5+4+3+2+1)=(45)=(4+5)=9)
single digit=9
Enter any number:32190
single digit=6
Enter any number:1092387456
single digit=9
Best Budget Laptop For Web Developers 2019
0 komentar:
Post a Comment