473,412 Members | 2,027 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

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

Nested Loop.. again

2
Hi,

I need to design the following pattern using just the 'for' and the 'if, else' statement. Please provide some help.. thanks in advance:

!!!!!!!!!*
!!!!!!!!**
!!!!!!!***
!!!!!!****
!!!!!*****
!!!!******
!!!*******
!!********
!*********
**********

The editor doesnt allow me to enter a space, so please replace ! with a space.

any help appreciated, thanks in advance
Oct 11 '06 #1
3 1721
for (int i = 1; i <= 10; i++){
for (int j = i; i < 10; i++)
cout<< " ";
for (j=1; j<=i; j++)
cout<< "*";
cout<< "\n";
}
Oct 11 '06 #2
D_C
293 100+
You can use the (code) (/code) tags (except use square brackets) to preserve whitespace. I will use them below. Also, he was supposed to use if/else.
Expand|Select|Wrap|Line Numbers
  1. for (int i = 1; i <= 10; i++)
  2. {
  3.   for (int j = 0; j < 10; j++)
  4.   {
  5.     if(j < 10-i)
  6.     {
  7.       cout << " ";
  8.     }
  9.     else
  10.     {
  11.       cout << "*";
  12.     }
  13.     cout << endl;
  14.   }
  15. }
Oct 11 '06 #3
Thank!
D_C
Oct 12 '06 #4

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

Similar topics

5
by: Martin Schou | last post by:
Please ignore the extreme simplicity of the task :-) I'm new to C, which explains why I'm doing an exercise like this. In the following tripple nested loop: int digit1 = 1; int digit2 = 0;...
5
by: dawn | last post by:
Hi, Once again I have a question : In my app, I have nested loops, very basic stuff, like for (int i = 0; i < 50; i++) { for (int j = 0 ; j < 75; j++) {
17
by: Peter Olcott | last post by:
http://www.tommti-systems.de/go.html?http://www.tommti-systems.de/main-Dateien/reviews/languages/benchmarks.html Why is C# 500% slower than C++ on Nested Loops ??? Will this problem be solved in...
13
by: PeterZ | last post by:
Hi, Back to basics! My understanding is that the only way to exit a For-Next loop prematurely is with the 'break' keyword. How are you supposed to do that if you're inside a Switch...
9
by: Javaman59 | last post by:
Using local declarations within a block often makes code more readable, but is it less efficient? eg... void P() { while (...) { int i = ...; bool b = ...; .... } }
10
by: Roshawn | last post by:
Hi, I am experimenting with nested For...Next loops. My code looks like this: Dim i as Byte Dim itm as Byte For i = 0 to 9 For itm = 0 to 9 'code omitted
77
by: Peter Olcott | last post by:
http://www.tommti-systems.de/go.html?http://www.tommti-systems.de/main-Dateien/reviews/languages/benchmarks.html The above link shows that C# is 450% slower on something as simple as a nested loop....
5
by: BMeyer | last post by:
I have been losing my mind trying to parse an XML document (with nested child elements, not all of which appear in each parent node) into a DataGrid object. What I want to do is "flatten" the XML...
2
by: th3dude | last post by:
I am trying to pull out some nested XML using C# and XMLReader. Can't seem to extract the "Items" for each "Product" when i loop through file, i can loop over the "Product" notes just fine but...
8
by: Nathan Sokalski | last post by:
I have several nested For loops, as follows: For a As Integer = 0 To 255 For b As Integer = 0 To 255 For c As Integer = 0 To 255 If <Boolean ExpressionThen <My CodeElse Exit For Next If Not...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
0
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and...

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.