Can you please tell me the c program to print the following pattern... 1 123 12345 1234567?

1 answer

Answer

1144791

2026-07-21 11:15

+ Follow

This was checked for C++ using VS2008.

#include <iOStream>

using std::cin;

using std::cout;

using std::endl;

int main()

{

cout << endl << "Enter of digits in the last number of the patter "

<< endl << "(should be odd number, if you enter even number N," << endl << "the answer will have N - 1 digits in the last number): ";

int numElem = 0;

cin >> numElem;

cout << endl << "Pattern:" << endl;

for (int i = 1; i <= numElem; i += 2)

{

for (int j = 1; j <= i; j++)

{

cout << j;

}

cout << endl;

}

system("PAUSE");

return 0;

}

For just C you might want to use something like (not tested):

#include <iOStream.h>

int main()

{

cout << endl << "Enter of digits in the last number of the patter "

<< endl << "(should be odd number, if you enter even number N,"

<< endl << "the answer will have N - 1 digits in the last number): ";

int numElem = 0;

cin >> numElem;

cout << endl << "Pattern:" << endl;

for (int i = 1; i <= numElem; i += 2)

{

for (int j = 1; j <= i; j++)

{

cout << j;

}

cout << endl;

}

system("PAUSE");

return 0;

}

ReportLike(0ShareFavorite

Copyright © 2026 eLLeNow.com All Rights Reserved.