Arithmetic and Relational Operators with example in C programming

 Arithmetic (+,-,/,%)
Arithmetic Operators in C

The arithmetic operators are the symbols that are used to perform basic mathematical  operations like addition , subtraction, multiplication, division and percentage modulo.

Example-Write a program to perform all Arithmetic operation in c language 

Program for Arithmetic operation

#include <stdio.h>

void main()

{   int a, b;

     

      printf("Enter the valur of the two number for performing the arithmatic opertion \n");

      printf("Enter the frist number a::");

      scanf("%d",&a);

      printf("Enter the second number of the b::");

      scanf("%d",&b);


    printf("Arithmetic operator in C \n"); 

printf("this is value of a+b is %d",a+b);

printf("\nthis is value of a-b is %d",a-b);

printf("\n this is value of a*b is %d",a*b);

    printf("\n This is value of a/b is %d",a/b);

}

output-

Enter the valur of the two number for performing the arithmatic opertion
Enter the frist number a::25
Enter the second number of the b::5
Arithmetic operator in C
this is value of a+b is 30
this is value of a-b is 20
 this is value of a*b is 125
 This is value of a/b is 5
--------------------------------

Relation Operators(<,>,<=,>=.==,!=)

The relation operators are the symbols that used to compare two values. Every relation operators has two result TRUE or FALSE

OperatorMeaning of OperatorExample
== Equal to5 == 3 is evaluated to 0
>Greater than5 > 3 is evaluated to 1
<Less than5 < 3 is evaluated to 0
!=Not equal to5 != 3 is evaluated to 1
>=Greater than or equal to5 >= 3 is evaluated to 1
<=Less than or equal to5 <= 3 is evaluated to 0

Example- write a code to find the relation operators

program-
#include<stdio.h>
void main()
{ int a,b,c;
printf("Enter the three value find their realtion :");
scanf("%d %d %d",&a,&b,&c);
    printf("%d == %d is %d \n", a, b, a == b);
    printf("%d == %d is %d \n", a, c, a == c);
    printf("%d > %d is %d \n", a, b, a > b);
    printf("%d > %d is %d \n", a, c, a > c);
    printf("%d < %d is %d \n", a, b, a < b);
    printf("%d < %d is %d \n", a, c, a < c);
    printf("%d != %d is %d \n", a, b, a != b);
    printf("%d != %d is %d \n", a, c, a != c);
    printf("%d >= %d is %d \n", a, b, a >= b);
    printf("%d >= %d is %d \n", a, c, a >= c);
    printf("%d <= %d is %d \n", a, b, a <= b);
    printf("%d <= %d is %d \n", a, c, a <= c);

}

output-

Enter the three value find their realtion :5
5
15
5 == 5 is 1
5 == 15 is 0
5 > 5 is 0
5 > 15 is 0
5 < 5 is 0
5 < 15 is 1
5 != 5 is 0
5 != 15 is 1
5 >= 5 is 1
5 >= 15 is 0
5 <= 5 is 1
5 <= 15 is 1


Comments

Popular posts from this blog

CYBER SECURITY & CRACKING PASSWORDS

"The Dark Side of Social Media: How It Fuels Digital Addiction and Impacts Mental Health"

Online Platforms to Learn Coding