Question

2. Write an algorithm to display up to 10 user inputs 3. Write an algorithm to display print first 5 items in a collection. 4

Help pls for assignment

0 0
Add a comment Improve this question Transcribed image text
Answer #1

2)

->initialize array of size 10 and i to n0

->Iterate loop 10 times

->read input from user and store it in array

->increment i value

3)

->Iniitialize i to 0

->Iterate array 5 times.

->display element in that index i

->Increment i value

4)

->read 3 numbers a,b,c

->check if a>b and a>c

->display a is large number

->else check b>c

->display b is large number.

->else

->c is the largest number.

CODE:

#include<iostream>
using namespace std;
int main()
{
   int arr[10],i,j;
   for(i=0;i<10;i++) {
       cin>>arr[i];
   }
  
   //3)ans
   for(i=0;i<5;i++) {
       cout<<arr[i]<<"\t";
   }
   //4)ans..
   int a,b,c;
   cout<<"\nEnter 3 numbers : ";
   cin>>a>>b>>c;
   if(a>b && a>c)
       cout<<a<<"is large";
   else if(b>c)
       cout<<b<<" is large";
   else
       cout<<c<<" is large";
  
}

OUTPUT:

Dev-C++ 5.2.0.2 Eile Edit Search View Project Execute Debug Tools CVS Window Help IO. * B65E 10HIIH+* ] 0 (globals) algo.cpp

if you have any doubts please COMMENT...

if you understand the answer please give THUMBS UP...

Add a comment
Know the answer?
Add Answer to:
Help pls for assignment 2. Write an algorithm to display up to 10 user inputs 3....
Your Answer:

Post as a guest

Your Name:

What's your source?

Earn Coins

Coins can be redeemed for fabulous gifts.

Not the answer you're looking for? Ask your own homework help question. Our experts will answer your question WITHIN MINUTES for Free.
Similar Homework Help Questions
  • 1-Write an algorithm to get two numbers from the user (as inputs) and calculate the sum...

    1-Write an algorithm to get two numbers from the user (as inputs) and calculate the sum of two numbers and print out the result. (draw the flow chart) 2-Write an algorithm to get a number from the user and calculate the square of that number and print out the result.

  • Write a program that lets the user enter 10 values into an array. The program should...

    Write a program that lets the user enter 10 values into an array. The program should then display the largest and the smallest values stored in the array. The program should display the following message to the user at the beginning "This program will ask you to enter ten values. Then it will determine the largest and smallest of the values you entered.Please enter 10 integers separated by spaces: " And then after user entered the numbers, it should display...

  • Write a script which asks the user to input numbers until the user inputs 0. Then...

    Write a script which asks the user to input numbers until the user inputs 0. Then the script should print only the positive numbers entered by the user, in reverse order E.G. if the user inputs '4, -1, 5, 2, -3, -8, 0', the script should print '2, 5, 4'. Please don't copy someone else's answer as they don't work.

  • Write an algorithm that takes an array B and a number N as inputs. Suppose that...

    Write an algorithm that takes an array B and a number N as inputs. Suppose that the array B contains n distinct numbers. Compute the sum of the N largest numbers in the array B. Example: if the array B= [4, 5, 8, 11, 3] and N = 3, then the algorithm should return 24 (11+8+5).

  • 2. Write an application that inputs a 3-digits number from the user and checks if all...

    2. Write an application that inputs a 3-digits number from the user and checks if all digits are prime numbers. If all digits are prime your program should stop. Use do/while for reading the input and any loop format to test if the number is prime. When checking the prime numbers don't use an if to check numbers from 1 - 9; you need to find an algorithm to check if the number is prime or not. Enter a 3-digit...

  • In Matlab, write a script which asks a user to input numbers until the user inputs...

    In Matlab, write a script which asks a user to input numbers until the user inputs 0. Then the script should print only the positive numbers entered by the user, in reverse order. For example, if the user inputs “4,-1,5,2,-3,-8,0” the script should print “2,5,4”.

  • Write a single program in java using only do/while loops for counters(do not use array pls)...

    Write a single program in java using only do/while loops for counters(do not use array pls) for the majority of the program and that asks a user to enter a integer and also asks if you have any more input (yes or no) after each input if yes cycle again, if not the program must do all the following 4 things at the end of the program once the user is finished inputting all inputs... a.The smallest and largest of...

  • 5.2 Write a program that repeatedly prompts a user for integer numbers until the user enters...

    5.2 Write a program that repeatedly prompts a user for integer numbers until the user enters 'done'. Once 'done' is entered, print out the largest and smallest of the numbers. If the user enters anything other than a valid number catch it with a try/except and put out an appropriate message and ignore the number. Enter 7, 2, bob, 10, and 4 and match the output below. ​ 1 largest = None 2 smallest = None 3 while True: 4...

  • 5.2 Write a program that repeatedly prompts a user for integer numbers until the user enters...

    5.2 Write a program that repeatedly prompts a user for integer numbers until the user enters 'done'. Once 'done' is entered, print out the largest and smallest of the numbers. If the user enters anything other than a valid number catch it with a try/except and put out an appropriate message and ignore the number. Enter 7, 2, bob, 10, and 4 and match the output below. 1 largest = None 2 smallest = None 3 while True: 4 num...

  • # Write PYTHON programs that read a sequence of integer inputs and print # a.  The...

    # Write PYTHON programs that read a sequence of integer inputs and print # a.  The smallest and largest of the inputs. # b.  The number of even and odd inputs. # c.  Cumulative totals. For example, if the input is 1 7 2 9, the program should print # 1 8 10 19. # d.  All adjacent duplicates. For example, if the input is 1 3 3 4 5 5 6 6 6 2, the # program should print...

ADVERTISEMENT
Free Homework Help App
Download From Google Play
Scan Your Homework
to Get Instant Free Answers
Need Online Homework Help?
Ask a Question
Get Answers For Free
Most questions answered within 3 hours.
ADVERTISEMENT
ADVERTISEMENT