You are on page 1of 6

6. Problem: Write a program to explain the function of unary prefix operator.

CODE:
#include <stdio.h>
int main()
{
int x,y;
printf("Enter two integers: \n");
scanf("%d %d",&x,&y);
printf("----PRE-INCREMENT OPERATOR EXAMPLE---- \n");
printf("Value of x : %d \n", x);
printf("Value of x : %d \n", ++x);
printf("Value of x : %d \n", x);
printf("----PRE-DECREMENT OPERATOR EXAMPLE---- \n");
printf("Value of y : %d \n", y);
printf("Value of y : %d \n", --y);
printf("Value of y : %d \n", y);
return 0;
}

INPUT:

OUTPUT:
7. Problem: Write a program to explain the function of unary postfix operator.
CODE:
#include <stdio.h>
int main()
{
int x,y;
printf("Enter two integers: \n");
scanf("%d %d",&x,&y);
printf("----POST-INCREMENT OPERATOR EXAMPLE---- \n");
printf("Value of x : %d \n", x);
printf("Value of x : %d \n", x++);
printf("Value of x : %d \n", x);
printf("----POST-DECREMENT OPERATOR EXAMPLE---- \n");
printf("Value of y : %d \n", y);
printf("Value of y : %d \n", y--);
printf("Value of y : %d \n", y);
return 0;
}

INPUT:

OUTPUT:
8. Problem: Write a program to show the working of the assignment operators.

CODE:
#include <stdio.h>
int main()
{
int a = 21,c;
c = a;
printf("1) = Operator Example, Value of c = %d\n", c );
c += a;
printf("2) += Operator Example, Value of c = %d\n", c );
c -= a;
printf("3) -= Operator Example, Value of c = %d\n", c );
c *= a;
printf("4) *= Operator Example, Value of c = %d\n", c );
c /= a;
printf("5) /= Operator Example, Value of c = %d\n", c );
c = 200;
c %= a;
printf("6) %= Operator Example, Value of c = %d\n", c );
c <<= 2;
printf("7) <<= Operator Example, Value of c = %d\n", c );
c >>= 2;
printf("8) >>= Operator Example, Value of c = %d\n", c );
c &= 2;
printf("9) &= Operator Example, Value of c = %d\n", c );
c ^= 2;
printf("10) ^= Operator Example, Value of c = %d\n", c );
c |= 2;
printf("11) |= Operator Example, Value of c = %d\n", c );
return 0;
}
OUTPUT:
9. Problem: Write a program to find the largest of two numbers using ternary
operator.

CODE:
#include<stdio.h>
int main()
{
int a,b,max;
printf("Enter the values of a and b:");
scanf("%d%d" ,&a,&b);
max = (a>b) ? a : b;
printf("Larger number=%d" ,max);
return 0;
}

INPUT:

OUTPUT:
10. Problem: Write a program to perform arithmetic operations (addition, subtraction,
multiplication, division and modulo-division) on two integers.

CODE:
#include<stdio.h>
int main()
{
int a,b,sum,subtract,product,division,remainder;
printf("Enter two integers of your choice:\n");
scanf("%d %d",&a,&b);
sum=a+b;
subtract=a-b;
product=a*b;
division=a/b;
remainder=a%b;
printf("\nThe sum of %d and %d is %d",a,b,sum);
printf("\nThe subtraction of %d and %d is %d",a,b,subtract);
printf("\nThe product of %d and %d is %d",a,b,product);
printf("\nThe division of %d and %d is %d",a,b,division);
printf("\nThe remainder of %d and %d is %d",a,b,remainder);
return 0;
}

INPUT:

OUTPUT:
11.Problem: Write a program using Short-circuit method to show the use of logical
operators.

CODE:
#include<stdio.h>
int main()
{
int a=1,b=0;
int c=!(-a&&++b);
printf("c=%d",c);
return 0;
}

INPUT & OUTPUT:

You might also like