C Language OPERATORS

 

OPERATORS

 

It is a Symbol which represents some operation that can be performed on data.

 1. Arithmetic operators

Addition (+)

Subtraction (-)

Multiplication (*)

Division (/)

Modulus (%)

 

2. Relational operators

 

Less than (<)

Greater than (>)

Less than or equal to (<=)

Greater than or equal to (>=)

Equal to (==)

Not equal to (!=)

 

3. Logical operators

 

X

Y

X&&Y

X||Y

0

0

0

0

0

1

0

1

1

0

0

1

1

1

1

1

          AND (&&)

OR (||)

NOT (!)

 

 

4. Short hand assignment operators

 

A+=B

A=A+B

A-=B

A=A-B

A*=B

A=A*B

A/=B

A=A/B

A%=B

A=A%B

 

5. Conditional Operators

          ?   :

 

6. Bitwise Operators

 

Bitwise AND (&)

Bitwise OR (|)

Bitwise EXCLUSIVE OR (^)

Bitwise LEFT SHIFT (<<)

Bitwise RIGHT SHIFT (>>)

Bitwise COMPLEMENT (~)

 

7. Special Operator

 

1. Size of

 

          Find the number of bytes occupied by the operand.

 

Syntax

          variable=sizeof(operand)

 

Example

          int sum;

int m=sizeof(sum);

 

(Output = 2 bytes)

 

2. Comma

Syntax

 

variable=(exp1.exp2,exp3,…………expn)

Example

sum(a=10,b=10,c=10,a+b+c)

 

SIMPLE PROGRAM

#include<stdio.h>

#include<conio.h>

main()

{

clrscr();

printf("Welcome");

getch();

}


Simple Add, Sub, Mul, Div, Mod

#include<stdio.h>

#include<conio.h>

main()

{

int a,b,c,d,e,f,g;

clrscr();

printf("Enter A Value=");

scanf("%d",&a);

printf("Enter B Value=");

scanf("%d",&b);

c=a+b;

d=a-b;

e=a*b;

f=a/b;

g=a%b;

printf("\n Addition=%d",c);

printf("\n Subtraction=%d",d);

printf("\n Multiplication=%d",e);

printf("\n Division=%d",f);

printf("\n Modulus=%d",g);

getch();

}

 

Simple & Compound Interest Calculation

 

Simple Interest = ptr/100

Compound Interest = p(1+r/100)-p

 

p - Principle Compound

t -  Number of years

r – Rate of Interest

 

#include<stdio.h>

#include<conio.h>

#include<math.h>

main()

{

float p,t,r,simple,compound;

clrscr();

printf("Enter Principal Amount=");

scanf("%f",&p);

printf("\n Enter the rate of interest=");

scanf("%f",&r);

printf("\n Enter the time period in years=");

scanf("%f",&t);

simple=p*t*r/100;

compound=p*pow(1+r/100,t)-p;

printf("\n Simple Interest= %6.2f",simple);

printf("\n");

printf("\n Compound Interest %6.2f",compound);

getch();

}

 

Find Area of Triangle

 

area = s(s-a)(s-b)(s-c)

s = (a+b+c)/2

 

#include<stdio.h>

#include<conio.h>

#include<math.h>

main()

{

float a,b,c,s,area;

printf("\n Enter three sides a,b,c");

scanf("%f %f %f",&a,&b,&c);

s=(a+b+c)/2;

area=sqrt(s*(s-a)*(s-b)*(s-c));

printf("\n Area of Triangle %6.2f",area);

getch();

}


To convert temperature in centigrade to Fahrenheit and vice versa.

 

c to f=1.8 x centigrade +32

f to c=(fahrenheit -32)/1.8

 

#include<stdio.h>

#include<conio.h>

#include<math.h>

main()

{

float c,f,ci,fi;

clrscr();

printf("\n Enter temperatue in centigrade \t");

scanf("%f",&c);

f=1.8*c+32;

printf("Fahrenheit=%f",f);

printf("\n Enter the temperature in fahrenheit \t");

scanf("%f",&fi);

ci=(fi-32)/1.8;

printf("Centigrade=%f",ci);

getch();

}

 

No comments:

Post a Comment