Golgappa.net | Golgappa.org | BagIndia.net | BodyIndia.Com | CabIndia.net | CarsBikes.net | CarsBikes.org | CashIndia.net | ConsumerIndia.net | CookingIndia.net | DataIndia.net | DealIndia.net | EmailIndia.net | FirstTablet.com | FirstTourist.com | ForsaleIndia.net | IndiaBody.Com | IndiaCab.net | IndiaCash.net | IndiaModel.net | KidForum.net | OfficeIndia.net | PaysIndia.com | RestaurantIndia.net | RestaurantsIndia.net | SaleForum.net | SellForum.net | SoldIndia.com | StarIndia.net | TomatoCab.com | TomatoCabs.com | TownIndia.com
Interested to Buy Any Domain ? << Click Here >> for more details...

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

Do you have any idea how to compare array with pointer in c?

1098


Why is not a pointer null after calling free? How unsafe is it to use (assign, compare) a pointer value after it is been freed?

1217


Why is it usually a bad idea to use gets()? Suggest a workaround.

1875


What is the size of structure in c?

1217


Explain 'far' and 'near' pointers in c.

1190


Can a file other than a .h file be included with #include?

1225


Why do we need volatile in c?

1232


what is the diffrenet bettwen HTTP and internet protocol

1886


When we use void main and int main?

1131


Explain what is the difference between a free-standing and a hosted environment?

1240


What is difference between union and structure in c?

1249


Explain threaded binary trees?

1216


Which is best linux os?

1083


What is build process in c?

1206


Why is c so powerful?

1168