471,058 Members | 972 Online
Bytes | Software Development & Data Engineering Community
Post +

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 471,058 software developers and data experts.

I don't even know where to start

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
7 13830
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
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
Try this one....

#include<iostream>
using namespace std;
int main()
{
int k=0;
while(k<97)
{
cout<<"*\n"<<endl;
k++;
}
}
Sep 19 '06 #4
D_C
293 100+
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
thanks,i am much clearer now..better understanding...(*_*)
Sep 20 '06 #6
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
dush
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.

Similar topics

303 posts views Thread by mike420 | last post: by
40 posts views Thread by komone | last post: by
18 posts views Thread by tomakated | last post: by
5 posts views Thread by Steven T. Hatton | last post: by
28 posts views Thread by DFS | last post: by
reply views Thread by Nashat Wanly | last post: by
9 posts views Thread by Emanuele Aina | last post: by

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.