By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
424,984 Members | 1,009 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 424,984 IT Pros & Developers. It's quick & easy.

I don't even know where to start

P: 5
Intro level problem; should be easy



Given an int variable k that has already been declared, use a while loop to print a single line consisting of 97 asterisks. Use no variables other than k .
Sep 18 '06 #1
Share this Question
Share on Google+
7 Replies


P: 61
Here your aim is to print 97 asterisks in one line. So you have to start a counter and let k be the counter and initialise it by 0.

Now start a while loop with the condition that is k < 97(see your counter starts with 0).

Inside the loop print one asterisk and increment the counter. So the loop will keep on printing the asterisks for k=0,1,2,.......,96 and when the value of k will become 97 the loop terminates and you will get 97 asterisks in one line.

So give a try.
Sep 19 '06 #2

P: 12
hi pukur123,i have try and it is like this........it's right....and i get the "*" print 97 times in a straight lines....
like this..
*
*
*
*
*
*
*
.
.
.
.
..
thanks ya


#include<iostream>
using namespace std;
int main()
{
int k=0;
while(k<97)
{
cout<<"*"<<endl;
k++;
}
}
Sep 19 '06 #3

P: 61
Try this one....

#include<iostream>
using namespace std;
int main()
{
int k=0;
while(k<97)
{
cout<<"*\n"<<endl;
k++;
}
}
Sep 19 '06 #4

100+
P: 293
D_C
If you want a row of 97 asterisks, instead of a column of 97 asterisks, The output statement should be cout << "*"; instead of cout << "*" << endl;
Sep 19 '06 #5

P: 12
thanks,i am much clearer now..better understanding...(*_*)
Sep 20 '06 #6

P: 3
Intro level problem; should be easy



Given an int variable k that has already been declared, use a while loop to print a single line consisting of 97 asterisks. Use no variables other than k .
hi,
i am writing a sample code for that in my standard as follows


int k;
k = 1;
while( k <= 97)
{
printf("*");
k++;
}
Sep 20 '06 #7

P: 27
int k=97;
while(k--) cout << '*';
Sep 20 '06 #8

Post your reply

Sign in to post your reply or Sign up for a free account.