Tuesday, 22 November 2016

Write a program that displays a diamond of asterisks using loop.



       
        #include <iostream.h>
        #include <conio.h>
        int main ()

        {
             int i, j; 

              for (i 0; i <4; i++)
             {
                   for (j 0; j <= 5-i; j++)
                       cout<< " " 

                   for (j = 5-i; j <= 5+i; j++)
                       cout<< "*" 

                  cout<< endl;
              }

               for (i 2; i <= 5; i++)
              {
                    for (j = 0; j <= i; j++)
                        cout<< " " ;

                    for (j = i; j <= (10-i); j++)
                        cout<< "*" ;

                       cout<< endl;
               }
               return 0;
        }


Output: 

                            

4 comments:

  1. what do i and j stand for? im working on this but have 4 variables.

    ReplyDelete
    Replies
    1. i and j are counter variables used for loop iterations.

      Delete
  2. I’ve been searching for some decent stuff on the subject and haven't had any luck up until this point, You just got a new biggest fan!.. necklace charms

    ReplyDelete

If you have any doubt please let me know

Methods in JAVA Language

 In general, a way may be thanks to perform some task. Similarly, the tactic in Java may be a collection of instructions that performs a sel...