Write a program and call it sortcheck.cpp which receives 10 numbers from input and checks whether these numbers are in ascending order or not. You are not allowed to use arrays. You should not define more than three variables

Answers were Sorted based on User's Feedback



Write a program and call it sortcheck.cpp which receives 10 numbers from input and checks whether th..

Answer / jobbine joseph

int main()
{
int Reading_num,Previou_num=-999999,i=0;
for(i=0;i<10;i++)
{
cin>>Reading_num;
if(Reading_num < Previous_num)
{
break;
}
Previous_num = Reading_num;
}
if(i<10)
{
cout<<"Numbers are Not in ASCENDING";
}
else
{
cout<<"Numbers are in ASCENDING ";
}

return(0);
}

Is This Answer Correct ?    8 Yes 1 No

Write a program and call it sortcheck.cpp which receives 10 numbers from input and checks whether th..

Answer / rajesh

I think this one is good answer...

#include<iostream>
using namespace std;

int main()
{
int prev = 0, next, i;

for(i = 0; i<5; i++)
{
cin>>next;
if(next > prev)
{
prev = next;
}
else
{
cout<<"not in ascending
order..\n"<<endl;
break;
}
}
if(i==5)
cout<<"Ascending order...\n"<<endl;
}

Is This Answer Correct ?    1 Yes 0 No

Post New Answer

More C++ General Interview Questions

What is pointer -to-members in C++? Give their syntax?

0 Answers   Honeywell, Zomato,


Is swift faster than c++?

0 Answers  


What do you mean by a template?

0 Answers  


Is it possible to use a new for the reallocation of pointers ?

0 Answers  


Does defining a function inline mean that it wont push and pop things on/off the stack ...like parameters and the return the address??

2 Answers  






find the two largest values among the 6 numbers using control structures : do-while,for,if else,nestedif- else ,while. one or two of them.

0 Answers  


char *ch = "abcde"; char c[4]; how to copy 'ch' to 'c'?

4 Answers   Thomson Reuters,


Which bitwise operator is used to check whether a particular bit is on or off?

0 Answers  


Why do we use the using declaration?

0 Answers  


What is the topic of the C++ FAQ list?

1 Answers  


Can we overload operator in c++?

0 Answers  


Why do we need constructors in c++?

0 Answers  


Categories