Write a C Program to print the Half Pyramid Number Pattern.
122
333
4444
55555
Problem statement:- Program to print the Half Pyramid Number Pattern
Data requirement:-
Input Data:- row_size
Output Data:- out
Additional Data:-in or i(In Python)
Program in C
Here is the source code of the C Program to print the Half Pyramid Number Pattern.
#include <stdio.h>
int main()
{
printf("Enter the row size:");
int row_size,out,in;
scanf("%d",&row_size);
for(out=1;out<=row_size;out++)
{
for(in=1;in<=out;in++)
{
printf("%d",out);
}
printf("\n");
}
}
Input/Output:int main()
{
printf("Enter the row size:");
int row_size,out,in;
scanf("%d",&row_size);
for(out=1;out<=row_size;out++)
{
for(in=1;in<=out;in++)
{
printf("%d",out);
}
printf("\n");
}
}
Enter the row size:5
1
22
333
4444
55555
Write a C++ Program to print the Half Pyramid Number Pattern.
Program in C++Here is the source code of the C++ Program to print the Half Pyramid Number Pattern.
#include <iostream>
using namespace std;
int main()
{
cout<<"Enter the row size:";
int row_size,in,out;
cin>>row_size;
for(out=1;out<=row_size;out++)
{
for(in=1;in<=out;in++)
{
cout<<out;
}
cout<<"\n";
}
}
Input/Output:using namespace std;
int main()
{
cout<<"Enter the row size:";
int row_size,in,out;
cin>>row_size;
for(out=1;out<=row_size;out++)
{
for(in=1;in<=out;in++)
{
cout<<out;
}
cout<<"\n";
}
}
Enter the row size:4
1
22
333
4444
Write a Java Program to print the Half Pyramid Number Pattern.
Program in JavaHere is the source code of the Java Program to print the Half Pyramid Number Pattern.
import java.util.Scanner;
public class P27 {
public static void main(String[] args) {
Scanner cs=new Scanner(System.in);
System.out.println("Enter the row size:");
int row_size,out,in;
row_size=cs.nextInt();
for(out=1;out<=row_size;out++)
{
for(in=1;in<=out;in++)
{
System.out.print(out);
}
System.out.println();
}
cs.close();
}
}
Input/Output:public class P27 {
public static void main(String[] args) {
Scanner cs=new Scanner(System.in);
System.out.println("Enter the row size:");
int row_size,out,in;
row_size=cs.nextInt();
for(out=1;out<=row_size;out++)
{
for(in=1;in<=out;in++)
{
System.out.print(out);
}
System.out.println();
}
cs.close();
}
}
Enter the row size:
6
1
22
333
4444
55555
666666
Write a Python Program to print the Half Pyramid Number Pattern.
Program in PythonHere is the source code of the Python Program to print the Half Pyramid Number Pattern.
row_size=int(input("Enter the row size:"))
for out in range(row_size+1):
for i in range(out):
print(out,end="")
print("\r")
Input/Output:for out in range(row_size+1):
for i in range(out):
print(out,end="")
print("\r")
Enter the row size:5
1
22
333
4444
55555
1 Comments
Want more prg
ReplyDeletePlease do not Enter any spam link in the comment box