0% found this document useful (0 votes)
2 views

Operators

The document contains a series of C programs that perform basic arithmetic operations such as addition, subtraction, multiplication, division, and modulus on two integers. It also includes programs to calculate the area of a circle based on the radius, convert temperatures between Celsius and Fahrenheit, and perform bitwise operations like AND, OR, and XOR. Each program is accompanied by code snippets and expected outputs.
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
2 views

Operators

The document contains a series of C programs that perform basic arithmetic operations such as addition, subtraction, multiplication, division, and modulus on two integers. It also includes programs to calculate the area of a circle based on the radius, convert temperatures between Celsius and Fahrenheit, and perform bitwise operations like AND, OR, and XOR. Each program is accompanied by code snippets and expected outputs.
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 11

Operator

1. Write a program that read two integers and display sum.

Code:

#include<stdio.h>
int main()
{
int a,b,c;
printf("Enter 1st Integer: ");
scanf("%d", &a);
printf("Enter 2nd Integer: ");
scanf("%d", &b);
c = a + b;
printf("Result : %d \n",c);
return 0;
}

Output:
2. Write a program that read two integers and display their difference.

Code:
#include<stdio.h>

int main()
{
int a,b,c;
printf("Enter 1st Integer: ");
scanf("%d", &a);
printf("Enter 2nd Integer: ");
scanf("%d", &b);
c = a - b;
printf("Difference is : %d \n",c);
return 0;
}

Output:
3. Write a program that read two integers and display product.

Code:
#include<stdio.h>
int main()
{
int a,b,c;
printf("Enter 1st Integer: ");
scanf("%d", &a);
printf("Enter 2nd Integer: ");
scanf("%d", &b);
c = a * b;
printf("Product is : %d \n",c);
return 0;
}

Output:
4. Write a program that read two integers and divide two integers.

Code:
// if the result is considered to be fractional and absolute both
//also handles divided by zero error

#include<stdio.h>
int main()
{
int a,b;
float c;
printf("Enter 1st Integer: ");
scanf("%d", &a);
printf("Enter 2nd Integer: ");
scanf("%d", &b);
if(b==0)
{
printf("Divided by Zero Error. ");
}
else
{
c = (float) a /(float) b;
printf("Division is : %f \n",c);
}
return 0;
}

Output:
5. Write a program that read two integer and display remainder.

Code:
#include<stdio.h>
int main()
{
int a,b,c;
printf("Enter 1st Integer: ");
scanf("%d", &a);
printf("Enter 2nd Integer: ");
scanf("%d", &b);
c = a % b;
printf("Remainder is : %d \n",c);
return 0;
}

Output:
6. Write a program that read radius of a circle and display area.

Code:
#include<stdio.h>
#define PI 3.14159
int main()
{
float r,area;
printf("Enter Radius: ");
scanf("%f", &r);
area = PI * r * r;
printf("The area is : %f \n",area);
return 0;
}
Output:
7. Write a program that read temperature in Celsius and display in Fahrenheit.

Code:
#include<stdio.h>
int main()
{
float F,C;
printf("Enter Temperature in Celsius: ");
scanf("%f", &C);
F = ( 1.8 * C) + 32 ;
printf("In Fahrenheit scale: %.2f F\n",F);
return 0;
}

Output:
8. Write a program that read temperature in Fahrenheit and display in Celsius.

Code:
#include<stdio.h>
int main()
{
float F,C;
printf("Enter Temperature in Fahrenheit: ");
scanf("%f", &F);
C = (F - 32) /1.8;
printf("In Celsius scale: %.2f C\n",C);
return 0;
}

Output:
9. Write a program that read two numbers and display bitwise AND.

Code:
#include<stdio.h>
int main()
{
int a,b;
printf("Enter 1st number: ");
scanf("%d", &a);
printf("Enter 2nd number: ");
scanf("%d", &b);
printf("Bitwise AND Result = %d", a&b);
return 0;
}

Output:
10. Write a program that read two numbers and display bitwise OR.

Code:
#include<stdio.h>
int main()
{
int a,b;
printf("Enter 1st number: ");
scanf("%d", &a);
printf("Enter 2nd number: ");
scanf("%d", &b);
printf("Bitwise OR Result = %d", a|b);
return 0;
}

Output:
11. Write a program that read two numbers and display bitwise Exclusive OR.

Code:
#include<stdio.h>
int main()
{
int a,b;
printf("Enter 1st number: ");
scanf("%d", &a);
printf("Enter 2nd number: ");
scanf("%d", &b);
printf("Bitwise XOR Result = %d", a^b);
return 0;
}

Output:

You might also like