EXAMPLES OF OPERATORS

WAP to read a number. Find the last digit of given number.

#include<stdio.h>

void main()

{

  int no,rem;

  printf(“Enter a number :”);

  scanf(“%d”,&no);

  rem=no%10;

  printf(“Last digit = %d”,rem);

}

Output: Enter a number: 127

Last digit = 7

WAP to read a number, find the last 2 digits of given number.

#include<stdio.h>

void main()

{

  int no,rem;

  printf(“Enter a number :”);

  scanf(“%d”,&no);

  rem=no%100;

  printf(“Last 2 digits = %d”,rem);

}  

Output: Enter a number: 1247

Last 2 digits = 47

WAP to find big number between 2 numbers.

#include<stdio.h>

void main()

{

  int a,b,big;

  printf(“Enter 2 numbers :”);

  scanf(“%d%d”,&a,&b);

  big=a>b?a:b;

  printf(“Big number=%d”,big);

}  

Output: Enter 2 numbers: 100 50

Big number=100

WAP to find big number between 3 numbers.

#include<stdio.h>

void main()

{

  int a,b,c,big;

  printf("Enter 3 numbers : ");

  scanf(“%d%d%d”,&a,&b,&c);

  big= (a>b?a:b) > c ? (a>b?a:b) : c;

  printf(“Big number=%d”,big);

}  

Output: Enter 3 numbers: 100 50 175

Big number=175

Example:

#include<stdio.h>

void main()

{

  printf(“Size of char =%d”,sizeof(char));

  printf(“\nSize of int =%d”,sizeof(int));

  printf(“\nSize of float =%d”,sizeof(float));

  printf(“\nsize of double =%d”,sizeof(double));

}

Output: Size of char =1

Size of int =4

Size of float =4

size of double =8

Example 1:

#include<stdio.h>

void main()

{

  int a;

  a=10,20,30;

  printf( “a=%d”,a);

}  

Output: a=10

Example 2:

If we use comma inside the brackets then it acts as a special operator.

It evaluates all the expressions and gives the result of right most expression.

Example Programs

#include<stdio.h>

void main()

{

  int a;

  a=(10,20,30);

  printf( “a=%d”,a);

}  

Output: a=30

WAP to read radius of a circle. Print the area.

#include<stdio.h>

#define PI 3.14

void main()

{

  int r;

  float a;

  printf(“Enter radius :”);

  scanf(“%d”,&r);

  a=PI*r*r;

  printf(“Area=%f”,a);

}

Output: Enter radius: 10

Area=314.000000

WAP to find simple interest.

#include<stdio.h>

#define PI 3.14

void main()

{

  int p,t,r,si;

  printf(“Enter p,t,r values :”);

  scanf(“%d%d%d”,&p,&t,&r);

  si=p*t*r/100;

  printf(“Simple interest=%d”,si);

}   

Output: Enter p,t,r values: 10000 12 2

Simple interest=2400

WAP to read basic, hra, da, pf. Find the net salary. Net = basic + hra + da – pf

#include<stdio.h>

#define PI 3.14

void main()

{

  int basic, hra, da, pf, net;

  printf(“Enter basic, hra, da, pf :”);

  scanf(“%d%d%d%d”,&basic, &hra, &da, &pf);

  net=basic + hra + da - pf;

  printf(“Net salary=%d”,net);

}

Output: Enter basic, hra, da, pf: 25000 5000 3000 2000

Net salary=31000

WAP to read a lowercase char. Convert it to upper case.

#include<stdio.h>

void main()

{

  char ch;

  printf(“Enter a lower case char :”);

  scanf(“%c”,&ch);

  ch=ch-32;

  printf(“Upper case char=%c”,ch);

}  

output: Enter a lowercase char: b

Upper case char=B

WAP to read a upper case char, convert it to lower case.

#include<stdio.h>

void main()

{

  char ch;

  printf(“Enter a upper case char :”);

  scanf(“ %c”,&ch);

  ch=ch+32;

  printf(“Lower case char=%c”,ch);

}   

Output: Enter a upper case char: D

lowercase char=d

WAP to find the sum of N natural numbers without using any loop.

#include<stdio.h>

int main ()

{

  int n,sum;

  printf(“Enter N value :”);

  scanf(“%d”,&n);

  sum=(n*(n+1))/2;

  printf(“Sum=%d”,sum);

  return 0;

}   

Output: Enter N value: 10

Sum=55

WAP to find big number between 2 numbers without using if-else or without using conditional statement.

#include<stdio.h>

int main ()

{

  int a,b,big;

  printf(“Enter 2 numbers :”);

  scanf(“%d%d”,&a,&b);

  big=((a+b)+abs(a-b))/2;

  printf(“Big number=%d”,big);

  return 0;

}   

Output: Enter 2 numbers: 10 50

Big number=50

Explanation:

A=10

B=50

Big=((a+b)+abs(a-b))/2;

Big=((10+50)+abs(10-50))/2

Big=( 60 + abs( -40 ))/2

Big=(60 + 40 )/2

Big= 100/2

Big=50

WAP to find small number between 2 numbers without using if-else or without using conditional statement.

#include<stdio.h>

int main ()

{

  int a,b,small;

  printf(“Enter 2 numbers :”);

  scanf(“%d%d”,&a,&b);

  small=((a+b)-abs(a-b))/2;

  printf(“small number=%d”,small);

  return 0;

}   

Output: Enter 2 numbers: 10 50

Small number=10

Explanation:

A=10

B=50

small =((a+b)-abs(a-b))/2;

small =((10+50)-abs(10-50))/2

small =( 60 - abs( -40 ))/2

small =(60 - 40 )/2

small = 20/2

small=10

Write a proram to check whether a given year leap year or not

#include<stdio.h>

void main()

{

  int year;

  printf(“enter the value of year”);

  scanf(“%d”,&year);

  if(year%4==0)

{

  printf(“leap year”);

}

  else

{

  printf(“not a leap year”);

}

}