Results 1 to 2 of 2

Thread: loop to get particular pattern

  1. #1
    FosterWood is offline Senior Member
    Join Date
    Dec 2009
    Posts
    215
    Rep Power
    3

    Default loop to get particular pattern

    How to use for loop to get particular pattern in c++?

    I am learning C++ programming language. In our lecture sir give one program where I have to show following output.

    1
    1 2
    1 2 3
    1 2 3 4
    1 2 3 4 5
    I tried different method but none of them worked out. Can anybody tell me how to use for loop to get particular output in c++? Any suggestion would be highly appreciated.

  2. #2
    FosterWood is offline Senior Member
    Join Date
    Dec 2009
    Posts
    215
    Rep Power
    3

    Default

    1) You have to use 2 for loop to obtain that output. In following program I have use 2 numeral to obtain this harvest. Just try to know it.

    #include <iostream>
    using namespace std;

    int main() {
    int sizes;
    cout << "Enter the correct length: ";
    cin >> sizes;
    for(int a=0; a<sizes; a++) {
    for(int k=1; k<sizes-a; k++)
    cout << ' ';
    for(int m=0; m<a*2+1; m++)
    cout << '&';
    cout << endl;
    }
    return 0;
    }

Similar Threads

  1. outer loop in C
    By ashley_black in forum Programming
    Replies: 1
    Last Post: 03-12-2010, 12:05 PM
  2. Java for loop example
    By WilsonMartin in forum Programming
    Replies: 1
    Last Post: 02-10-2010, 01:12 PM
  3. Differentiate between Do-While loop and While loop
    By RussellBarnes in forum Programming
    Replies: 1
    Last Post: 01-14-2010, 06:27 PM
  4. Problem in my loop
    By sara fisher in forum Programming
    Replies: 3
    Last Post: 10-21-2009, 12:03 PM
  5. using The Loop Function
    By jack879 in forum Everything Else
    Replies: 0
    Last Post: 11-17-2008, 12:45 PM

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
SEO by SubmitEdge

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48