0
Can anyone please check the mistake in this code of c++ project 35, I am not able to find out the minimum value.
#include <iostream> using namespace std; int main() { int a[5]; int b[5]; for (int i = 0; i < 5; ++i) { cin >> a[i]; } //your code goes here if (a[0]>a[1]&&a[1]>a[2]&&a[2]>a[3]&&a[3]>a[4]){b[4]=a[4];} if (a[0]>a[1]&&a[1]>a[2]&&a[2]>a[4]&&a[4]>a[3]){b[3]=a[3];} if (a[0]>a[1]&&a[1]>a[3]&&a[3]>a[4]&&a[4]>a[2]){b[2]=a[2];} if (a[0]>a[2]&&a[2]>a[3]&&a[3]>a[4]&&a[4]>a[1]){b[1]=a[1];} if (a[1]>a[2]&&a[2]>a[3]&&a[3]>a[4]&&a[4]>a[0]){b[0]=a[0];} cout<<b[0]<<endl; cout<<b[1]<<endl; cout<<b[2]<<endl; cout<<b[3]<<endl; cout<<b[4]<<endl; return 0; } That is the code please check it, C++ ,35 code project
1 Antwort
0
one mistake is :
If a[0] > a[1] is false then none of your if conditions true so it print all 0's. ex: 1 2 3 4 5
Learn about loops then try this example.. It will be easy to do with loops.