Question

Write a C function named: div() with one local variable: m to prompt the user to...

Write a C function named: div() with one local variable: m to prompt the user to enter one integer for the local variable m. When you call the function, it should display one of the following lines:
If m is divisible by 9 the function displays the message m is divisible by 9
If m is divisible by 3 and not divisible 9 (e.g. 24) the function displays the message m is divisible by 3
If m is neither divisible by 3 nor by 9 the function displays the message m is not divisible by 3 or 9.
Note that in the above three lines, by m, I mean the value of m.

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

#include <stdio.h>
#include<string.h>

void div()
{
int m;
printf("Enter one integer: ");
scanf("%d",&m);
if(m%9==0)
{
printf("%d is divisible by 9.",m);
}
else if(m%3==0 && m%9!=0)
{
printf("%d is divisible by 3.",m);
}
else if(m%3!=0 && m%9!=0)
{
printf("%d is divisible by 3 or 9.",m);
}

}
int main()
{
div();
return 0;
}

Add a comment
Know the answer?
Add Answer to:
Write a C function named: div() with one local variable: m to prompt the user to...
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
  • Create a new MATLAB Script file named MT3P3_itname.m. In your script file perform the following calculations:...

    Create a new MATLAB Script file named MT3P3_itname.m. In your script file perform the following calculations: Prompt the user to enter an integer. Use a multiple if-elseif structure to determine the following: Confirm that the number is an integer. If not, the program displays message 1. Check if the number is divisible by 2 and displays message 2. Check if the number is divisible by 3 and displays message 3. For anything other than 1, 2, or 3, the program...

  • Visual Basic: Write the code for a function named GetMajor. The function should prompt the user...

    Visual Basic: Write the code for a function named GetMajor. The function should prompt the user to enter a major field of study and then return the user’s response. Then write a statement to invoke the GetMajor function, returning the result to the strCurrentMajor variable.

  • use C++            Project 6 1. Using vectors or arrays, write a function named word_rev() that reverse...

    use C++            Project 6 1. Using vectors or arrays, write a function named word_rev() that reverse any given word. 2. Write a program that will: Ask the user to enter a word. Save the entry as word_entered. Call word_rev on the entry Display the reversed entry (word_entered) 3. Write a function named prime() that determine whether or not a given number n (greater than one) is prime. The algorithm: If n is even then n is not a prime number...

  • Y F G Prompt and Store. 5. Prompt the user with "Enter your weight in pounds:...

    Y F G Prompt and Store. 5. Prompt the user with "Enter your weight in pounds: "message and store in the weight variable. 6. Initialize an int variable named heightIn Inches to feet OſHeight times 12 plus Inches OfHeight. 7. Initialize a double variable named BMI to weight * 703.0 heightIrinches El VB 8. Initialize a double variable named ratio to height In Inches? 703.0 9. Initialize a double variable named lower Normal to 18.5 times ratio. 10. Initialize a...

  • c++ please (1) Write a program that prompts the user to enter an integer value N...

    c++ please (1) Write a program that prompts the user to enter an integer value N which will rpresent the parameter to be sent to a function. Use the format below. Then write a function named CubicRoot The function will receive the parameter N and return'its cubic value. In the main program print the message: (30 Points) Enter an integer N: [. ..1 The cubic root of I.. ] is 2 update the code om part and write another function...

  • Q2. To check and print if entered integer is prime or not. Prompt the user to...

    Q2. To check and print if entered integer is prime or not. Prompt the user to enter a positive integer or 0 to exit. while negative integer entered - prompt for valid values again. If positive integer entered - check if it is prime. Write a separate function that accepts a positive integer as argument and checks and returns 1 if the integer is prime or 0 if it is not prime. Call the function from main. Accept the return...

  • In this program, you will be using C++ programming constructs, such as overloaded functions. Write a...

    In this program, you will be using C++ programming constructs, such as overloaded functions. Write a program that requests 3 integers from the user and displays the largest one entered. Your program will then request 3 characters from the user and display the largest character entered. If the user enters a non-alphabetic character, your program will display an error message. You must fill in the body of main() to prompt the user for input, and call the overloaded function showBiggest()...

  • Summary: Write a C program that prompts the user to enter 2 positive integer numbers, display...

    Summary: Write a C program that prompts the user to enter 2 positive integer numbers, display the numbers in 3 formats. Then check, whether the larger of the 2 is evenly divisible by the smaller. Detail: Write a complete C program, more complex than the typical "hello world" program. Prompt the user to enter 2 integer numbers that are not negative. After either entry, display that number again. Print the smaller in hexadecimal, in decimal, and in octal format. Include...

  • Write a Python program to prompt the user for an integer number. Assign this integer to...

    Write a Python program to prompt the user for an integer number. Assign this integer to a variable X. Then assign a variable Y to the X**3 (X to the power 3). Finally, assign the variable Z to the square root of Y and print the values of X, Y, and Z as shown in the example below. Use main() function to define and call the program. Example: Enter an integer number: 3 X = 3 if Y=X**3 then Y...

  • extra credit 1 Write a program that will display the following menu and prompt the user...

    extra credit 1 Write a program that will display the following menu and prompt the user for a selection: A) Add two numbers B) Subtract two numbers C) Multiply two numbers D) Divide two numbers X) Exit program The program should: display a hello message before presenting the menu accept both lower-case and upper-case selections for each of the menu choices display an error message if an invalid selection was entered (e.g. user enters E) prompt user for two numbers...

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