arithmetic operator
TRANSCRIPT
Arithmetic Operator - Basic C Programming Solve niterians.blogspot.com
Pag
e1
Arithmetic Operator - Basic C Programming Solve
Problems… 1. (a) Write a program that read two integer and display sum.
(b) Write a program that read two floating point and display sum.
2. Write a program that subtracts two integer.
3. Write a program that read two integer and display product.
4. (a) Write a program that divide two integer.
(b) Write a program that divide two floating point
5. Write a program that read two integer and display reminder.
6. Write a program that read radius of a circle and display its area.
7. Write a program to demonstrate the working of increment and
decrement operators.
SOLVED BY
Md. Masudur Rahman
Department of Textile Engineering 4th Batch
National Institute of Textile Engineering and Research (NITER) [email protected]
Arithmetic Operator - Basic C Programming Solve niterians.blogspot.com
Pag
e2
Operator : Operators in C program is special symbol or word which directs the
compiler to perform arithmetical or logical works, i.e. the characters which is used in C
for special purpose so this character is called operators.
Different types of operators :
Arithmetic operator
Unary operator
Relational operator
Logical operator
Assignment operator
Conditional operator
Arithmetic Operators List :
Arithmetic Operators niterians.blogspot.com
Operator Meaning
+ Addition or unary plus
- Subtraction or unary minus
* Multiplication
/ Division
% Modulo division
++ Increment operator increases the integer value
by one.
-- Decrement operator decreases the integer
value by one.
Arithmetic Operator - Basic C Programming Solve niterians.blogspot.com
Pag
e3
Arithmetic expressions: An arithmetic expression is a combination of variables, constants, and
operators.
For example,
Arithmetic expressions: niterians.blogspot.com
a*b-c a*b-c
(m+n)(x+y) (m+n)*(x+y)
ax2+bx+c a*x*x+b*x+c
1) (a) Write a program that read two integer and display sum.
#include <stdio.h>
int main ()
{
int a, b, c;
printf("Enter the value of a : ");
scanf("%d", &a);
printf("Enter the value of b : ");
scanf("%d", &b);
c =a+b;
printf("Sum of a and b is %d ", c);
}
Arithmetic Operator - Basic C Programming Solve niterians.blogspot.com
Pag
e4
(1) (b) Write a program that read two floating point and display sum.
2) Write a program that subtracts two integer.
#include <stdio.h>
int main ()
{
float a, b, c;
printf("Enter the value of a : ");
scanf("%f", &a);
printf("Enter the value of b : ");
scanf("%f", &b);
c =a+b;
printf("Sum of a and b is %f ", c);
}
#include <stdio.h>
int main ()
{
int a, b, c;
printf("Enter the value of a :");
scanf("%d", &a);
printf("Enter the value of b :");
scanf("%d", &b);
c =a-b;
printf("a - b = %d", c);
}
Arithmetic Operator - Basic C Programming Solve niterians.blogspot.com
Pag
e5
2) Write a program that subtracts two integer
3) Write a program that read two integer and display product.
#include <stdio.h>
int main ()
{
int a, b, c;
printf("Enter the value of a : ");
scanf("%d", &a);
printf("Enter the value of b : ");
scanf("%d", &b);
c =a*b;
printf("Product of a and b is %d ", c);
}
Arithmetic Operator - Basic C Programming Solve niterians.blogspot.com
Pag
e6
(4) (a) Write a program that divide two integer.
(4) (b) Write a program that divide two floating point
#include <stdio.h>
int main ()
{
int a, b, c;
printf("Enter the value of a: ");
scanf("%d", &a);
printf("Enter the value of b: ");
scanf("%d", &b);
c =a/b;
printf("a divide b is = %d", c);
}
#include <stdio.h>
int main ()
{
float a, b, c;
printf("Enter the value of a: ");
scanf("%f", &a);
printf("Enter the value of b: ");
scanf("%f", &b);
c =a/b;
printf("a divide b is = %f", c);
}
Arithmetic Operator - Basic C Programming Solve niterians.blogspot.com
Pag
e7
(4) (b) Write a program that divide two floating point
5) Write a program that read two integer and display reminder.
#include <stdio.h>
int main ()
{
int a, b, c;
printf("Enter the value of a: ");
scanf("%d", &a);
printf("Enter the value of b: ");
scanf("%d", &b);
c =a%b;
printf("Remainder = %d", c);
}
Arithmetic Operator - Basic C Programming Solve niterians.blogspot.com
Pag
e8
(6) (a) Write a program that read radius of a circle and display its area.
(6) (b) Write a program that read radius of a circle and display its area
#include <stdio.h>
void main ()
{
float r, area;
printf("Enter the radius : ");
scanf("%f", &r);
area = 3.1416*r*r;
printf("The area of the circle is: %f", area);
}
#include <stdio.h>
#define pi 3.1416
void main ()
{
float r, area;
printf("Enter the radius : ");
scanf("%f", &r);
area = pi*r*r;
printf("The area of the circle is: %f", area);
}
Arithmetic Operator - Basic C Programming Solve niterians.blogspot.com
Pag
e9
(6) (b) Write a program that read radius of a circle and display its area
(6) (c) Write a program that read radius of a circle and display its area
#include <stdio.h>
#define pi 3.1416
void main ()
{
float r, area;
printf("Enter the radius : ");
scanf("%f", &r);
area = pi*r*r;
printf("The area of the circle is: %f", area);
}
Arithmetic Operator - Basic C Programming Solve niterians.blogspot.com
Pag
e10
7) Write a program to demonstrate the working of increment and decrement operators.
#include <stdio.h>
int main()
{
int a, c;
float b, d;
printf("a = ");
scanf("%d", &a);
printf("b = ");
scanf("%f", &b);
printf("c = ");
scanf("%d", &c);
printf("d = ");
scanf("%f", &d);
printf("++a = %d \n", ++a);
printf("--b = %f \n", --b);
printf("++c = %d \n", ++c);
printf("--d = %f \n", --d);
return 0;
}