1234554321
1234 4321
123 321
12 21
1 1
12 21
123 321
1234 4321
1234554321

Answers were Sorted based on User's Feedback



1234554321 1234 4321 123 321 12 21 1 1 12 21 123 321 1234 4321 1234..

Answer / c++ coder

#include <iostream>
using namespace std;

int main()
{

int MAX =5; /*the number to which series needs to
be created*/
int i,j,k;

/* this loop will print first half of the series*/
for (int m = MAX; m >0 ; m-- )
{
cout<<endl;

for( i =0; i<m; i++) /*loop to print start
numbers from 1 to MAX in each line*/
cout<<(i+1);

for( k = 0; k< 2*(MAX-i);k++) /*space which
needs to be printed after the incremented num*/
cout<<" ";

for( j = i ; j>0 ; j--)/* loop to print
decremented num*/
cout<<j;

}

/* this loop will print next half of the series -
duplicate line skipped*/
for ( int n = 2; n <= MAX ; n++ )
{
cout<<endl;
for ( i = 0; i<n ; i++)
cout<<(i+1);

for( k = 0; k< 2*(MAX-i);k++)
cout<<" ";

for( j = i ; j>0 ; j--)
cout<<j;

}

cout<<endl;
}

Is This Answer Correct ?    4 Yes 0 No

1234554321 1234 4321 123 321 12 21 1 1 12 21 123 321 1234 4321 1234..

Answer / mahesh m

#include<stdio.h>
int main()
{
int i,j,n=5,a;
for (i=1;i<5;i++)
{
for(j=1;j<=n;j++)
{
printf("%d",j);
a=j;
}
for(int k=1;k<=n;k++)
{
printf("%d",a);
a--;
}
n=n-1;
}
}

Is This Answer Correct ?    0 Yes 1 No

Post New Answer

More OOPS Interview Questions

What is conditional Compilation?

3 Answers   emc2, HCL,


What is basic concept of oop?

0 Answers  


What are the access specifiers avaible in c++?

4 Answers  


The type of variable a pointer points to must be the part of pointer's definition so that:

1 Answers   Infosys,


i hav very low percentage in 12th n BSCwhich is around 50.......coz it was just imposed on me 2 b a science graduate,nw m doin MCA n hav aggregate 74% ....what shud i answer if company's HR ask me about dis much low previous percentage??????

3 Answers   Infosys,






Can a varargs method be overloaded?

0 Answers  


can main method be overloaded...??? How..????

2 Answers   Satyam,


What is encapsulation selenium?

0 Answers  


What is overriding vs overloading?

0 Answers  


What does no cap mean?

0 Answers  


Polymorphism with an example?

8 Answers   Accenture, emc2,


Why do we use inheritance?

0 Answers  


Categories