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 translation phases used in c language?

724


Is it better to use a pointer to navigate an array of values, or is it better to use a subscripted array name?

745


What is define c?

673


Can we assign string to char pointer?

678


To print the pattern 1 2 3 4 5 10 17 18 19 6 15 24 25 20 7 14 23 22 21 8 13 12 11 10 9

2312






What does the file stdio.h contain?

695


What are the different types of data structures in c?

712


What is the easiest sorting method to use?

720


How many loops are there in c?

684


How can I find the modification date and time of a file?

698


Write a Program to find whether the given number or string is palindrome.

742


#define PRINT(int) printf("int = %d ",int) main() {< BR> intx,y,z; x=03;y=02;z=01; PRINT(x^x); z<<=3;PRINT(x); y>>=3;PRINT(y); }

832


What is #include stdio h and #include conio h?

681


how to find binary of number?

3658


What are types of structure?

701