I want solution of a simple program using while loop. I'm a beginner in C++ language. My problem is as follows.
Write a program to receive 'n' numbers and display all the numbers that are divisible by 3.
While loop (C++)a simple program on while loop
Page 1 of 1
4 Replies - 3976 Views - Last Post: 03 June 2008 - 01:30 PM
Replies To: While loop (C++)
#2
Re: While loop (C++)
Posted 02 June 2008 - 10:58 PM
Come on show some code.
Dream.In.Code has a policy by which we prefer to see a good faith effort on your part before providing source code for homework assignments. Please post the code you have written in an effort to resolve the problem, and our members would be happy to provide some guidance. Be sure to include a description of any errors you are encountering as well.
Please post like this:
Thank you for helping us helping you.
Dream.In.Code has a policy by which we prefer to see a good faith effort on your part before providing source code for homework assignments. Please post the code you have written in an effort to resolve the problem, and our members would be happy to provide some guidance. Be sure to include a description of any errors you are encountering as well.
Please post like this:
Thank you for helping us helping you.
#3
Re: While loop (C++)
Posted 02 June 2008 - 11:42 PM
true..
do show us what u have done so far..
do show us what u have done so far..
#4
Re: While loop (C++)
Posted 03 June 2008 - 03:42 AM
aparnasp, on 2 Jun, 2008 - 09:44 PM, said:
I want solution of a simple program using while loop. I'm a beginner in C++ language. My problem is as follows.
Write a program to receive 'n' numbers and display all the numbers that are divisible by 3.
Write a program to receive 'n' numbers and display all the numbers that are divisible by 3.
Hi
May be this code can help you. One thing i have not handled exception because that might make program look more diffcult as you said you are a beginner.
#include<iostream>
#include<vector>
using namespace std;
int main()
{
int n;
char ch;
vector<int>v1;
vector<int>::iterator itr;
do{
cout<<"Enter the number :";
cin>>n;
v1.push_back(n);
cout<<"Enter more 'y' for yes and 'n' for no :";
cin>>ch;
}while(ch=='y');
for(itr=v1.begin();itr!=v1.end();itr++)
{
if((*itr)%3==0)
cout<<"The number divible by 3 is : "<<*itr<<endl;
}
return 0;
}
#5
Re: While loop (C++)
Posted 03 June 2008 - 01:30 PM
anshuldas should use the code tags, too, like kya says. Another hint, use the % operator, too.
Page 1 of 1
|
|

New Topic/Question
Reply




MultiQuote




|