Arithmetic Operator - Basic C Programming Solve

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) 
masudbdasia@gmail.com






#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 :


  1. Arithmetic operator

  2. Unary operator

  3. Relational operator

  4. Logical operator

  5. Assignment operator

  6. Conditional operator


#Arithmetic Operators List :

# Arithmetic expressions:

An arithmetic expression is a combination of variables, constants, and operators.
For example,




Problems…

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);
}



(1)(b) Write a program that read two floating point and display sum.

#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);
}



2) Write a program that subtracts two integer.

#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);
}


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);
}

(4) (a) Write a program that divide two integer.

#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);
}


(4) (b) Write a program that divide two floating point.

#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);
}


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);
}

(6) (a) 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);
}

(6) (b) 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);
}

(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);
}

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;
}


Input Output





Previous
Next Post »
Thanks for your comment