Computer Science, asked by manassingh17102003, 1 year ago

If a five-digit number is input through the keyboard, write a program to calculate the sum of its digits.

Answers

Answered by nitish8089
1

c +  + .....
#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 abhirck04
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
nitish8089: actually syntax in c
nitish8089: try below answer it will run c++ syntax
nitish8089: any other problem would you face... :D
Similar questions