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


Please Help Members By Posting Answers For Below Questions

What is the difference between c &c++?

657


Is null valid for pointers to functions?

621


What is c variable?

565


Explain what are the __date__ and __time__ preprocessor commands?

601


What is sorting in c plus plus?

570






#define MAX(x,y) (x) >(y)?(x):(y) main() { inti=10,j=5,k=0; k= MAX(i++,++j); printf("%d..%d..%d",i,j,k); }

790


How to write c functions that modify head pointer of a linked list?

554


What is 1d array in c?

616


How many types of arrays are there in c?

609


what is the difference between 123 and 0123 in c?

733


If jack lies on Mon, Tue Wed and jill lies on Thursday, Friday and Saturday. If both together tell they lied yesterday. So c the given options and then c cos in the given dates one will be saying the truth and one will be lying. I got Thursday as option because jack is saying the truth he lied yest but jill is lying again as he lies on that day.

1795


What are register variables? What are the advantage of using register variables?

698


How can I display a percentage-done indication that updates itself in place, or show one of those twirling baton progress indicators?

595


What functions are used in dynamic memory allocation in c?

604


Is it fine to write void main () or main () in c?

559