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]
4 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]4 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
Write a program using integers user_num and x as input, and output user_num divided by x three times. Ex: If the input is: 2000
TiliK225 [7]

Answer:

user_num = 2000

x = 2

for i in range(3):

 user_num = user_num // x

 print(user_num)

3 0
3 years ago
What device is designed specifically to reduce broadcast traffic that passes over a network and to choose the best path for movi
mezya [45]

Answer:

Router        

Explanation:

  • A router is a network device that forwards data packets between networks. Its a network layer hardware device. For example a DSL router that connects to the Internet through an internet service provider.
  • Router is connects at least 2 networks (can be two LANs) and the ISP.
  • Router is used to transfer data from one network to another if both networks use same protocols.
  • It receives data in packets form and forwards the data to another router using a routing table. These data packets can be sent between devices or from devices to the internet.
  • The routing table is used to choose the optimal path for forwarding the packets between the source and destination hosts. Routing table configure the best route a packet can take to reach its destination using routing protocols. A Routing Protocol defines how routers connect with each other and share information that makes them choose routes on a computer network between source and destination. Routing tables can be configured statically (routes are fed manually) or dynamically (routes are updated based on information obtained  from other routers).
  • Router makes sure that the data packets reach right destination instead of being lost within the network and it also strengthen signals before transmitting them.
  • Routers reduce broadcast traffic. They form boundaries between broadcast domains and separate a network into multiple broadcast domains.
  • Router do not broadcast traffic and eliminates the packet when it detects a broadcast address. Routers also stop broadcast messages and don't route a broadcast message between broadcast domains.
6 0
3 years ago
True or False: A private access modifier is normally used with methods
Veseljchak [2.6K]
I’m pretty sure it’s true! Brainliest if correct
4 0
3 years ago
Read 2 more answers
What is the key function of a Scrum Master?
Reptile [31]

Answer:

The scrum master is the team role responsible for ensuring the team lives agile values and principles and follows the processes and practices that the team agreed they would use. The responsibilities of this role include: Clearing obstacles. Establishing an environment where the team can be effective.

Explanation:

8 0
4 years ago
A strategic business unit​ (SBU) of a major corporation has high market share in its​ industry, but the growth rate of the indus
VLD [36.1K]

Answer:

Cash cow

Explanation:

A cash cow is seen or made reference to as that part of a business, investment, or product that provides a steady income or profit.

Basically a cash cow is a business unit, product line, or investment that has a return on assets (ROA) greater than the market growth rate. This is expressed with an Idiom to mean that it produces "milk" that is profit long after the cost of the investment has been recouped.

The strategic business unit of this organization having high market share in its​ industry, but the growth rate of the industry is expected to be stagnant over the long run is simply yielding steady profit for the corporation through its high market value and this will continue for longer because it has to be at that high rate for a long period of time.

The SBU can be categorised as acting as the cash cow for that corporation.

6 0
4 years ago
Read 2 more answers
Other questions:
  • A database on a mobile device containing bands, sub-bands and service provider IDs allowing the device to establish connection w
    9·1 answer
  • Which of the following enabled mass production in the 1920s? a.standardization of spare parts b.mass availability of electricity
    7·2 answers
  • What are the benefits of using disk cleanup as part of regular maintenance on a computer​
    8·1 answer
  • Give a logical expression with variables p,q, and r that is true if p and q are false and r is true and is otherwise false.
    5·1 answer
  • Your desktop, Internet Explorer®, and the Media Player can be started from this area on most computers.
    10·2 answers
  • Addition and subtraction are considered to be ____ operations performed by a computer.
    7·1 answer
  • Linda is training to become a certified network design expert and consultant. While researching about the process of cellular ra
    12·1 answer
  • The labels on the tab buttons on the Driver tab of the Windows Device are Driver Details, Update Driver, Roll Back Driver, Unins
    12·1 answer
  • Write a Java code statement for each of following:
    6·1 answer
  • When you hear music, read a printout, or view a video, you are using a computer's
    13·1 answer
Add answer
Login
Not registered? Fast signup
Signup
Login Signup
Ask question!