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
Do you have any idea how to compare array with pointer in c?
Why is not a pointer null after calling free? How unsafe is it to use (assign, compare) a pointer value after it is been freed?
Why is it usually a bad idea to use gets()? Suggest a workaround.
What is the size of structure in c?
Explain 'far' and 'near' pointers in c.
Can a file other than a .h file be included with #include?
Why do we need volatile in c?
what is the diffrenet bettwen HTTP and internet protocol
When we use void main and int main?
Explain what is the difference between a free-standing and a hosted environment?
What is difference between union and structure in c?
Explain threaded binary trees?
Which is best linux os?
What is build process in c?
Why is c so powerful?