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
Write the test cases for checking a variable having value in range -10.0 to +10.0?
Describe the header file and its usage in c programming?
What is binary tree in c?
Explain how can I pad a string to a known length?
Why n++ execute faster than n+1 ?
Why c is called a middle level language?
What is conio h in c?
What is structure in c definition?
Who invented b language?
Explain function?
What is strcmp in c?
Why do we use pointer to pointer in c?
What is the purpose of main() function?
How do you list a file’s date and time?
Why functions are used in c?