Question

In: Computer Science

Create a basic program (C programming language) that accomplishes the following requirements: Allows the user to...

Create a basic program (C programming language) that accomplishes the following requirements:

  1. Allows the user to input 2 numbers, a starting number x and ending number y
  2. Implements a while loop that counts from x (start) to y(end).
  • Inside the loop, print to the screen the current number
  • Print rather the current number is even or odd
  • If the number is even , multiply by the number by 3 and print the results to the screen.
  • If the number is odd , add 10 and print the results to the screen.
  • Use at least 1 increment or decrement operator.

Solutions

Expert Solution

Program:

#include <stdio.h>

int main()
{
    int x, y;
    printf("Enter 2 numbers:\n");
    // Takes input of starting number from user
    printf("Enter starting number : ");
    scanf("%d",&x);
    // Takes input of ending from user
    printf("Enter ending number : ");
    scanf("%d",&y);
    
    // Loop iterates till the x is less than or equal to y
    while (x <= y) {
        // Printing the current number
        printf("Current number is: %d\n", x);
        // Condition to check if x is even
        if (x%2 == 0) {
            // Printing the current number is even
            printf("The current number is even\n");
            // Multiplying the number with 3 and print the result
            printf("%d\n", x*3);
        } else { // If x is odd
            // Printing the current number is odd
            printf("The current number is odd\n");
            // Adding 10 to the number and print the result
            printf("%d\n", x+10);
        }
        // Incrementing the x value
        x++;
    }
    
    return 0;
}

Output:


Related Solutions

Using (C programming language) Create a health monitoring program, that will ask user for their name,...
Using (C programming language) Create a health monitoring program, that will ask user for their name, age, gender, weight, height and other health related questions like blood pressure and etc. Based on the provided information, program will tell user BMI, blood pressure numbers if they fall in healthy range or not and etc. Suggestions can be made as what should be calorie intake per day and the amount of exercise based on user input data. User should be able to...
C# Programming Language Write a C# program ( Console or GUI ) that prompts the user...
C# Programming Language Write a C# program ( Console or GUI ) that prompts the user to enter the three examinations ( test 1, test 2, and test 3), homework, and final project grades then calculate and display the overall grade along with a message, using the selection structure (if/else). The message is based on the following criteria: “Excellent” if the overall grade is 90 or more. “Good” if the overall grade is between 80 and 90 ( not including...
Create a program in visual basic that allows the user to manage vehicle information including: •...
Create a program in visual basic that allows the user to manage vehicle information including: • License plate number • Owner name • Owner phone number The user interface will be GUI-based providing the following capabilities: • Add up to 100 vehicles • Remove specified vehicles • View a sorted list of all known license plates • View the data for a specified vehicle • Save the database contents into a file • Load a saved database from a file
Fat Percentage Calculator Create a C++ program that allows the user to enter the number of...
Fat Percentage Calculator Create a C++ program that allows the user to enter the number of calories and fat grams in a food. The application should display the percentage of the calories that come from fat. If the calories from fat are less than 30% of the total calories of the food, it should also display a message indicating the food is low in fat. One gram of fat has 9 calories, so: Calories from fat = fat grams *...
Using c# programming language Write a program that mimics a lottery game. Have the user enter...
Using c# programming language Write a program that mimics a lottery game. Have the user enter 3 distinct numbers between 1 and 10 and match them with 3 distinct, randomly generated numbers between 1 and 10. If all the numbers match, then the user will earn $10, if 2 matches are recorded then the user will win $3, else the user will lose $5. Keep tab of the user earnings for, let say 5 rounds. The user will start with...
Using C# programming language, Write a program that sort three numbers entered by the user using...
Using C# programming language, Write a program that sort three numbers entered by the user using only if and nested if statements. If for instance the user entered 5, 2, and 7; the program should display 2,5,7.
C Programming Language: For this lab, you are going to create two programs. The first program...
C Programming Language: For this lab, you are going to create two programs. The first program (named AsciiToBinary) will read data from an ASCII file and save the data to a new file in a binary format. The second program (named BinaryToAscii) will read data from a binary file and save the data to a new file in ASCII format. Specifications: Both programs will obtain the filenames to be read and written from command line parameters. For example: - bash$...
Java Programming: Write a program that allows the user to compute the power of a number...
Java Programming: Write a program that allows the user to compute the power of a number or the product of two numbers. Your program should prompt the user for the following information: • Type of operation to perform • Two numbers (the arguments) for the operation to perform The program then outputs the following information: • The result of the mathematical operation selected. Menu to be displayed for the user: MATH TOOL 1. Compute the power of a number 2....
Create a Python program that: Allows the user to enter a phrase or sentence. The program...
Create a Python program that: Allows the user to enter a phrase or sentence. The program should then take the phrase or sentence entered Separate out the individual words entered Each individual word should then be added to a list After all of the words have been place in a list Sort the contents of the list Display the contents of the sorted list with each individual word displayed on a separate line Display a message to the user indicating...
Assembly Language Programming Construct an assembly language program fragment equivalent to the following C/C++ statement: if...
Assembly Language Programming Construct an assembly language program fragment equivalent to the following C/C++ statement: if (M <= N + 3 && (C == ‘N’ || C == ‘n’)) C = ‘0’; else C = ‘1’; Assume that M and N are 32-bit signed integer variables, and C is an 8-bit ASCII character variable. All variables are stored in memory, and all general-purpose registers are available for use.
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT