Please help with this question 💔 (I want it without a matrix) | Sololearn: Learn to code for FREE!
New course! Every coder should learn Generative AI!
Try a free lesson
- 1

Please help with this question 💔 (I want it without a matrix)

Type C ++ to read 7 numbers and determine if the numbers are stored ascending or not.

4th May 2020, 12:47 PM
Duha
Duha - avatar
12 Answers
+ 1
Simply store the number in array and loop over its length and check if arr[i]<arr[i+1] ,if not print not in ascending order
4th May 2020, 12:54 PM
Abhay
Abhay - avatar
+ 1
Sorry for disturbing you.... can you help me on how to have codes... because I am a beginner here please
6th May 2020, 8:51 AM
Jackson Kipamila
Jackson Kipamila - avatar
0
Take an input and compare it with the previous input in a for loop
4th May 2020, 2:02 PM
CeePlusPlus
CeePlusPlus - avatar
0
Abhay https://code.sololearn.com/cL7j5P8KwrWa/?ref=app What is wrong with the program? Why the result is always ascending؟
5th May 2020, 10:51 AM
Duha
Duha - avatar
0
First you didn't stored the a into b for first Loop ,like b=a and second you didn't do i>=1 because when the loop runs second time it will compare with first value of a which is stored in b to recent value of a like a<b ,now I am looking on how to use if else statement in c++ to clearly write a code and then paste it here
5th May 2020, 1:48 PM
Abhay
Abhay - avatar
0
Abhay Thanks, I hope I know my mistake
5th May 2020, 2:01 PM
Duha
Duha - avatar
0
#include <iostream> using namespace std; int main(){ int i,a,b; for(i=0;i<5;i++) { cin>>a; if(i>=1 && b<a){ cout<<"ascending order"<<endl; } else if(b>a){ cout<<"not in ascending order"<<endl; break; } b=a; } return 0; }
5th May 2020, 3:55 PM
Abhay
Abhay - avatar
0
Abhay Is the problem from me? When you perform the program . The output is only non-ascending
5th May 2020, 9:23 PM
Duha
Duha - avatar
0
Abhay Is the problem from me? When you perform the program . The output is only non-ascending
5th May 2020, 9:23 PM
Duha
Duha - avatar
0
Sorry I implemented the if Loop wrong way with && condition so it was jumping to else statement since i was 0 for first time ,just edited the code ,run it now Also you could do with nested if as I explained in python, it is much readable #include <iostream> using namespace std; int main(){ int i,a,b=0; for(i=0;i<5;i++) { cin>>a; if(i>=1){ if(b<a){ cout<<"ascending order"<<endl; } else{ cout<<"not in ascending order"<<endl; break; } } b=a; } return 0; }
5th May 2020, 9:40 PM
Abhay
Abhay - avatar
- 1
Abhay Useful information, but if I want to solve the question without matrices , what should I do؟
4th May 2020, 1:00 PM
Duha
Duha - avatar
- 1
Here is something like I assume you are expecting but in python b=0 for i in range(5): a=int(input()) if i>=1: if b<a: print("ascending order") else: print("not in ascending order") break b=a for I in range(5) is basically for(I=0;I<5;i++) a=int(input()) is converting string to integer input in c++ I think it's something like int a; cin<<a;
4th May 2020, 1:56 PM
Abhay
Abhay - avatar