Write a C Program to print the Solid Half Diamond Star Pattern.
***
***
****
*****
****
***
**
*
Problem statement:- Program to print the Solid Half Diamond Star Pattern
Data requirement:-
Input Data:- row_size
Output Data:- Nothing
Additional Data:-in or i(In Python), out
Program in C
Here is the source code of the C Program to print the Solid Half Diamond Star Pattern.
#include <stdio.h>
#include<math.h>
int main()
{
printf("Enter the row size:");
int row_size,in,out;
scanf("%d",&row_size);
for(out=row_size;out>=-(row_size-1);out--)
{
for(in=(row_size-1);in>=abs(out);in--)
{
printf("*");
}
printf("\n");
}
}
Input/Output:#include<math.h>
int main()
{
printf("Enter the row size:");
int row_size,in,out;
scanf("%d",&row_size);
for(out=row_size;out>=-(row_size-1);out--)
{
for(in=(row_size-1);in>=abs(out);in--)
{
printf("*");
}
printf("\n");
}
}
Enter the row size:5
*
**
***
****
*****
****
***
**
*
Write a C++ Program to print the Solid Half Diamond Star Pattern.
Program in C++Here is the source code of the C++ Program to print the Solid Half Diamond Star Pattern.
#include <iostream>
#include<cmath>
using namespace std;
int main()
{
cout<<"Enter the row size:";
int row_size,in,out;
cin>>row_size;
for(out=row_size;out>=-(row_size-1);out--)
{
for(in=(row_size-1);in>=abs(out);in--)
{
cout<<"*";
}
cout<<"\n";
}
}
Input/Output:#include<cmath>
using namespace std;
int main()
{
cout<<"Enter the row size:";
int row_size,in,out;
cin>>row_size;
for(out=row_size;out>=-(row_size-1);out--)
{
for(in=(row_size-1);in>=abs(out);in--)
{
cout<<"*";
}
cout<<"\n";
}
}
Enter the row size:4
*
**
***
****
***
**
*
Write a Java Program to print the Solid Half Diamond Star Pattern.
Program in JavaHere is the source code of the Java Program to print the Solid Half Diamond Star Pattern.
import java.util.Scanner;
public class P26 {
public static void main(String[] args) {
Scanner cs=new Scanner(System.in);
System.out.println("Enter the row size:");
int row_size=cs.nextInt();
for(int out=row_size;out>=-(row_size-1);out--)
{
for(int in=(row_size-1);in>=Math.abs(out);in--)
{
System.out.print("*");
}
System.out.println();
}
cs.close();
}
}
Input/Output:public class P26 {
public static void main(String[] args) {
Scanner cs=new Scanner(System.in);
System.out.println("Enter the row size:");
int row_size=cs.nextInt();
for(int out=row_size;out>=-(row_size-1);out--)
{
for(int in=(row_size-1);in>=Math.abs(out);in--)
{
System.out.print("*");
}
System.out.println();
}
cs.close();
}
}
Enter the row size:
3
*
**
***
**
*
Write a Python Program to print the Solid Half Diamond Star Pattern.
Program in PythonHere is the source code of the Python Program to print the Solid Half Diamond Star Pattern.
row_size=int(input("Enter the row size:"))
for out in range(row_size,-(row_size-1),-1):
for i in range((row_size),abs(out-1),-1):
print("*",end="")
print("\r")
Input/Output:for out in range(row_size,-(row_size-1),-1):
for i in range((row_size),abs(out-1),-1):
print("*",end="")
print("\r")
Enter the row size:6
*
**
***
****
*****
******
*****
****
***
**
*
0 Comments
Please do not Enter any spam link in the comment box