Write a C Program to print the Half Pyramid Number Pattern.
112
123
1234
12345
Problem statement:- Program to print the Half Pyramid Number Pattern
Data requirement:-
Input Data:- row_size
Output Data:- in or i(In Python)
Additional Data:-out
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",in);
}
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",in);
}
printf("\n");
}
}
Enter the row size:5
1
12
123
1234
12345
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<<in;
}
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<<in;
}
cout<<"\n";
}
}
Enter the row size:6
1
12
123
1234
12345
123456
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 P28 {
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(in);
}
System.out.println();
}
cs.close();
}
}
Input/Output:public class P28 {
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(in);
}
System.out.println();
}
cs.close();
}
}
Enter the row size:
4
1
12
123
1234
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(1,out+1):
print(i,end="")
print("\r")
Input/Output:for out in range(row_size+1):
for i in range(1,out+1):
print(i,end="")
print("\r")
Enter the row size:5
1
12
123
1234
12345
0 Comments
Please do not Enter any spam link in the comment box