Write a C++ program that reads a list of numbers 10 and displays
largest,
second largest and third largest.
Note: Please do it with loops don't used arrays
#include<iostream> using namespace std; int main() { int i,f=0,s=0,m=0,num,temp,temp1; for(i=0;i<10;i++) { cout<<"enter the " <<i+1<<" number\n"; cin>>num; if(i==0) { f=num; } if(i==1) { if(f<num) { temp=f; f=num; s=temp; } else if(f==num) { continue; } else { s=num; } } else { if(f==num||s==num) { continue; } if(f<num) { temp=f; f=num; temp1=s; s=temp; m=temp1; } else if(s<num) { temp=s; s=num; m=temp; } else if(num>m) { m=num; } else continue; } } if(s==0) { cout<<"1st:"<<f<<" \t Not yet found 2nd largest elemnt \t Not yet found 3rd largest elemnt"; } if(s!=0 && m==0) { cout<<"1st:"<<f<<"\t2nd:"<<s<<"\t Not yet found 3rd largest elemnt"; } else { cout<<"1st largest:"<<f<<"\t2nd largest:"<<s<<"\t3rdlargest:"<<m; return 0; } }
output::
Here's a C++ program that reads a list of 10 numbers and displays the largest, second largest, and third largest numbers using loops:
cppCopy code#include <iostream>int main() { int largest = INT_MIN; int secondLargest = INT_MIN; int thirdLargest = INT_MIN; for (int i = 1; i <= 10; i++) { int num; std::cout << "Enter number " << i << ": "; std::cin >> num; if (num > largest) { thirdLargest = secondLargest; secondLargest = largest; largest = num; } else if (num > secondLargest) { thirdLargest = secondLargest; secondLargest = num; } else if (num > thirdLargest) { thirdLargest = num; } } std::cout << "Largest: " << largest << std::endl; std::cout << "Second Largest: " << secondLargest << std::endl; std::cout << "Third Largest: " << thirdLargest << std::endl; return 0; }
In this program, we initialize three variables (largest
, secondLargest
, and thirdLargest
) with the minimum possible integer value (INT_MIN
). We then use a loop to read 10 numbers from the user. For each number, we compare it with the current largest, second largest, and third largest numbers and update the variables accordingly.
Finally, we display the largest, second largest, and third largest numbers obtained from the loop.
Write a C++ program that reads a list of numbers 10 and displays largest, second largest...
6.2 - Write a program that reads numbers and adds them to a list if they aren't already contained in the list. When the list contains ten numbers, the program displays the contents and quits. Use Python 3 Please. Comments in code if you can
Max3.java: Write a program that reads 10 integers and displays top 3 records (i.e., the largest three elements). Please consider the extreme case when all integers are negative. For instance, by given -1, -2, …, -10, the display will be -1, -2, and -3.
In C++ Sorted List of User Entered Numbers 2. Write a program that reads in a list of integers into a vector with base type int. Provide the facility to read this vector from an input file. Make sure to ask the user for a filename. The output is a two-column list. The first column is a list of the distinct vector elements. The second column is the count of the number of occurrences for each element. The list should...
Can you please answer this in complete C++ program. I. Write a program that reads in an array of five integers al 5] and arses the mray in t fncion largest that rcurns the value of the largest element in the arrav, 2.Write a program that reads in two arrays, a[3] and b[3], and passes them to a function Scalarproduct that returns the scalar product of these arrays; the scalar product of two arrays is
Write an assembly program that finds the largest two numbers in list of 10 numbers. use if cond and loop list = 111, 32, 51, 220, 10, 13, 34, 113, 56, 44
1. Write a program that reads a sequence of numbers from the keyboard, and displays the smallest number. The sequence has at least one number and is terminated by -999(-999 will not appear in the sequence other than as the end marker). 2. Write a program which requests an integer input n from the keyboard and computes the sum of square of k for all k from 1 to n(inclusive). use java
Write a program that reads k integers and displays their sum. Write a program that reads k values representing family income from the keyboard and place them into the array. Find the maximum income among these values. Count the families that make less than 10 percent of the maximum income. (JAVA)
In the Java language APCS Sorting Numbers Lab Write a program that reads in 3 floating-point numbers (decimal numbers) and prints the three numbers in sorted order from smallest to largest. In your main method, create a scanner and get the 3 numbers from the user. Create a separate method called sort that accepts the 3 numbers prints them in the appropriate order. Sample Run#1 Please enter first number: 4 Please enter second number: 9 Please enter third number: 2.5...
write in c programming Write a C program that reads in up to 10 numbers into an array. The program should count the number of duplicate elements within that array and print the result. Example test data and expected output is given below Test Data: [2,1,1,2,1,3, 4] Duplicates:
Write a C program that reads a sequence of numbers and display a message 1. The numbers a re red from the standard input. 2. The first number is the length of the sequence (n) followed by n numbers. 3. If n is 0 or negative, the program displays the message "Error_1" followed 4. If the length is shorter than n, it displays "Error_2" followed by a new line 5. The program inspects the list and display one of the...