In this Blog We are going through the following:
In this blog, I'm using C language to write a program.
I choose C language because it is very effective and closer to computer memeory.
This computer langauge help me to solve simple and critical problems in an easy way.That's why is used this language as my first programming Language. So let's go to the problam and solve it.🥰
About Problem
This problem is about to take 2 numbers from the user (number will be any type. i.e integer, floating point ).To use that numbers perform an operation that is decide by the user. The operation is Arithmetic Operation.The operator is checked before it perofm on the data using switch statement.
Arithmatic Operators
There are total five Arithmatic Operators. In this operation, we can perform some methimatical operation on the data give by the user
- Addition +
- Substraction -
- Division /
- Multiplication *
- Modulas %
Switch Statement
It is the type of selection statement, that is used when there are many choices and only one should be executed.It takes only inteager and character data type value.
It execute one case if that case is match with the use input.
We will talk about their details in other blog, for now lets move to the solution.
Solution and Explanation
I divided this problem into Three Steps.
- Declaration
- Input from the user
- Apply Swicth Statement
I write this progrm in C language, you can write in any language in which you find Structure like Switch Statement.
Declaration Process
First of all, I declare two variables in which the value of user will store.The name of valraible could be any thats upon your thinking.I give inetger (int) data type to both variables.
I asign them name is num1 and num2 and the data type is int.
Then to store arithmatic operator enterd by the user, I used Character Data Type (char) for it.
Declaration process is completed.😍 WOW.
Declared Three Variables. |
Input from the user
For input from the user, I use two funtions.
- printf
- scanf
Printf is used to tell the user to enter correct input
scanf is used to take the value from the user.
I write this input code in the following way.
Input three values |
Note:In this situation, if no case is match with the given cases, then the default case is executed automaticaly.It is optional in the program.
default:
printf("Invalid Input, Try Again");
Thanks a lot for your pricious time. ❤❤
Code to copy Link:[ Directory Link click one me]
0 Comments