Question

C programming question! Write a program that reads two numbers and finds the greater one. The...

C programming question!

Write a program that reads two numbers and finds the greater one. The input is two integers and the output will be a single line “The maximum of ? and ? is ?.”, where ? and ? are the input values and ? is the maximum of ? and ?. If ? and ? are equal, ? will be equal to both of them.

Example of input: 10 20

Corresponding output: The maximum of 10 and 20 is 20.

Example of input: 40 30

Corresponding output: The maximum of 40 and 30 is 40.

0 0
Add a comment Improve this question Transcribed image text
Answer #1
Algorithm:
Step 1: Start
Step 2: Declare variables x,y and z.
Step 3: Read variables x and y.
Step 4: If x != y
           If x > y
              assign z = x
           Else
              assign z  = y
        Else
           Both are equal  
Step 5: Stop

Program:
#include<stdio.h>

int main()

{

int x, y, z;

printf("Enter Value for X : ");

scanf("%d", &x);

printf("Enter Value for Y : ");

scanf("%d", &y);

if (x != y) {

if (x > y) {

z = x;

}

else {

z = y;

}

printf("The maximum of %d and %d is %d", x, y, z);

}

else {

z = x;

printf("%d will be equal to both numbers", z);

}

}

Add a comment
Answer #2

You can achieve this in C by writing a simple program that takes two integer inputs, compares them, and then outputs the maximum value. Here's a C program that does that:

cCopy code#include <stdio.h>int main() {    int num1, num2, max;    // Input two integers
    printf("Enter two integers: ");    scanf("%d %d", &num1, &num2);    // Compare the numbers to find the maximum
    if (num1 >= num2) {
        max = num1;
    } else {
        max = num2;
    }    // Output the result
    printf("The maximum of %d and %d is %d.\n", num1, num2, max);    return 0;
}

Save the above code in a C source file (e.g., "max_number.c") and compile it using a C compiler (such as GCC) to create an executable. When you run the program and provide two integers as input, it will display the maximum of the two numbers as specified in the output format.


answered by: Mayre Yıldırım
Add a comment
Know the answer?
Add Answer to:
C programming question! Write a program that reads two numbers and finds the greater one. The...
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
  • using C programming Date Write a program that reads a month and a day in that...

    using C programming Date Write a program that reads a month and a day in that month and prints the date in format "month day". The input is two integers, one between 1 and 12 (inclusive) and one between 1 and 31 (inclusive) and the output is a single line in format "month day". For example, for input 2 10 the program will print "February 10th". The day will always have the ordinal indicator, e.g. 1st, 2nd, 3rd, 4th. Example...

  • C programming! Write a program that reads integers until 0 and prints the sum of values...

    C programming! Write a program that reads integers until 0 and prints the sum of values on odd positions minus the sum of values on even positions. Let ?1, ?2, … , ??, 0 be the input sequence. Then the program prints the value of ?1 − ?2 + ?3 − ?4 + ⋯ ??. The input is a sequence of integers that always contains at least 0 and the output will be a single number. For example, for input...

  • USING PYTHON: Write a program that reads an unspecified number of integers and finds the ones...

    USING PYTHON: Write a program that reads an unspecified number of integers and finds the ones that have the most occurrences. For example, if you enter 2 3 40 3 5 4 –3 3 3 2 0, the number 3 occurs most often. Enter all numbers in one line. If not one but several numbers have the most occurrences, all of them should be reported. For example, since 9 and 3 appear twice in the list 9 30 3 9...

  • write in c programming Write a C program that reads in up to 10 numbers into...

    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:

  • Programming language is C++. 9. Write a program that reads digits and composes them into integers....

    Programming language is C++. 9. Write a program that reads digits and composes them into integers. For example, 123 is read as the characters 1, 2, and 3. The program should output 123 is 1 hundred and 2 tens and 3 ones. The number should be output as an int value Handle numbers with one, two, three, or four digits. Hint: To get the integer value 5 from the character '5' subtract '0' that is, '5'-'0'

  • C programming help! Write a program that reads the electricity consumption (in kWh) and computes the...

    C programming help! Write a program that reads the electricity consumption (in kWh) and computes the electricity bill based on the following information: • The first 50 kWh costs 8.5 cents/kWh • Next 100 kWh costs 9.5 cents/kWh • Next 100 kWh costs 9.8 cents/kWh • The consumption above 250 kWh costs 10.25 cents/kWh Additional surcharge 20% is added to the bill. The input of the program is one integer and the output will be “The total bill is $?.”,...

  • In C++ Please work on the following short programming assignments and upload your solutions on a...

    In C++ Please work on the following short programming assignments and upload your solutions on a single .txt file. 1. Write a function to take two integers and return the maximum number. Then, in the main function, ask the user to enter 2 numbers and output the maximum using the function. 2. Write a program to input 5 integers and store them in an array. Then, show the array in the output. 3. Write a program to input 5 numbers...

  • Write a C program that reads a sequence of numbers and display a message 1. The...

    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...

  • In C++: Write a program that reads a list of integers, and outputs the two smallest...

    In C++: Write a program that reads a list of integers, and outputs the two smallest integers in the list, in ascending order. The list is preceded by an integer indicating how many numbers are in the list. If the input is: 5 10 5 3 21 2, the output is: 2 3 To achieve the above, first read the integers into a vector.

  • C++ Programming question Problem: 5. Write a program that reads in a list of integers into...

    C++ Programming question Problem: 5. Write a program that reads in a list of integers into an array with base type int. Provide the facility to either read this array from the keyboard or from a file, at the user's option. If the user chooses file input, the program should request a file name. You may assume that there are fewer than 50 entries in the array. Your program determines how many entries there are. The output is to be...

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
ADVERTISEMENT