Write a program in c to print
1
121
12321
1234321
123454321
Answer Posted / rahim
int i, j, k, num = 5;
cout << "number u1=";
cin >> num;
for (i = 1; i <= num; i++)
{
for (j = 1; j <= num - i; j++)
{
cout << " ";
}
for (k = 1; k < i; k++)
{
cout << k;
}
for (k = i; k >= 1; k--)
{
cout << k;
}
cout << endl;
}
//----------------------------------------
for (i = num; i >= 1; i--)
{
for (j = 1; j <= num - i; j++)
{
cout << " ";
}
for (k = 1; k < i; k++)
{
cout << k;
}
for (k = i; k >= 1; k--)
{
cout << k;
}
cout << endl;
}
| Is This Answer Correct ? | 1 Yes | 1 No |
Post New Answer View All Answers
What is the difference between specifying a constant variable like with constant keyword and #define it? i.e what is the difference between CONSTANT FLOAT A=1.25 and #define A 1.25
What is the use of sizeof?
What are multidimensional arrays?
What is a list in c?
Can a variable be both static and volatile in c?
what is a NULL Pointer? Whether it is same as an uninitialized pointer?
What does c mean?
What is meant by recursion?
What is a struct c#?
What is the advantage of c?
can any one tel me wt is the question pattern for NIC exam
Explain void pointer?
Explain what is gets() function?
What are the different types of C instructions?
Explain how can type-insensitive macros be created?