Arithmetic Operator in C programming


The Arithmetic operators are some of the C Programming Operator, which are used to perform arithmetic operations includes operators like Addition, Subtraction, Multiplication, Division and Modulus.All these Arithmetic operators in C are binary operators which means they operate on two operands.

ARITHMETIC OPERATORSOPERATIONEXAMPLE
+Addition 10 + 2 = 12
Subtraction 10 – 2 = 8
*Multiplication 10 * 2 = 20
/Division 10 / 2 = 5
%Modulus – It returns the remainder after the division 10 % 2 = 0 (Here remainder is zero). If it is 10 % 3 then it will be 1.

Sample program to demonstrate Arithmetic Operators in C Programming


Source Code

#include<stdio.h>
int main()
{
    int a,b,c;
    float x;
    printf("\nEnter 2 Nos : ");
    scanf("%d%d",&a,&b);
    c=a+b;
    printf("\nTotal : %d",c);
    c=a-b;
    printf("\nDifference : %d",c);
    c=a*b;
    printf("\nMul : %d",c);
    x=(float)a/(float)b;
    printf("\nDiv : %0.2f",x);
    c=a%b;
    printf("\nMod : %d",c);
    return 0;
}
To download raw file Click Here

Output

Enter 2 Nos : 25 10
Total : 35
Difference : 15
Mul : 250
Div : 2.50
Mod : 5

Question-1 :Ramesh’s basic salary is input through the keyboard. His dearness allowance is 40% of basic salary, and house rent allowance is 20% of basic salary. Write a program to calculate his gross salary.

Source Code

#include<stdio.h>
int main()
{
    float bs,da,hra,gs;
    printf("\nEnter Your Basic Salary : ");
    scanf("%f",&bs);
    da=bs*0.4;
    hra=bs*0.2;
    gs=bs+da+hra;
    printf("\nBasic Salary : %0.2f",bs);
    printf("\nDA : %0.2f",da);
    printf("\nHRA : %0.2f",hra);
    printf("\nGross Salary : %0.2f",gs);
    return 0;
}
To download raw file Click Here

Output



Question-2 :The distance between two cities (in km.) is input through the keyboard. Write a program to convert and print this distance in meters, feet, inches and centimeters.

Source Code

#include<stdio.h>
int main()
{
    float km,m,cm,ft,i;
    printf("Enter The Kilometer : ");
    scanf("%f",&km);
    m=km*1000;
    cm=m*100;
    i=cm/2.54;
    ft=i/12;
    printf("\n KM : %0.2f",km);
    printf("\n M  : %0.2f",m);
    printf("\n CM : %0.2f",cm);
    printf("\n IN : %0.2f",i);
    printf("\n FT : %0.2f",ft);
    return 0;
}
To download raw file Click Here

Output

Enter Your Basic Salary : 15000
Basic Salary : 15000.00
DA : 6000.00
HRA : 3000.00
Gross Salary : 24000.00

Question-3 :If the marks obtained by a student in five different subjects are input through the keyboard, find out the aggregate marks and percentage marks obtained by the student. Assume that the maximum marks that can be obtained by a student in each subject is 100.

Source Code

#include<stdio.h>
int main()
{
    int m1,m2,m3,m4,m5,total;
    float avg;
    printf("\nEnter Five Marks : ");
    scanf("%d%d%d%d%d",&m1,&m2,&m3,&m4,&m5);
    total=m1+m2+m3+m4+m5;
    avg=total/5.0;
    printf("\nTotal : %d",total);
    printf("\nAverage : %0.2f",avg);
    return 0;
}
To download raw file Click Here

Output

Enter Five Marks : 75
78
98
85
99
Total : 435
Average : 87.00

Question-4 :Temperature of a city in Fahrenheit degrees is input through the keyboard. Write a program to convert this temperature into Centigrade degrees.

Source Code

/*
(32°F - 32)*5/9
*/
#include<stdio.h>
int main()
{
    float f,c;
    printf("\nEnter The Temperature : ");
    scanf("%f",&f);
    c=(f-32)*(5.0/9.0);
    printf("\nResult : %f",c);

    return 0;
}
To download raw file Click Here

Output

Enter The Temperature : 100
Result : 37.777779

Question-5 :The length & breadth of a rectangle and radius of a circle are input through the keyboard. Write a program to calculate the area & perimeter of the rectangle, and the area & circumference of the circle

Source Code

#include<stdio.h>
int main()
{
    float l,b,r_area,r_peri,r,c_area,cir;
    printf("\nEnter Length & Breadth :");
    scanf("%f%f",&l,&b);
    printf("\nEnter Radius :");
    scanf("%f",&r);
    r_area=l*b;
    r_peri=(2*(l+b));
    c_area=3.14*r*r;
    cir=2*3.14*r;
    printf("\nArea of Rectangle : %0.2f",r_area);
    printf("\nPerimeter of Rectangle : %0.2f",r_peri);
    printf("\nArea of Circle : %0.2f",c_area);
    printf("\nCircumference of Circle : %0.2f",cir);

    return 0;
}
To download raw file Click Here

Output

Enter Length & Breadth :10 20
Enter Radius :5
Area of Rectangle : 200.00
Perimeter of Rectangle : 60.00
Area of Circle : 78.50
Circumference of Circle : 31.40

Question-6 :Two numbers are input through the keyboard into two locations C and D. Write a program to interchange the contents of C and D.

Source Code

#include<stdio.h>
int main()
{
    int a,b;
    printf("\nEnter 2 Nos : ");
    scanf("%d%d",&a,&b);//5 10
    printf("\n A : %d   B : %d",a,b);
    a=a+b;//15
    b=a-b;//5
    a=a-b;//10
    printf("\n A : %d   B : %d",a,b);
    return 0;
}
/*
a=a*b;
b=a/b;
a=a/b;
*/
To download raw file Click Here

Output

Enter 2 Nos : 10 15
 A : 10   B : 15
 A : 15   B : 10

Question-7 :If a five-digit number is input through the keyboard, write a program to calculate the sum of its digits. (Hint: Use the modulus operator ‘%’)

Source Code

#include<stdio.h>
int main()
{
    int a,b,d,f,sum=0;
    printf("\nEnter 5 Digit No : ");
    scanf("%d",&a);//12345
    b=a/10;//1234
    sum+=a%10;//5
    d=b/10;//123
    sum+=b%10;//4
    f=d/10;//12
    sum+=d%10;//3
    sum+=f/10;//1
    sum+=f%10;//2
    printf("\nTotal : %d",sum);
    return 0;
}

/*
 int a,b,c,d,e,f,g,h,i,sum=0;
    printf("\nEnter 5 Digit No : ");
    scanf("%d",&a);//12345
    b=a/10;//1234
    c=a%10;//5
    sum+=c;//sum=sum+5
    d=b/10;//123
    e=b%10;//4
    sum+=e;
    f=d/10;//12
    g=d%10;//3
    sum+=g;
    h=f/10;//1
    sum+=h;
    i=f%10;//2
    sum+=i;
    printf("\nTotal : %d",sum);
    return 0;
*/
To download raw file Click Here

Output

Enter 5 Digit No : 12345
Total : 15

List of Programs


Sample Programs


Switch Case in C


Conditional Operators in C


Goto Statement in C


While Loop Example Programs


Looping Statements in C

For Loop Example Programs


Array Examples in C

One Dimensional Array


Two Dimensional Array in C


String Example Programs in C


Functions Example Programs in C


Learn All in Tamil © Designed & Developed By Tutor Joes