Print the following pattern
Pattern for N = 4
The dots represent spaces.
Input Format :
Output Format :
Sample Input :
Sample Output :
The dots represent spaces.
code:
#include<iostream>
using namespace std;
int main(){
int n, num = 1, space;
cin>>n;
space = n - 1;
for (int i = 1; i <= n; i++)
{
num = i;
for (int j = 1; j <= space; j++)
cout<<" ";
space--;
for (int j = 1; j <= i; j++)
{
cout<<num;
num++;
}
cout<<endl;
}
}
0 comments:
Post a Comment