Write a C++ program to print K shape number pattern using for loop.
#include<iostream> using namespace std; int main() { int i, j, k, rows; cout << "Enter K Shape Number Pattern Row = "; cin >> rows; cout << "K Shape Number Pattern\n"; for(i = rows; i >= 1; i--) { for(j = 1; j <= i; j++) { cout << j << " "; } cout << "\n"; } for(i = 2; i <= rows; i++) { for(j = 1; j <= i; j++) { cout << j << " "; } cout << "\n"; } return 0; }

This C++ example uses a while loop to print a K shape number pattern.
#include<iostream> using namespace std; int main() { int i, j, k, rows; cout << "Enter K Shape Number Pattern Row = "; cin >> rows; cout << "K Shape Number Pattern\n"; i = rows; while( i >= 1) { j = 1; while( j <= i) { cout << j << " "; j++; } cout << "\n"; i--; } i = 2; while( i <= rows) { j = 1; while( j <= i) { cout << j << " "; j++; } cout << "\n"; i++; } return 0; }
Enter K Shape Number Pattern Row = 9
K Shape Number Pattern
1 2 3 4 5 6 7 8 9
1 2 3 4 5 6 7 8
1 2 3 4 5 6 7
1 2 3 4 5 6
1 2 3 4 5
1 2 3 4
1 2 3
1 2
1
1 2
1 2 3
1 2 3 4
1 2 3 4 5
1 2 3 4 5 6
1 2 3 4 5 6 7
1 2 3 4 5 6 7 8
1 2 3 4 5 6 7 8 9