Â
The Code given below can be used in TURBO C++ Compilers: -
#include <iostream.h>
#include <stdio.h>
#include <conio.h>
#define lim(n) (n * (n + 1)) / 2
void main()
{
int r, n;
cout << "Enter row: ";
cin >> r;
n = lim(r);
for (int i = r; i >= 1; i--)
{
for (int j = r; j > r - i; j--)
{
cout << n << " ";
n--;
}
cout << endl;
}
getch();
clrscr();
}
The Code given below can be used in gcc/g++ Compilers: -
#include <iostream>
using namespace std;
#define lim(n) (n * (n + 1)) / 2
int main()
{
int r, n;
cout << "Enter row: ";
cin >> r;
n = lim(r);
for (int i = r; i >= 1; i--)
{
for (int j = r; j > r - i; j--)
{
cout << n << " ";
n--;
}
cout << endl;
}
return 0;
}
#ENJOY CODING
Post a Comment
FOR ANY DOUBTS AND ERRORS FEEL FREE TO ASK. YOUR DOUBTS WILL BE ADDRESSED ASAP