Monday, September 23, 2019

C ++ write nested for loops to produce a triangular array of stars, in the form below.

C ++ write nested for loops to produce a triangular array of stars, in the form below.
**
****
*****
****
**





Code

#include <iostream>
using namespace std;
int main()
{
 int i, j, k;
 for(i=1; i<3; i++)
 {
  cout<<"* ";
 }
 cout<<endl;
 for(j=1; j<5; j++)
 {
  cout<<"* ";
 }
 cout<<endl;
 for(k=1; k<=5; k++)
 {
  cout<<"* ";
 }
 cout<<endl;
 for(j=1; j<5; j++)
 {
  cout<<"* ";
 }
 cout<<endl;

 for(i=1; i<3; i++)
 {
  cout<<"* ";
 }
 cout<<endl;
 return 0;

}

Code - 2

#include <iostream>
using namespace std;
int squaresum(int n) ;

int main()
{
int n;
 cout<<"Enter the number of row : ";cin>>n;cout<<endl;
     for(int i=0; i<=n; i++)
     {
      for(int j=1; j<=i; j++)
      {
       cout<<"*";
   }
   cout<<endl;
  }
  for(int i=n-1; i>1; i--)
  {
   for(int j=1; j<=i; j++)
      {
       cout<<"*";
   }
   cout<<endl;
  }
}

OUTPUT


No comments:

Post a Comment

C++ BLACKJACK

#include <iostream> #include <ctime> #include <stdlib.h> #include <time.h> #include <string> using namesp...