Question

C language: P14. Ask a user for three positive integer numbers. Use an input valiadation loop...

C language: P14. Ask a user for three positive integer numbers. Use an input valiadation loop to make sure that all numbers are positive, ask again if not. Determine the smallest, middle and largest number and display them with proper labeling (Smallest=AA, Middle=BB, Largest=CC).

0 0
Add a comment Improve this question Transcribed image text
Answer #1
#include <stdio.h>

int isPrime(int num)
{
   int i;
   if (num <= 1) return 0;
   if (num % 2 == 0 && num > 2) return 0;
   for (i = 3; i <= sqrt(num); i += 2)
   {
      if (num % i == 0)
         return 0;
   }
   return 1;
}


int main() { 
   int a,b,c,Smallest,Middle,Largest;
   do{
      printf("Enter value for a: ");
      scanf("%d",&a);
   }while(a<=0);
   
   do{
      printf("Enter value for b: ");
      scanf("%d",&b);
   }while(b<=0);
   
   do{
      printf("Enter value for c: ");
      scanf("%d",&c);
   }while(c<=0);
   
   if(a<b && a<c){
      Smallest = a;
      if(b<c){
         Middle = b;
         Largest = c;
      }
      else{
         Middle = c;
         Largest = b;
      }
   }
   else if(b<c){
      Smallest = b;
      if(a<c){
         Middle = a;
         Largest = c;
      }
      else{
         Middle = a;
         Largest = b;
      }
   }
   else{
      Smallest = c;
      if(b<a){
         Middle = b;
         Largest = a;
      }
      else{
         Middle = a;
         Largest = b;
      }
   }
   
   printf("Smallest=%d, Middle=%d, Largest=%d",Smallest,Middle,Largest);
   return 0;
}

Add a comment
Know the answer?
Add Answer to:
C language: P14. Ask a user for three positive integer numbers. Use an input valiadation loop...
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
  • Ask a user for three positive integer numbers. Use an input validation loop to make sure...

    Ask a user for three positive integer numbers. Use an input validation loop to make sure that all numbers are positive, ask again if not. Determine the smallest, middle and largest number and display them with proper labeling (Smallest=AA, Middle=BB, Largest=CC). Write this program in C

  • In java language: Ask for keyboard input of a decimal number. Use a loop to keep...

    In java language: Ask for keyboard input of a decimal number. Use a loop to keep asking for input of up to ten numbers. Exit the loop if ten numbers are entered or if a sentinel value for “QUIT” is entered. Store the numbers in an array. Sort the array according to ascending number. Get the average for all the numbers in the array. Print out the average. Calculate the distance from the average for each number in the array...

  • In java, write a program that gets 10 integer numbers from the user using user input,...

    In java, write a program that gets 10 integer numbers from the user using user input, and then calculates and display the sum of the numbers that have been read.   Program Requirements: Write the program in three versions with three loops. Put all three loops in the main method of your source code. version1:  use a while loop. version2:  use a do-while loop. version 3:  use a for loop. For each version, use a loop to input 10 int numbers from the user...

  • In java, write a program that gets 10 integer numbers from the user using user input,...

    In java, write a program that gets 10 integer numbers from the user using user input, and then calculates and display the sum of the numbers that have been read.   Program Requirements: Write the program in three versions with three loops. Put all three loops in the main method of your source code. The program must be in one file. version1:  use a while loop. version2:  use a do-while loop. version 3:  use a for loop. For each version, use a loop to...

  • In MATLAB, ask the user to input a matrix of any size. Ensure that the user...

    In MATLAB, ask the user to input a matrix of any size. Ensure that the user inputs a positive, integer matrix. If there is an incorrect input, ask them for a matrix again. Use Loops to do this. Using loops, find the sum of all prime numbers present in the user-entered matrix. You must not use the built-in isprime function to do this. Use loops. (The number 1 may count as as a prime number) Example Matrix: [1 2 3;...

  •    use C++ language Output the prime numbers between 1 and 1000 Ask the user for...

       use C++ language Output the prime numbers between 1 and 1000 Ask the user for a color. If they choose "red", use a while loop to output "red" 5 times. If they choose "green", output "green" seven times with a for loop. If they choose anything else, tell them to choose a better color. Create a random number between 1 and 6

  • First, ask the user for a positive integer called “length”. If the user does not provide...

    First, ask the user for a positive integer called “length”. If the user does not provide an integer, or if the integer is not positive, then ask again, by asking inside a while loop. The acceptable integer is intended to indicate the user’s desired twist length. A twist is always three lines long, and made of slash characters and X characters. For example, if length is 25, then your code should print out this: Simple output: IXI XI XI XI...

  • C++ Write a program that asks user to input three positive integers one at a time,...

    C++ Write a program that asks user to input three positive integers one at a time, then compute and output the largest entered number. Use if-else statements for three integer comparison and use for loops for a user validation. Example output: Enter an integer: -7 Invalid! Number must be positive. Enter an integer: -2 Invalid! Number must be positive. Enter an integer: 5 Enter an integer: 7 Enter an integer: 1 Largest number: 7

  • 1. (sumFrom1.cpp) Write a program that will ask the user for a positive integer value. The...

    1. (sumFrom1.cpp) Write a program that will ask the user for a positive integer value. The program should use the for loop to get the sum of all the integers from 1 up to the number entered. For example, if the user enters 50, the loop will find the sum of 1, 2, 3, 4, ... 50. If the user enters a zero or negative number, a message should be given and the program should not continue (see Sample Run...

  • **Using C Language** Get a number from the user and use that number for loops and...

    **Using C Language** Get a number from the user and use that number for loops and to make some calculations. Get a number from the user (n) (For example if the user enters a 3, each loop below will repeat 3 times) //ask, get, and return an integer (by reference) void GetIntPointer(int *numPtr); //input: the number entered by the user (pass by copy) //Calculates the product of the first (n)numbers using a while loop and store the result in *productPtr...

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