Friday, 27 May 2016

Write a program that inputs the height of a triangle and display it using loop. For example if the user enters height as 5, the program should display the following. 

                        &&&&&&&&&
                           &&&&&&&
                             &&&&&
                                &&&
                                  &
Solution: 
#include <iostream.h>
#include<conio.h>
void main ()
{
    int i , n , j;
   clrscr();
   cout<<"Please Give the Value of  N as height";
   cin>>n;
   for(i = n; i >0; i++)
   {
      for(j=n-i; j>0; j--)
        cout<<" ";
      for(j = 2*i-1; j>0; j--)
       cout<<"&";
     cout<<"\n";
   }
   getch();
}

1 comment: