Question

In: Computer Science

Write a program that reads in a single integer. Display a message depending on what is...

Write a program that reads in a single integer.

Display a message depending on what is given:

  • When the number is 42, output "42 is the Ultimate Question of Life, the Universe, and Everything."
  • When the number is 2020 output "2020 is the current year."
  • When the number is greater than 1000 and less than 3000 output "1500 could be a year." where 1500 is the number the user originally inputted
  • When none of the above, output "no idea."

One example shown below with the user input highlighted:

Give a number: 2020
2020 is the current year.
-- Font family -- -- Font size --

Solutions

Expert Solution

C CODE:

#include <stdio.h>

int main() {
    int num;
    printf("Give a number: ");
    scanf("%d", &num);
    
    if(num == 42)
      printf("%d is the Ultimate Question of Life, the Universe, and Everything.", num);
      
    else if(num == 2020)
      printf("%d is the current year.", num);
      
    else if(num> 1000 && num<3000)
      printf("%d could be a year.", num);
      
    else 
      printf("no idea.");
    return 0;
}

Screenshots:


Related Solutions

Write FORTRAN 90 statements that will display an appropriate message if an integer variable test is...
Write FORTRAN 90 statements that will display an appropriate message if an integer variable test is divisible by 2,3, and or 10 using if statements.
Write a program that reads an integer, a list of words, and a character.
13.14 LAB: Contains the characterWrite a program that reads an integer, a list of words, and a character. The integer signifies how many words are in the list. The output of the program is every word in the list that contains the character at least once. Assume at least one word in the list will contain the given character.Ex: If the input is:4 hello zoo sleep drizzle zthen the output is:zoo drizzleIn c++ 
How to write a java application that reads an integer, then determines and display whether it's...
How to write a java application that reads an integer, then determines and display whether it's odd or even. Use the remainder operator.
In c++ Write a program that reads a string consisting of a positive integer or a...
In c++ Write a program that reads a string consisting of a positive integer or a positive decimal number and converts the number to the numeric format. If the string consists of a decimal number, the program must use a stack to convert the decimal number to the numeric format. Use the STL stack
In c++, write a program that reads a string consisting of a positive integer or a...
In c++, write a program that reads a string consisting of a positive integer or a positive decimal number and converts the number to the numeric format. If the string consists of a decimal number, the program must use a stack to convert the decimal number to the numeric format.
Q1: Write a Java program that will display different messages depending on your age. Your program...
Q1: Write a Java program that will display different messages depending on your age. Your program should ask the user for his/her name and their age in years and give one or more answers from the following ones below: if the age of the user is less than 16, the program should print on the screen “You are not allowed to drive at the moment”. if the age of the user is less than 18, the program should print on...
Q1: Write a Java program that will display different messages depending on your age. Your program...
Q1: Write a Java program that will display different messages depending on your age. Your program should ask the user for his/her name and their age in years and give one or more answers from the following ones below: if the age of the user is less than 16, the program should print on the screen “You are not allowed to drive at the moment”. if the age of the user is less than 18, the program should print on...
Write a Java program that will display different messages depending on your age. Your program should...
Write a Java program that will display different messages depending on your age. Your program should ask the user for his/her name and their age in years and give one or more answers from the following ones below: if the age of the user is less than 16, the program should print on the screen “You are not allowed to drive at the moment”. if the age of the user is less than 18, the program should print on the...
Lab 5 a) Write a program that reads in an unsigned integer K and sums the...
Lab 5 a) Write a program that reads in an unsigned integer K and sums the first K many integers that are divisible by 7. You should output the sum on a formatted manner b)Consider the following diamond it is an 11 by 11 diamond made with * signs. Write a program that takes as input positive odd integer K (greater than or equal to three and outputs a K by K diamond made with * signs * *** *...
The Sum and The Average In C++, Write a program that reads in 10 integer numbers....
The Sum and The Average In C++, Write a program that reads in 10 integer numbers. Your program should do the following things: Use a Do statement Determine the number positive or negative Count the numbers of positive numbers, and negative Outputs the sum of: all the numbers greater than zero all the numbers less than zero (which will be a negative number or zero) all the numbers Calculate the average of all the numbers. The user enters the ten...
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT