Write a program to enter a number and its sum of digits ??

2
in whch lang...??
I mean in c,c++ or something else...
please rephrase your question
you need a program to enter a number and to find the sum of its digit right.? so in which language this program is to be written..??
you want it in Java, C or C++?

Answers

2014-06-17T12:37:54+05:30
In c++:-
int main()
{
int a,b,c;
cout<<"enter value of 'a' ";
cin>>a;
cout<<"enter value of 'b' ";
cin>>b;

c=a+b;

cout<<"the sum of no. a and b is = "<<c;

getchar(); //to stop the display

}
0
hey this is the sum of two numbers and not the sum of digits of a number
2014-06-19T23:32:54+05:30
Class digitsum
{
public static void main(String args[])
{
System.out.println("Enter a number of your choice");
int p=Integer.parseInt(args[0]);
int a=0,sum=0;
while(i!=0)
{
a=i%10;
i=i/10;
sum=sum+a;
}
System.out.println(sum);
}
}
Hope i helped u.....:)
0