0% found this document useful (0 votes)
9 views

Caculator in C Language in Linux

This C program allows a user to enter two numbers and a mathematical operator, and then calculates and displays the result. It defines functions for addition, subtraction, multiplication, and division, and uses conditionals to call the appropriate function based on the operator entered. The main function gets input from the user, calls the corresponding calculation function, and prints the result.

Uploaded by

uflilla
Copyright
© Attribution Non-Commercial (BY-NC)
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
9 views

Caculator in C Language in Linux

This C program allows a user to enter two numbers and a mathematical operator, and then calculates and displays the result. It defines functions for addition, subtraction, multiplication, and division, and uses conditionals to call the appropriate function based on the operator entered. The main function gets input from the user, calls the corresponding calculation function, and prints the result.

Uploaded by

uflilla
Copyright
© Attribution Non-Commercial (BY-NC)
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 2

File: /home/umar/OS/lab.

c
/* Program to calculate the product of two numbers. */ #include <stdio.h> float val1, val2, val3; char c; float float float float product(float x, float y); division(float x, float y); addition(float x, float y); subtraction(float x, float y);

Page 1 of 2

int main(void) { /* Get the first number */ printf("Please enter the first number: "); scanf("%f", &val1); /* Get the second number */ printf("Please enter the second number: "); scanf("%f", &val2); scanf("%c",&c); printf("Enter operator: "); scanf("%c",&c); if (c=='*'){ /* Calculate and display the product */ val3 = product(val1, val2); printf ("%f * %f = %f\n", val1, val2, val3); } else if (c=='/'){ /* Calculate and display the product */ val3 = division(val1, val2); printf ("%f / %f = %f\n", val1, val2, val3); } else if (c=='+'){ /* Calculate and display the product */ val3 = addition(val1, val2); printf ("%f + %f = %f\n", val1, val2, val3); } else if (c=='-'){ /* Calculate and display the product */ val3 = subtraction(val1, val2); printf ("%f - %f = %f\n", val1, val2, val3); } else printf("invalid operator \n"); return 0; } /* Function returns the product of the two values provided */ float product(float x, float y) { return (x * y); } float division(float x, float y) { return (x / y); } float subtraction(float x, float y) { return (x - y);

File: /home/umar/OS/lab.c
} float addition(float x, float y) { return (x + y); }

Page 2 of 2

You might also like