Write a C Program to print the Solid Diamond Star Pattern.
** *
* * *
* * * *
* * * * *
* * * * * *
* * * * *
* * * *
* * *
* *
*
Problem statement:- Program to print the Solid 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 Diamond Star Pattern.
#include <stdio.h>
#include<math.h>
int main()
{
printf("Enter the row size:");
int row_size,out,in1,in2;
scanf("%d",&row_size);
for(out=row_size;out>=-row_size;out--)
{
for(in1=1;in1<=abs(out);in1++)
{
printf(" ");
}
for(in2=row_size;in2>=abs(out);in2--)
printf("* ");
printf("\n");
}
}
Input/Output:#include<math.h>
int main()
{
printf("Enter the row size:");
int row_size,out,in1,in2;
scanf("%d",&row_size);
for(out=row_size;out>=-row_size;out--)
{
for(in1=1;in1<=abs(out);in1++)
{
printf(" ");
}
for(in2=row_size;in2>=abs(out);in2--)
printf("* ");
printf("\n");
}
}
Enter the row size:5
*
* *
* * *
* * * *
* * * * *
* * * * * *
* * * * *
* * * *
* * *
* *
*
Write a C++ Program to print the Solid Diamond Star Pattern.
Program in C++
Here is the source code of the C++ Program to print the Solid Diamond Star Pattern.
#include <iostream>
#include<cmath>
using namespace std;
int main()
{
cout<<"Enter the row size:";
int row_size,out,in1,in2;
cin>>row_size;
for(out=row_size;out>=-row_size;out--)
{
for(in1=1;in1<=abs(out);in1++)
{
cout<<" ";
}
for(in2=row_size;in2>=abs(out);in2--)
cout<<"* ";
cout<<"\n";
}
}
Input/Output:#include<cmath>
using namespace std;
int main()
{
cout<<"Enter the row size:";
int row_size,out,in1,in2;
cin>>row_size;
for(out=row_size;out>=-row_size;out--)
{
for(in1=1;in1<=abs(out);in1++)
{
cout<<" ";
}
for(in2=row_size;in2>=abs(out);in2--)
cout<<"* ";
cout<<"\n";
}
}
Enter the row size:6
*
* *
* * *
* * * *
* * * * *
* * * * * *
* * * * * * *
* * * * * *
* * * * *
* * * *
* * *
* *
*
Write a Java Program to print the Solid Diamond Star Pattern.
Program in JavaHere is the source code of the Java Program to print the Solid Diamond Star Pattern.
import java.util.Scanner;
public class SolidDiamondStarPattern{
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;out--)
{
for(int in1=1;in1<=Math.abs(out);in1++)
{
System.out.print(" ");
}
for(int in2=row_size;in2>=Math.abs(out);in2--)
System.out.print("* ");
System.out.println();
}
cs.close();
}
}
Input/Output:public class SolidDiamondStarPattern{
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;out--)
{
for(int in1=1;in1<=Math.abs(out);in1++)
{
System.out.print(" ");
}
for(int in2=row_size;in2>=Math.abs(out);in2--)
System.out.print("* ");
System.out.println();
}
cs.close();
}
}
Enter the row size:
4
*
* *
* * *
* * * *
* * * * *
* * * *
* * *
* *
*
Write a Python Program to print the Solid Diamond Star Pattern.
Program in PythonHere is the source code of the Python Program to print the Solid Diamond Star Pattern.
row_size=int(input("Enter the row size:"))
for out in range(row_size,-row_size,-1):
for in1 in range(1,abs(out)+1):
print(" ",end="")
for in2 in range(row_size,abs(out),-1):
print("* ",end="")
print("\r")
Input/Output:for out in range(row_size,-row_size,-1):
for in1 in range(1,abs(out)+1):
print(" ",end="")
for in2 in range(row_size,abs(out),-1):
print("* ",end="")
print("\r")
Enter the row size:5
*
* *
* * *
* * * *
* * * * *
* * * * * *
* * * * *
* * * *
* * *
* *
*
0 Comments
Please do not Enter any spam link in the comment box