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
Explain what are compound statements?
Tell me what is null pointer in c?
What is an array in c?
How can you increase the size of a dynamically allocated array?
How can I call a function with an argument list built up at run time?
What is the purpose of realloc()?
Who is the main contributor in designing the c language after dennis ritchie?
What is || operator and how does it function in a program?
What is the code in while loop that returns the output of given code?
What is a MAC Address?
What is the difference between a function and a method in c?
What's the difference between constant char *p and char * constant p?
How will you delete a node in DLL?
Can you explain what keyboard debouncing is, and where and why we us it? please give some examples
What is the difference between Printf(..) and sprint(...) ?