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 OPERATORS | OPERATION | EXAMPLE |
---|---|---|
+ | 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. |
The code is a C program that prompts the user to input two integers, performs various arithmetic operations on them, and then prints the results to the console. Here is an explanation of each line of the 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
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.
#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
Enter Your Basic Salary : 10000 Basic Salary : 10000.00 DA : 4000.00 HRA : 2000.00 Gross Salary : 16000.00
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.
#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
Enter The Kilometer : 30 KM : 30.00 M : 30000.00 CM : 3000000.00 IN : 1181102.38 FT : 98425.20
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.
#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
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.
/* (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
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
#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
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.
#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
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 ‘%’)
#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
Enter 5 Digit No : 12345 Total : 15
Question-8 :If a five-digit number is input through the keyboard, write a program to reverse the number
#include<stdio.h> int main() { int a,b,c,d,e,f,g,h,i,result; printf("\nEnter 5 Digit No : "); scanf("%d",&a);//12345 b=a/10;//1234 c=a%10;//5 d=b/10;//123 e=b%10;//4 f=d/10;//12 g=d%10;//3 h=f/10;//1 i=f%10;//2 result=(c*10000)+(e*1000)+(g*100)+(i*10)+h; printf("\nReverse of 5 Digit No %d is : %d",a,result); return 0; }To download raw file Click Here
Enter 5 Digit No : 12345 Reverse of 5 Digit No 12345 is : 54321
Learn All in Tamil © Designed & Developed By Tutor Joes | Privacy Policy | Terms & Conditions