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 control statements in C language
Is linux written in c?
What is substring in c?
The performance of an operation in several steps with each step using the output of the preceding step a) recursion b) search c) call by value d) call by reference
What is c value paradox explain?
What does the message "automatic aggregate intialization is an ansi feature" mean?
Does c have an equivalent to pascals with statement?
Is it better to use a pointer to navigate an array of values, or is it better to use a subscripted array name?
What are the similarities between c and c++?
Difference between Function to pointer and pointer to function
What are the functions to open and close the file in c language?
What is the process of writing the null pointer?
What is extern keyword in c?
What is the description for syntax errors?
Why do we write return 0 in c?