Skip to main content

PROGRAMMING FOR PROBLEM SOLVING LAB : Program 1

 

1.   Write a simple program that prints the results of all the operators available in C (including pre/ post increment, bitwise and/or/ not, etc.). Read required operand values from standard input.



# include <stdio.h> 
   void main()
{
int a,b,c=0,r=5,result=0; 
clrscr();
printf("\n Enter a & b values:\n"); 
scanf("%d%d",&a,&b);
c = a+b;
printf("\n ARITHMETIC OPERATORS a+b = %d \n",c); 
c = a-b;
printf("\n ARITHMETIC OPERATORS a-b = %d \n",c); 
c = a*b;
printf("\n ARITHMETIC OPERATORS a*b = %d \n",c);
c=a/b;
printf("\n ARITHMETIC OPERATORS a/b = %d \n",c);
c=a%b;
printf("\n ARITHMETIC OPERATORS MODULO DIVISION = %d \n",c); 
printf("\n PREINCREMENT OPERATOR ++a = %d \n", ++a);
printf("\n PREDECREMENT OPERATOR--b = %d \n", --a); 
printf("\n POST INCREMENT OPERATOR a++ = %d \n", a++); 
printf("\n POST DECREMENT OPERATORa-- = %d \n", a--);
b = a;
printf("\n ASSIGNMENT OPERATOR b = %d \n", b); 
b += a; // b = b+a
printf("\n ARITHMETIC ASSIGNMENT OPERATOR b = %d \n", b);
b -= a; // b = b-a
printf("\n ARITHMETIC ASSIGNMENT OPERATOR b = %d \n", b);
b *= a; // b = b*a
printf("ARITHMETIC ASSIGNMENT OPERATOR b = %d \n", b);
b /= a; // b = b/a
printf("\n ARITHMETIC ASSIGNMENT OPERATOR b = %d \n", b);
b %= a; // b = b%a
printf("\n ARITHMETIC ASSIGNMENT OPERATOR b = %d \n", b);
printf("\n RELATIONAL OPERATOR %d == %d = %d \n", a, b, a == b); 
printf("\n RELATIONAL OPERATOR %d > %d = %d \n", a, b, a > b);
//RETURNS 1 FOR TRUE OR 0 FOR FALSE
printf("\n RELATIONAL OPERATOR %d < %d = %d", a, b, a < b); 
printf("\n RELATIONAL OPERATOR %d != %d = %d \n", a, b, a != b); 
printf("\n RELATIONAL OPERATOR %d >= %d = %d \n", a, b, a >= b); 
printf("\n RELATIONAL OPERATOR %d <= %d = %d \n", a, b, a <= b);
result = (a == b) && (r > b);
printf("\n LOGICAL OPERATOR AND (a == b) && (r > b) equals to %d \n",result);
result = (a == b) && (r < b);
printf("\n LOGICAL OPERATOR OR (a == b) || (r < b) equals to %d \n",result);
result = (a != b) || (r < b);
printf("\n LOGICAL OPERATOR NOT (a != b) || (r < b) equals to %d \n",result);
result = !(a == b);
printf("!(a == b) equals to %d \n", result); 
c = (a == b) ? 1 : 0;
printf("\n CONDITIONAL OPERATOR= %d",c);
printf("\n BITWISE AND Output = %d", a&b); 
printf("\n BITWISE OR Output = %d", a|b); 
printf("\n BITWISE XOR Output = %d", a^b);
printf("\n SIZE OF OPERATOR int=%lu bytes\n",sizeof(a)); 
getch();
}
OUTPUT:


Enter a & b values:
7
4
ARITHMETIC OPERATORS a+b = 11 

 ARITHMETIC OPERATORS a-b = 3 

 ARITHMETIC OPERATORS a*b = 28 

 ARITHMETIC OPERATORS a/b = 1 

 ARITHMETIC OPERATORS MODULO DIVISION = 3 

 PREINCREMENT OPERATOR ++a = 8 

 PREDECREMENT OPERATOR--b = 7 

 POST INCREMENT OPERATOR a++ = 7 

 POST DECREMENT OPERATORa-- = 8 

 ASSIGNMENT OPERATOR b = 7 

 ARITHMETIC ASSIGNMENT OPERATOR b = 14 

 ARITHMETIC ASSIGNMENT OPERATOR b = 7 
ARITHMETIC ASSIGNMENT OPERATOR b = 49 

 ARITHMETIC ASSIGNMENT OPERATOR b = 7 

 ARITHMETIC ASSIGNMENT OPERATOR b = 0 

 RELATIONAL OPERATOR 7 == 0 = 0 

 RELATIONAL OPERATOR 7 > 0 = 1 

 RELATIONAL OPERATOR 7 < 0 = 0
 RELATIONAL OPERATOR 7 != 0 = 1 

 RELATIONAL OPERATOR 7 >= 0 = 1 

 RELATIONAL OPERATOR 7 <= 0 = 0 

 LOGICAL OPERATOR AND (a == b) && (r > b) equals to 0 

 LOGICAL OPERATOR OR (a == b) || (r < b) equals to 0 

 LOGICAL OPERATOR NOT (a != b) || (r < b) equals to 1 
!(a == b) equals to 1 

 CONDITIONAL OPERATOR= 0
 BITWISE AND Output = 0
 BITWISE OR Output = 7
 BITWISE XOR Output = 7
 SIZE OF OPERATOR int=4 bytes

Comments

Popular posts from this blog

Learning and Development Interview Questions and answers for Mathematics-1.

  1). What is Mean, Mode and Median? Solution Answer: The mean is the average of a  collection of numbers or terms in a sequence. To calculate the mean use a formula is sum of total terms divided  by number of terms. The mode  is the most f requent number or term in a sequence. It means the number that occurred  highest number of times  in a sequence. To find the mode arrange the numbers in ascending or descending order and verify which number repeated most number of times in a sorted sequence. The median is the middle number/term where the sequence is arranged in ascending or descending order. If the sorted sequence have odd number of terms then  divide by 2 and round up to get the position of the median number.  If the  sorted sequence  have  even  number of terms then  divide by 2  to get the position of the median number.  2 ). What is the Difference between Fractional and Rational number? Solu...