C Programming

How to Make A Calculations Application in C Using Functions

Top 5 programming language in 2020
Written by Arpit

Hello Learners , Today We will See how we can make a small calculation application in c using User Defined Functions .

First of all Create an Empty File in Ubuntu or any of your OS. in My case i am using Ubuntu

Just tuple the below code in your C file

//Working with Functions and Making a Simple Calculations Application

#include<stdio.h>

int Addnumber(int a , int b); //funtion Prototype
int Subtractnumber(int a , int b); //funtion Prototype
int Multiplynumber(int a , int b); //funtion Prototype
int Dividenumber(int a , int b); //funtion Prototype

int Addnumber(int a , int b) //Function Defination
{
int Sum = a+b;
return Sum;
}
int Subtractnumber(int a , int b)//Function Defination
{
int Subtract = a-b;
return Subtract;
}
int Multiplynumber(int a , int b) //Function Defination
{
int Multiply = a*b;
return Multiply;
}
int Dividenumber(int a , int b) //Function Defination
{
int Division = a/b;
return Division;
}

void main() // Main Method
{
int a , b , c ; //declare variables

printf(“Enter your First Number : “);
scanf(“%d”,&a);
printf(“Enter your Second Number : “);
scanf(“%d”,&b);

printf(“for Addition press 1 \n”);
printf(“for Subtraction press 2 \n”);
printf(“for Multiplication press 3 \n”);
printf(“for Division press 4 \n”);

scanf(“%d”,&c);

if(c==1)
{
printf(“You Choose Addition \n”);
int result = Addnumber(a,b);
printf(“Addition result : %d\n”,result);
}
else if(c==2)
{
printf(“You Choose Subtraction \n”);
int result = Subtractnumber(a,b);
printf(“Subtraction result : %d\n”,result);
}
else if(c==3)
{
printf(“You Choose Mulriplications \n”);
int result = Multiplynumber(a,b);
printf(“Multiplication result : %d\n”,result);
}
else if(c==4)
{
printf(“You Choose Division \n”);
int result = Dividenumber(a,b);
printf(“Division result : %d\n”,result);
}
else
{
printf(“Your Choice is Invalid \n”);
main();
}

}

it is Very easy and simple to Understand

Do comments down if you face any Problem.

Happy Coding , Keep Coding .

About the author

Arpit

2 Comments

Leave a Comment