0% found this document useful (0 votes)
11 views5 pages

Assignment3

The document describes a Simple Calculator application written in C that performs basic arithmetic operations including addition, subtraction, multiplication, division, logarithmic calculations, and square roots. It includes a main function that presents a menu for user selection and calls the respective functions based on the user's choice. Error handling is implemented for invalid inputs, division by zero, and logarithm and square root calculations for inappropriate values.

Uploaded by

abhinavrao666
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
11 views5 pages

Assignment3

The document describes a Simple Calculator application written in C that performs basic arithmetic operations including addition, subtraction, multiplication, division, logarithmic calculations, and square roots. It includes a main function that presents a menu for user selection and calls the respective functions based on the user's choice. Error handling is implemented for invalid inputs, division by zero, and logarithm and square root calculations for inappropriate values.

Uploaded by

abhinavrao666
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 5

ASSIGNMENT 3

Simple Calculator is a C language-based application used for


performing all the simple arithmetic operations like addition,
multiplication, division, and subtraction. The application can be
made using basic knowledge of C like if-else statements, loops,
etc.
The functionalities of the application are mentioned below:
1. Addition
2. Subtraction
3. Multiplication
4. Division
5. Logarithmic values
6. Square roots

Solution:

#include <stdio.h>

#include <math.h>

void addition();

void subtraction();

void multiplication();

void division();

void logarithm();

void squareRoot();

int main() {

int choice;

do {

printf("\nSelect an operation:\n");

printf("1. Addition\n");

printf("2. Subtraction\n");

printf("3. Multiplication\n");

printf("4. Division\n");
printf("5. Logarithmic values\n");

printf("6. Square roots\n");

printf("7. Exit\n");

printf("Enter your choice (1-7): ");

scanf("%d", &choice);

switch (choice) {

case 1:

addition();

break;

case 2:

subtraction();

break;

case 3:

multiplication();

break;

case 4:

division();

break;

case 5:

logarithm();

break;

case 6:

squareRoot();

break;

case 7:

printf("Exiting the program.\n");

break;

default:
printf("Invalid choice!Please enter a number IN RANGE 1-7.\n");

} while (choice != 7);

return 0;

void addition() {

double a, b;

printf("Enter two numbers: ");

scanf("%f %f", &a, &b);

printf("Result: %f\n", a + b);

void subtraction() {

double a, b;

printf("Enter two numbers: ");

scanf("%f %f", &a, &b);

printf("Result: %f\n", a - b);

void multiplication() {

double a, b;

printf("Enter two numbers: ");

scanf("%f %f", &a, &b);

printf("Result: %.2lf\n", a * b);

void division() {

double a, b;

printf("Enter two numbers: ");


scanf("%f %f", &a, &b);

if (b != 0) {

printf("Result: %f\n", a / b);

} else {

printf("Error: Division by zero is not allowed.\n");

void logarithm() {

double a;

printf("Enter a positive number: ");

scanf("%f", &a);

if (a > 0) {

printf("Logarithm (base e): %f\n", log(a)); // Natural logarithm

printf("Logarithm (base 10): %f\n", log10(a));

} else {

printf("Error: Logarithm is defined for positive numbers only.\n");

void squareRoot() {

double a;

printf("Enter a non-negative number: ");

scanf("%f", &a);

if (a >= 0) {

printf("Square root: %f\n", sqrt(a));

} else {

printf("Error: Square root is not defined for negative numbers.\n");

}
}

You might also like