Program to print the Inverted V Star Pattern

Write a C Program to Program to print the Inverted V Star Pattern.

    *
   * *
  *   *
 *     *
*       *


Problem Statement:-  Program to print the Inverted V Star Pattern.

 Data requirement:-

   Input Data:- row_size

  Output Data:- in2

  Additional Data:-in1, out


Program in C
  
Here is the source code of the C Program to print the Inverted V Star Number Pattern.

#include <stdio.h>
 int main()
  {
 printf("Enter the row size:");
  int row_size,out,in;
  scanf("%d",&row_size);
   int print_control_x=row_size;
       int print_control_y=row_size;
   for(out=1;out<=row_size;out++)
       {
           for(in=1;in<=row_size*2;in++)
           {
               if(in==print_control_x||in==print_control_y)
               {
                   printf("*");
               }
               else
               {
                 printf(" ");
               }
           }
           print_control_x--;
           print_control_y++;
           printf("\n");
       }
}


Input/Output:
Enter the row size:5
    *
   * *
  *   *
 *     *
*       *

Write a C++ Program to print the Inverted V Star Pattern.

Program in C++
  
Here is the source code of the C++ Program to print the Inverted V Star Pattern.

#include <iostream>
using namespace std;
int main()
{
   cout<<"Enter the row size:";
   int row_size,out,in;
   cin>>row_size;
   int print_control_x=row_size;
   int print_control_y=row_size;
   for(out=1;out<=row_size;out++)
       {
           for(in=1;in<=row_size*2;in++)
           {
               if(in==print_control_x||in==print_control_y)
               {
                   cout<<"*";
               }
               else
               {
                 cout<<" ";
               }
           }
           print_control_x--;
           print_control_y++;
           cout<<"\n";
       }
}


Input/Output:
Enter the row size:6
     *
    * *
   *   *
  *     *
 *       *
*         *

Write a Java Program to print the Inverted V Star Pattern.

Program in Java
  
Here is the source code of the Java Program to print the Inverted V Star Pattern.

import java.util.Scanner;
public class P36 {

public static void main(String[] args) {
Scanner cs=new Scanner(System.in);
        System.out.println("Enter the row size:");
       int out,in;
       int row_size=cs.nextInt();
       int print_control_x=row_size;
       int print_control_y=row_size;
       for(out=1;out<=row_size;out++)
       {
           for(in=1;in<=row_size*2;in++)
           {
               if(in==print_control_x||in==print_control_y)
               {
                  System.out.print("*");
               }
               else
               {
                System.out.print(" ");    
               }
           }
           print_control_x--;
           print_control_y++;
           System.out.println(); 
       }
       cs.close();
 }
}


Input/Output:
Enter the row size:
4
   *    
  * *   
 *   *  
*     * 

Write a Python Program to print the Inverted V Star Pattern.

Program in Python
  
Here is the source code of the Python Program to print the Inverted V Star Pattern.

row_size=int(input("Enter the row size:"))
print_control_x=row_size
print_control_y=row_size
for out in range(1,row_size+1):
    for in1 in range(1,row_size*2+1):
        if in1==print_control_x or in1==print_control_y:
            print("*",end="")
        else:
            print(" ", end="")
    print_control_x-=1
    print_control_y+=1
    print("\r")


Input/Output:
Enter the row size:5
    *
   * *
  *   *
 *     *
*       *

Post a Comment

0 Comments