Operators in C programming
// operators in c
// Arithmatic operators
// Relational operators
// Logical operators
// Bitwise operators
#include <stdio.h>
#include <conio.h>
#include <math.h>
int main()
{
// this is an example for arithmatic operators
int a, b, c, d;
printf("note - this programm includes addtion substraction and multiplication\n");
printf("enter number a\n");
scanf("%d", &a);
printf("enter number b\n");
scanf("%d", &b);
printf("enter number c\n");
scanf("%d", &c);
printf("enter number d\n");
scanf("%d", &d);
// Arthmatic operators are
// addition, substraction, multiplication, divison
printf("The sum of all numbers is %d\n", a + b + c + d);
printf("The substraction of all numbers is %d\n", a - b - c - d);
printf("the multiplication of all numbers is %d\n", a * b * c * d);
printf("the divison of all numbers is %d\n", a / b / c / d);
//to print the power
// printf("the 2 to the power 4 is %d\n", pow(2, 4));
return 0;
}
// logical operators in c programm
// && logical AND operator
// if both operands are non zero then the condition is true
// example (a&&b) is false
// logical OR operator
// If any of these two operands are non zero then condition becomes true
// example (A||B) is true#include <stdio.h>
// logical operators in c programm
// && logical AND operator
// Logical NOT operator
// It is used to reverse the logical state of its operand. If conditiion is true
// then logical not operator will make it false
// example !(A&&B) is true
#include <stdio.h>
int main()
{
int a = 10, b = 10;
printf("a&b is %d\n", a && b);
// this is and operator
printf("a||b %d\n", a || b);
// this is or operator
printf("a!b %d\n", !b);
// this is not operator
return 0;
}
Examples and solved problems for operators
//Question no 1
#include<stdio.h>
int main()
{
// to create a programm to find the area of the rectangle
int a=10,b=15;
printf("The area of the rectangle is %d\n",a*b);
return 0;
}
#include <stdio.h>
int main()
{
int length, width;
printf("Enter the length of the rectangle\n");
scanf("%d",&length);
printf("Enter the width of the rectangle\n");
scanf("%d",&width);
printf("The area of the rectangle is %d\n",length*width);
return 0;
}
Question no 2
calculate the area of the circle using the user input
#include <stdio.h>
int main()
{
int r, h;
printf("Enter the radius of the circle\n");
scanf("%d", &r);
printf("The area of the circle is %d units\n", 22 / 7 * (r * r));
printf("Enter the radius of the cylinder\n");
scanf("%d", &r);
printf("Enter the hieght of the cylinder\n");
scanf("%d", &h);
printf("The volume of cylinder is %d units\n", 22 / 7 * (r * r) * h);
return 0;
}
programm to calculate the volume of cylinder
#include <stdio.h>
int main()
{
int r, h;
printf("Enter the radius of the cylinder\n");
scanf("%d", &r);
printf("Enter the hight of the cylinder\n");
scanf("%d", &h);
printf("The volume of the cylinder is %d\n", 22 / 7 * (r * r) * h);
return 0;
}
#include <stdio.h>
int main()
{
int c;
printf("Enter the celcius which you want to convert\n");
scanf("%d", &c);
printf("The farenhiet scale is %d\n", (c * 9 / 5) + 32);
return 0;
}
question no 4 simple interest calculator
#include <stdio.h>
int main()
{
int principle,interest,time;
printf("Enter the principle\n");
scanf("%d",&principle);
printf("Enter the interest\n");
scanf("%d",&interest);
printf("Enter the time\n");
scanf("%d",&time);
printf("The simple interest is %d inr\n",(principle*interest*time)/100);
return 0;
}
#include <stdio.h>
int main()
{
int a, ;
printf("Enter the number which you want check It is divisible by 2\n");
scanf("%d", &a);
printf("The return is %d",a%2);
return 0;
}
Comments
Post a Comment