Introduction to C

Data Types in C

Operators in C

Hello World Program

Add-Sub-Mul-Div Program

Swapping Program

If Else

Loops in C

While Loop

doWhile Loop

For Loop

Switch statement

Goto statement

Arrays

Single Dimensional Array

Two Dimesnional Arrays

Array Example Programs

Pointers

Functions

Strings

Structures

File Handling

Graphics

Lets understand the logic first for the program and then write it. Its a good practice to think about the logic before to write the program. So, here we have to perform algebraic operations like addition, subtraction, multiplication and division. It is obvious that we need two integers between which you have to perform various operations. Suppose say it as x and y. Now, we need four integers here as the result each for addition, subtraction, multiplication and division. So, now start with the program:

#include<stdio.h> void main() { int x,y; int sum, sub, mul, div; printf("Enter two integer numbers"); scanf("%d",&x,&y); sum = x+y; sub = x-y; mul = x*y; div = int(x/y); printf("Sum of the numbers=%d \n",sum); printf("Subtraction = %d \n",sub); printf("Multiplication of the numbers = %d \n",mul); printf("Division between two numbers = %d \n",div); }

__Explanation for the above program__

For the explanation of program from starting, you need to go to previous program. Here, I am explaining the other parts which is not explained earlier. Lets understand the program through an example. Suppose, two numbers enterd by user are 5 and 2.

Now, x = 5 and y = 2.

sum = x+y; => sum = 5+2 = 7 .

sub = x-y; => sub = 5-2 = 3.

mul = x*y => mul = 5*2 = 10.

div = x/y => div = 5/2 = 2.5

But, we have used div = int(x/y). So, it will take the division result into integer i.e, it will display the result as div = 2 instead of div = 2.5

This process is called type casting. Remember that type casting always occurs in right side as in above example. You can't use it in left side.