954,500 Members — Technology Publication meets Social Media
Username:
Password:
Lost login information?
Have something to say? Contribute New Article Reply to this Article

Can any1 tell me whatz wrong in this program...this does not show the output!!!

Hey can any1 figure out wat is wrong in this program...after i compiled it and executed the program ....I inputed the value of n...but after that it does not show the output...Can any1 help me plz..!!

The program which I wrote is below::


#include

int sumofdigits(int n)

{

int sum=0, x;

while(n>0)

{
x=n%10;

sum+=x;

}

return sum;

}

void main()

{

int n, sum;

cout<<"Enter any number"<>n;

sum=sumofdigits(n);

cout<<"Sum of digits ="<

Extreme
Newbie Poster
12 posts since Nov 2004
Reputation Points: 10
Solved Threads: 0
 

You forgot to update the loop counter.

while(n>0)
{
   x=n%10;
   sum+=x;
   n/=10;
}
Dave Sinkula
long time no c
Team Colleague
5,058 posts since Apr 2004
Reputation Points: 2,780
Solved Threads: 314
 

hey Dave Sinkula thanx a lot...

Extreme
Newbie Poster
12 posts since Nov 2004
Reputation Points: 10
Solved Threads: 0
 

This article has been dead for over three months

Post: Markdown Syntax: Formatting Help
You