Program Discussion :: Basics
65 / 279
Write a program to print pattern of numbers as below:
1
121
12321
Answer:
Asked In ::
Language:
Rajsekaran
20 Jun, 2017 11:23 PM
<!DOCTYPE html>
<html>
<body>
<?php
function Pattern()
{
$n=5;
for($i=1;$i<=$n;$i++)
{
$c=$i-1;
for($j=0;$j<(2*$i+1);$j++)
{
if($i>=$j)
{
echo $j;
}
else
{
echo $c;
$c--;
}
} echo "<br/>";
}
echo "<br/>";
}
Pattern();
?>
</body>
</html>
Language:
Sharan
7 Jul, 2017 9:30 AM
#include <stdio.h>
int main()
{
int row, c, n, temp;
printf("Enter the number of rows in pyramid of stars you wish to see ");
scanf("%d",&n);
temp = n;
for ( row = 1 ; row <= n ; row++ )
{
for ( c = 1 ; c <= row; c++ )
printf(c);
printf("\n");
}
return 0;
}
Language:
Varun
7 Jul, 2017 9:30 AM
#include <stdio.h>
#include<iostream>
using namespace std;
int main()
{
int row, c, n, temp;
cout<<"Enter the number of rows in pyramid of stars you wish to see ";
cin>>n;
temp = n;
for ( row = 1 ; row <= n ; row++ )
{
for ( c = 1 ; c <= row; c++ )
cout<<c;
cout<<"\n";
}
return 0;
}
Language:
Soma
6 Jul, 2018 12:01 AM
<ol>
<li>#include <iostream> </li>
<li>using namespace std; </li>
<li>int main() </li>
<li>{ </li>
<li>int i,j,k,l,n; </li>
<li>cout<<"Enter the Range="; </li>
<li>cin>>n; </li>
<li>for(i=1;i<=n;i ) </li>
<li>{ </li>
<li>for(j=1;j<=n-i;j ) </li>
<li>{ </li>
<li>cout<<" "; </li>
<li>} </li>
<li>for(k=1;k<=i;k ) </li>
<li>{ </li>
<li>cout<<k; </li>
<li>} </li>
<li>for(l=i-1;l>=1;l--) </li>
<li>{ </li>
<li>cout<<l; </li>
<li>} </li>
<li>cout<<"\n"; </li>
<li>} </li>
<li>return 0; </li>
<li>} </li>
</ol>
Language:
Siddhartha Paul
19 Jun, 2019 2:16 PM
import java.util.*;
public class Pattern
{
public static void main(String[] args)
{
int i,j,n=3,k=0;
for(i=0;i<n;i++)
{
k=1;
for(j=0;j<(n+i);j++)
{
if(j<n-i-1)
System.out.print(" ");
else
{
System.out.print(""+k);
if(j<(n-1))
k++;
else
k--;
}
}
System.out.println(" ");
}
}
}