If a five-digit number is input through the keyboard, write a program to calculate the sum of its digits.
Answers
Answered by
1
#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;
}
Answered by
10
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() ;
}
manassingh17102003:
THANKS BHAI BUT IT NOT RUNNING ON MY PC DEV C++ IS THE COMPILER
Similar questions