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 polymorphism give a real life example?

0 Answers  


what are the ways in which a constructors can be called?

0 Answers  


what is runtime polymorphism? For the 5 marks.

3 Answers  


officer say me - i am offered to a smoking , then what can you say

0 Answers  


what is a ststic variable and stiticfunction briefly explain with exmple and in which case we use

2 Answers   HCL,






What is multilevel inheritance?

0 Answers  


what type of question are asked in thoughtworks pair programming round ?

0 Answers   Thought Works,


WHAT'S THE OOPS BASIC OOPS CONCEPTS IN DOTNET

1 Answers  


What is the difference between Home and $Home?

2 Answers   TCS,


#include <stdio.h> #include <alloc.h> #include <stdlib.h> #include <conio.h> void insert(struct btreenode **, int); void inorder(struct btreenode *); struct btreenode { struct btreenode *leftchild; struct btreenode *rightchild; int data; }; main() { struct btreenode *bt; bt=(struct btreenode *)NULL; int req,i=1,num; clrscr(); printf("Enter number of nodes"); scanf("%d",&req); while(i<=req) { printf("Enter element"); scanf("%d",&num); insert(&bt,num); i++; } inorder(bt); } void insert(struct btreenode **sr, int num) { if(*sr==NULL) { *sr=(struct btreenode *)malloc (sizeof(struct btreenode)); (*sr)->leftchild=(struct btreenode *)NULL; (*sr)->rightchild=(struct btreenode *)NULL; (*sr)->data=num; return; } else { if(num < (*sr)->data) insert(&(*sr)->leftchild,num); else insert(&(*sr)->rightchild,num); } return; } void inorder(struct btreenode *sr) { if(sr!=(struct btreenode *)NULL) { inorder(sr->leftchild); printf("\n %d",sr->data); inorder(sr->rightchild); } else return; } please Modify the given program and add two methods for post order and pre order traversals.

0 Answers  


What is sub classing in c++?

1 Answers  


What is oops with example?

0 Answers  


Categories