C-Programming
How to easily write a program in c to calculate sum of the all digit of a number ??
How to easily write a program in c to calculate sum of the all digit of a number ??
in C-Programming
/* sum of the all digit of a no.*/
#include<stdio.h>
#include<conio.h>
main()
{
int p,r,sum=0;
clrscr();
printf("\n enter a no:");
scanf("%d",&p);
while (p != 0)
{
r=p%10;
sum=r+sum;
p=p/10;
}
printf("\n sum of the digit= %d",sum);
getch();
}
in C-Programming
How to easily write a program in c to calculate sum of the all digit of a number ??
Code:-/* sum of the all digit of a no.*/
#include<stdio.h>
#include<conio.h>
main()
{
int p,r,sum=0;
clrscr();
printf("\n enter a no:");
scanf("%d",&p);
while (p != 0)
{
r=p%10;
sum=r+sum;
p=p/10;
}
printf("\n sum of the digit= %d",sum);
getch();
}
No comments:
Post a Comment