Can anyone please check the mistake in this code of c++ project 35, I am not able to find out the minimum value. | Sololearn: Learn to code for FREE!
New course! Every coder should learn Generative AI!
Try a free lesson
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

25th Jul 2022, 12:26 PM
Hafiz Muhammad Zubair
Hafiz Muhammad Zubair - avatar
1 Answer
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.
25th Jul 2022, 12:41 PM
Jayakrishna 🇮🇳