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;
}
Copyright © 2026 eLLeNow.com All Rights Reserved.