#include<stdio.h> #include<conio.h> void main() { int num, a, n; int sum=0; clrscr(); printf(" enter a five digit no."); scanf("%d", &num); a=num%d; n=num/10; sum=sum+a;
a=n%10; n=n/10; sum=sum+a;
a=n%10; n=n/10; sum=sum+a;
a=n%10; n=n/10; sum=sum+a;
a=n%10; sum=sum+a;
printf("\n the sum of five digit of %d is %d", num,sum) ; getch() ; }
4 votes Thanks 5
manassingh17102003
THANKS BHAI BUT IT NOT RUNNING ON MY PC DEV C++ IS THE COMPILER
Answers & Comments
#include<iostream>
using namespace std;
int main(){
int a; // creating variable to store number:
cin>>a; // taking input:
int sum=0; // creating for store sum of digit.
int temp=a;
do{
int x=temp%10;
sum+=x;
temp/=10;
}while(temp>0);
cout<<"sum of digit of "<<a<<" is "<<sum<<endl;
return 0;
}
c lang
#include<stdio.h>
#include<conio.h>
void main()
{
int num, a, n;
int sum=0;
clrscr();
printf(" enter a five digit no.");
scanf("%d", &num);
a=num%d;
n=num/10;
sum=sum+a;
a=n%10;
n=n/10;
sum=sum+a;
a=n%10;
n=n/10;
sum=sum+a;
a=n%10;
n=n/10;
sum=sum+a;
a=n%10;
sum=sum+a;
printf("\n the sum of five digit of %d is %d", num,sum) ;
getch() ;
}