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

Explain what are compound statements?

605


Tell me what is null pointer in c?

615


What is an array in c?

597


How can you increase the size of a dynamically allocated array?

641


How can I call a function with an argument list built up at run time?

639






What is the purpose of realloc()?

672


Who is the main contributor in designing the c language after dennis ritchie?

553


What is || operator and how does it function in a program?

629


What is the code in while loop that returns the output of given code?

1316


What is a MAC Address?

628


What is the difference between a function and a method in c?

560


What's the difference between constant char *p and char * constant p?

657


How will you delete a node in DLL?

686


Can you explain what keyboard debouncing is, and where and why we us it? please give some examples

1659


What is the difference between Printf(..) and sprint(...) ?

789