Question

C Program: Trap divide by zero. Write a main (include libraries as always) that asks the...

C Program: Trap divide by zero. Write a main (include libraries as always) that asks the user to enter two numbers(up to 100 times). For each pair of numbers divide the first number by the second and print the result. Set up and use the signal handler to trap the divide by zero, give the user a pleasant greeting before exiting. Test with no zeroes before forcing the error by entering zero for the second number

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

`Hey,

Note: Brother in case of any queries, just comment in box I would be very happy to assist all your queries

#include <stdio.h>


int main()
{
int count=0;
char ch='y';
while(ch=='y'||ch=='Y')
{
count++;
int num1,num2;
printf("Enter first number: ");
scanf("%d",&num1);
printf("Enter second number: ");
scanf("%d",&num2);
if(num2==0)
{
printf("Error! Second number is 0\n");
}
else
{
printf("Division result is %f\n",(double)num1/(double)num2);
}
if(count==100)
break;
printf("Do you want to test again (y/n)?: ");
scanf(" %c",&ch);
}
printf("Thank you for using the program\n");
return 0;
}

​​​​​​​

Kindly revert for any queries

Thanks.

Add a comment
Know the answer?
Add Answer to:
C Program: Trap divide by zero. Write a main (include libraries as always) that asks 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
  • Write an assembler program that asks the user (as shown below) for two integers and a...

    Write an assembler program that asks the user (as shown below) for two integers and a single character representing the arithmetic operations: addition, subtraction, multiplication and integer division (displays both quotient and remainder). Perform the requested operation on the operands and display the result as specified below. Assume SIGNED NUMBERS. The program should not divide by 0! If the user attempts to divide by 0, display the error message: "Cannot divide by zero." If this error occurs, the program should...

  • Q2- Write a C program that work as a calculator for the 4 main operations (...

    Q2- Write a C program that work as a calculator for the 4 main operations ( + * / - ), an error message should be displayed when the user attempts to divide by zero. The user input should be in this form: Number operation number, ex: 2-3‏

  • 12.5 Program: Divide by Zero (C++) This program will test exception handling during division. The user...

    12.5 Program: Divide by Zero (C++) This program will test exception handling during division. The user will enter 2 numbers and attempt to divide (in a try block) the 1st number by the 2nd number. The program will provide for 2 different catch statements: Division by zero - denominator is zero Division results in a negative number The user should be prompted with Enter 2 numbers: For input of 7 and 0 the output should be Exception: Division by zero...

  • Write a C program that asks the user to enter three numbers (integres). A menu will...

    Write a C program that asks the user to enter three numbers (integres). A menu will be displayed to let the user choose one of the three options: print the two highest numbers, product of the three numbers or the division of the second by the by the third if the third is not zero. See the sample runs. Required: Your code must use -One function to get the numbers from the user One function for each of the three...

  • Write a program that asks the user for a lower limit and an upper limit. The...

    Write a program that asks the user for a lower limit and an upper limit. The program finds all pairs of amicable numbers where the first number of the pair is between those limits. The second number of the pair may or may not be between the limits. To do this sensibly, write a function int sumDivisors( int num ); that returns the sum of all the proper divisors of num. The main program looks at each integer N between...

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

  • Wrote a program called ExceptionalDivide that asks the user for 2 integer values and displays the...

    Wrote a program called ExceptionalDivide that asks the user for 2 integer values and displays the quotient of the first value divided by the second value. Make sure the your program reads in the two input values as ints. Your program must catch either of two exceptions that might arise and crash your program java.util.InputMismatchException //wrong data type inputted java.lang.ArithmeticException //divide by zero error Once you catch these exceptions, your program must print out a message explaining what happened and...

  • (C programing, Not C++) Write a program in C that asks the user to input 10...

    (C programing, Not C++) Write a program in C that asks the user to input 10 numbers. Store these numbers in an array. Then ask the user to input a single number. Your program should execute a linear search on the array, trying to find that number. If the number exists in the array, have the program print out which position/element the number was found at. If the target number is not in the array, have the program print out...

  • C# Programming: A.    Write a GUI program named MultiplicationGUI whose Main() method asks the user to...

    C# Programming: A.    Write a GUI program named MultiplicationGUI whose Main() method asks the user to input an integer into a TextBox and then calls a method named MultiplicationTable() after the user clicks a Button. MultiplicationTable() displays the results of multiplying the integer by each of the numbers 2 through 10.

  • C++ Write a program that asks for a number and then prints as many lines as...

    C++ Write a program that asks for a number and then prints as many lines as the user inputs. Each line contains as many pairs of characters ("*#") as the number of this line. It should look like the right half of a pyramid. Your version of the program must print the same result as the expected output. To to this lab, you must use two do-while loops. Two exceptions: When the user inputs a number less than 1, then...

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