0

A program that receives 10 numbers and displays the second largest number along with its input number.

#include<iostream> using namespace std; int main() { int flag1,flag2; /// for(int i=1; i<=10 ; i+=2) { int x[i],a[i]; cout<<"x["<<i<<"]"<<'\n'; cin>>x[i]; cout<<"x["<<i+1<<"]"<<'\n'; cin>>a[i+1]; } /// int i=1; int x[i], a[i]; int max1; int max2; //// for (i=3; i<=10 ; i+=2) { max1 = a[2]; if(a[i+1]>max1) { max1 = a[i+1]; flag1 = i+1; } } /// for (i=3; i<=10 ; i+=2) { max2 = x[1]; if(x[i] > max2) { max2 = a[i]; flag2 = i; } } /// if(max2>max1) { cout<<max1<<" p = "<<flag1<<endl; } if(max2<max1) { cout<<max2<<" p ="<<flag2<<endl; } return 0; } \\I can`t write this program in well. \\can you help me?

22nd May 2021, 12:04 PM
alireza mohammadian
alireza mohammadian - avatar
2 Answers
0
your code is unreadable and it doesn't do the job. i don't think one will try to improve your code. but... I was managed to print the second number but I couldn't work it to print out the position in which the second largest is in https://code.sololearn.com/cczu5F6ktNqI/?ref=app edit: guess I can't help you with.
22nd May 2021, 12:57 PM
Rellot's screwdriver
Rellot's screwdriver - avatar
0
You can copy to your compiler in computer and run it again .it has some output but it is wrong answer
22nd May 2021, 1:09 PM
alireza mohammadian
alireza mohammadian - avatar