C++ program to find the sum of digits of a number
Here we write code for find sum of digits of a number program in C.#include<stdio.h>
#include<conio.h>
void main()
{
int a,no,sum=0;
clrscr();
printf("enter any num = ");
scanf("%d",&no);
while(no>0)
{
a=no%10;
no=no/10;
sum=sum+a;
}
printf("\nSUM OF DIGITS = %d",sum);
getch();
}
Output
No comments:
Post a Comment