Sunday, 23 July 2017

Write the program using nested loop which display a square of satiric

Write a program using nested loop that generates the following output, a square of satiric is printed. i.e.  if enter 4, output must be

                                                  $   $   $   $                                              
                                                  $             $
                                                  $             $
                                                  $   $   $   $ 

Here are some extraordinarily simple programs in C++ for beginners. I am hoping these might help them understand how nested loops work in programming.

What is Nested Loop ?

A loop inner any other loop is referred to as a nested loop. ... We will have any wide number of nested loops as required. Remember a nested loop where the outer loop runs n times and includes any other loop inner it. The internal loop runs m times. Then, the total number of times the internal loop runs all through the program execution is n*m.

Code:


#include<stdio.h>

#include<conio.h>
int main()
{
 int r,c,sp;
 for(r=1;r<=4;r++)
 printf("$");
 printf("\n");
 for(c=1;c<=2;c++)
 {
  printf("$");
  for(sp=1;sp<=2;sp++)
  printf(" ");
 printf("$\n");
 }
 for(r=1;r<=4;r++)
  printf("$");
 getch();
 clrscr();
}

Output:


Try it yourself.
If you have any problem you can tell me on comment box i will help you.

Viral Programs

Lorem ipsum dolor sit amet, consectetur adipisicing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation.

0 comments:

Post a Comment