1answer.
Ask question
Login Signup
Ask question
All categories
  • English
  • Mathematics
  • Social Studies
  • Business
  • History
  • Health
  • Geography
  • Biology
  • Physics
  • Chemistry
  • Computers and Technology
  • Arts
  • World Languages
  • Spanish
  • French
  • German
  • Advanced Placement (AP)
  • SAT
  • Medicine
  • Law
  • Engineering
GuDViN [60]
3 years ago
7

Write a C program to prform simple C aritlimetic calculations. The user is to enter a simple expression(integer operaior integer

) such as 15+30=45. The program is to exlract the 2 operands and the operator, perform the indicated calculation and display the result. For examole15 + 30 = 45. Operators should includc t, -, * , l, and %'.Operands are prcsitive integers, no sign. Use getchar to input the cxpression. Allow for variable spacing before the first operand and between operators and operands.

Computers and Technology
1 answer:
larisa86 [58]3 years ago
4 0

Answer:

Here is the C program:

#include <stdio.h>  //to use input output functions

//functions prototype

unsigned int mod(unsigned int a, unsigned int b);  

unsigned int mul(unsigned int a, unsigned int b);  

unsigned int sub( unsigned int a,unsigned int b);

float divide(unsigned int a,unsigned int b);  

unsigned int add( unsigned int a,unsigned int b);  

int main()  {  //start of main method

unsigned int a, b;   //declare variables to store the operands

char d;  //declare variable to store the operator

printf("Enter an operator:  ");   //prompts user to enter an operator

scanf("%c",&d);  //reads the operator from use

getchar();  //gets a character

while (d!='q')   { //keeps iterating until user enters q to quit

printf("Enter 1st operand: ");   //prompts user to enter first operand

scanf("%d",&a);   //reads first operand from user

getchar();  //reads character

printf("Enter 2nd operand: ");   //prompts user to enter second operand

scanf("%d",&b);   //reads second operand from user

getchar();  

if (d=='%')  {   //if the character of operator is a mod

printf("%d",a);  //prints operand 1

putchar(d);  //displays operator

printf("%d",b);  //displays operand 2

printf(" = ");  //displays =

mod(a,b);  }  //displays computed modulo of two input operands

if (d=='*')   //if the input character is for multiplication operator

{printf("%d",a);  //prints operand 1

putchar(d);  //displays operator

printf("%d",b);  //displays operand 2

printf(" = ");  //displays =

mul(a,b); }  //displays computed multiplication

if (d=='+')  {  //if the input character is for addition operator

printf("%d",a);  //prints operand 1

putchar(d);  //displays operator

printf("%d",b);  //displays operand 2

printf(" = "); // displays =

add(a,b);  }   //displays computed addition

if (d=='/')  {  //if the input character is for division operator

printf("%d",a); // prints operand 1

putchar(d);  //displays operator

printf("%d",b);  //displays operand 2

printf(" = ");  //displays =

divide(a,b);  }   //displays computed division

if (d=='-')  {  //if the input character is for subtraction operator

printf("%d",a);  //prints operand 1

putchar(d);  //displays operator

printf("%d",b); // displays operand 2

printf(" = ");  //displays =

sub(a,b);  }  //displays computed subtraction

printf("Enter an operator: ");   //asks again to enter an operator

scanf("%c",&d);  //reads operator from user

getchar();  }  }   //gets character

unsigned int mod( unsigned int a, unsigned int b){  //function to compute modulo of two integers with no sign

     int c = a%b;  //computes mod

    printf("%d",c);  }  //displays mod result

unsigned int add(unsigned int a, unsigned int b){     // function to compute addition of two integers

    int c = a+b; //computes addition

    printf("%d\n",c);  } //displays result of addition

unsigned int mul(unsigned int a, unsigned int b){       //function to compute multiplication of two integers

    int c = a*b;  //multiplies two integers

   printf("%d\n",c); }  //displays result of multiplication

float divide(unsigned int a, unsigned int b){   //function to compute division of two integers

    float c = a/b;  //divides two integers and stores result in floating point variable c

    printf("%f\n",c);  } //displays result of division

unsigned int sub(unsigned int a, unsigned int b){       //function to compute subtraction of two integers

    int c = a-b;  //subtracts two integers

    printf("%d\n",c);  }  //displays result of subtraction

Explanation:

The program is well explained in the comments mentioned with each line of the program. The program uses while loop that keeps asking user to select an operator and two operands to perform arithmetic calculations. The if conditions are used to check what arithmetic calculation is to be performed based on user choice of operand and calls the relevant function to perform calculation. There are five functions that perform addition, modulo, subtraction, division and multiplication and display the result of computation. The screenshot of output is attached.

You might be interested in
Which object waits for and responds toan event from a GUI component?
irakobra [83]

Answer:

The answer is action eventlistener

Explanation:

It is an event handler and it is easy to implement.In java we call them even listeners it is function or a sub routine or a procedure that waits for an event to occur and respond to an event from a GUI component.

8 0
3 years ago
Fifty part-time students were asked how many courses they were taking this term. The (incomplete) results are shown below. Need
Ne4ueva [31]

Answer:

The answer for B is 10% and for C is 40%.

Explanation:

To get the percentage for B you take the the frequecy of students taking 2 courses (5) and multiply it by 100 then you divide it by whole number of students.

For C you do the after adding the number of students taking 1 or 2 courses (20).

5 0
3 years ago
What did basic elements of music look like in the Twentieth Century period?
Alexandra [31]

Answer:

I just want my 5 point lol sorry hope you get your answer

Explanation:

get terraria

5 0
3 years ago
Which of the following is the term for software that automatically displays or downloads unwanted offers?
slega [8]
Adware. Adware displays ads and popups. The other options are completely different from each other
5 0
3 years ago
AFLAC, Inc. recently implemented a company policy that all new IT projects must be coordinated and approved by the project manag
Shkiper50 [21]

Answer:

Option (E) is the correct answer to the following question.

Explanation:

Because it helps AFLAC Inc. company to run their project in a more easier way and it also helps its employees to work fast on their new IT projects by installing a WiFi network in their ALFAC inc. branch office. So, that's why they have to install a wireless network.

And the other option is not applied because these activities have to be done in all projects if the project is important either not.

8 0
3 years ago
Other questions:
  • Your desktop computer monitor is not displaying a picture. What would you do to troubleshoot the problem?
    7·2 answers
  • Describe mobile computing
    7·1 answer
  • Which option marks all modification made within a document? Review Comment Track Changes Balloons
    15·2 answers
  • Type two statements that use rand() to print 2 random integers between (and including) 100 and 149. End with a newline.
    15·1 answer
  • Convert hexadecimal number 1AF2 to a decimal number.
    7·1 answer
  • An acronym is a word formed by taking the first letters of the words in a phrase and making a word from them. For example, AGH i
    10·1 answer
  • Write a program that allows the user to enter a time in seconds and then outputs how far an object would drop if it is in free f
    7·1 answer
  • Write a nested loop to set values as follows: [0] [1] [2] [3] [4] [0] 1 2 3 4 5 [1] 1 2 3 4 5 [2] 1 2 3 4 5 [3] 1 2 3 4 5
    12·1 answer
  • Which sentence describe internet safety precautions?
    5·1 answer
  • A(n) ______is like an intranet except it shares its resources with users from a distant location. Select your answer, then click
    10·1 answer
Add answer
Login
Not registered? Fast signup
Signup
Login Signup
Ask question!