•
•
•
•
What is DaniWeb IT Discussion Community?
You're currently browsing the C++ section within the Software Development category of DaniWeb, a massive community of 397,770 software developers, web developers, Internet marketers, and tech gurus who are all enthusiastic about making contacts, networking, and learning from each other. In fact, there are 2,531 IT professionals currently interacting right now! Registration is free, only takes a minute and lets you enjoy all of the interactive features of the site.
Please support our C++ advertiser:
Views: 1358 | Replies: 2
![]() |
•
•
Join Date: Nov 2004
Posts: 11
Reputation:
Rep Power: 0
Solved Threads: 0
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<iostream.h>
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"<<endl;
cin>>n;
sum=sumofdigits(n);
cout<<"Sum of digits ="<<sum;
cout<<endl;
}
The program which I wrote is below::
#include<iostream.h>
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"<<endl;
cin>>n;
sum=sumofdigits(n);
cout<<"Sum of digits ="<<sum;
cout<<endl;
}
>>>Extreme<<<
Re: Can any1 tell me whatz wrong in this program...this does not show the output!!!
#2
Nov 29th, 2004
You forgot to update the loop counter.
while(n>0)
{
x=n%10;
sum+=x;
n/=10;
}•
•
Join Date: Nov 2004
Posts: 11
Reputation:
Rep Power: 0
Solved Threads: 0
Re: Can any1 tell me whatz wrong in this program...this does not show the output!!!
#3
Nov 29th, 2004
![]() |
•
•
•
•
Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
•
•
•
•
•
•
•
•
DaniWeb C++ Marketplace
Similar Threads
- Is it wrong to have a very long program if i did not find another way? (C++)
- Can anyone figure out what is wrong in my program? (C++)
- wrong output in c program (C++)
- Running a program (C++)
Other Threads in the C++ Forum



Linear Mode