7. WRITE A C PROGRAM USING CONDITIONAL OPERATOR TO FIND GREATEST OF TWO NUMBERS
/*C program using conditional operator to find greatest of two numbers*/#include<stdio.h>
#include<conio.h>
void main()
{
int x,y,z;
clrscr();
printf(" Enter value of x:");
scanf("%d",&x);
printf("\n Enter value of y:");
scanf("%d",&y);
z=(x>y)?x:y;
printf("\n %d is greater number",z);
getch();
}
output
Enter value of x:30
Enter value of y:50
50 is greater number
8. WRITE A C PROGRAM TO EXPLAIN INCREMENT AND DECREMENT OPERATOR
/*C program to explain increment and decrement operator*/#include <stdio.h>
#include<conio.h>
int main()
{
int integerType;
float floatType;
double doubleType;
char charType;
// Sizeof operator is used to evaluate the size of a variable
printf("Size of int: %ld bytes\n",sizeof(integerType));
printf("Size of float: %ld bytes\n",sizeof(floatType));
printf("Size of double: %ld bytes\n",sizeof(doubleType));
printf("Size of char: %ld byte\n",sizeof(charType));
return 0;
}
output
Size of int: 4 bytes
Size of float: 4 bytes
Size of double: 8 bytes
Size of char: 1 byte
9. WRITE A C PROGRAM TO FIND THE SIZE OF A VARIABLE
/*program explaining increment and decrement operators*/#include<stdio.h>
#include<conio.h>
Int main()
{
Int a,b,c,d,e,f;
clrscr();
printf(“enter a,b values”);
scanf(“%d%d”,&a,&b);
++a;
++b;
printf(“\na=%d,b=%d”,a,b);
c=++a;
d=b++;
printf(“\nc=%d,d=%d”,c,d);
e=--c;
f=d--;
printf(“\ne=%d,f=%d”,e,f);
getch();
return 0;
}
output
enter a,b values4
4
a=4,b=5
c=6,d=5
e=5,f=5
10. WRITE A C PROGRAM FOR BITWISE OPERATORS
/*program for bitwise operators*/#include<stdio.h>
#include<conio.h>
Int main()
{
int a,b;
clrscr();
a=4;
b=6;
printf(“bitwise and is %d\n”,a&b);
printf(“bitwise or is %d\n”a|b);
printf(“bitwise exclusive or is %d\n”a^b);
printf(“bitwise negation a is %d”\n, ¬a);
printf(“bitwise << is %d\n”,a<<4);
printf(“bitwise >> is %d\n”,b>>6);
getch();
return 0;
}
output
bitwise and is 4
bitwise or is 6
bitwise exclusive or is 2
bitwise negation a is -5
bitwise << is 4
bitwise >> is 6
11. WRITE A C PROGRAM FOR SPECIAL OPERATORS / COMMA OPERATORS
/*program to comma operator*/#include<stdio.h>
#include<conio.h>
int main()
{
int a,b,c;
clrscr();
c=(a=6,b=3,a+b);
printf(“the value of c is %d\n”,c);
getch();
return 0;
}
output
the value of c is 9
12. WRITE A C PROGRAM EXPLAINING SHORTHAND OPERATORS
/*c program explaining shorthand operators*/#include<stdio.h>
#include<conio.h>
int main() {
int res;
res = 11;
res += 4;
printf("\nResult of Ex1 = %d", res);
res = 11;
res -= 4;
printf("\nResult of Ex2 = %d", res);
res = 11;
res *= 4;
printf("\nResult of Ex3 = %d", res);
res = 11;
res /= 4;
printf("\nResult of Ex4 = %d", res);
res = 11;
res %= 4;
printf("\nResult of Ex5 = %d", res);
return 0;
}
output
Result of Ex1 = 15
Result of Ex2 = 7
Result of Ex3 = 44
Result of Ex4 = 2
Result of Ex5 = 3
13. WRITE A C PROGRAM TO UNDERSTAND RELATIONAL OPERATORS
/*C Program to Understand Relational operators*/#include <stdio.h>
int main(void)
{
int a,b;
a=10; b=20;
printf("Relational Operators output \n");
printf("a < b is : %d \n",a<b);
printf("a <= b is : %d \n",a<=b);
printf("a == b is : %d \n",a==b);
printf("a != b is : %d \n",a!=b);
printf("a > b is : %d \n",a>b);
printf("a >= b is : %d \n",a>=b);
return 0;
}
output
a < b is : 1
a <= b is : 1
a == b is : 0
a != b is : 1
a > b is : 0
a >= b is : 0
14. WRITE A C PROGRAM TO UNDERSTAND LOGICAL AND & LOGICAL OR OPERATOR
/*Program to Understand Logical And operator :*/#include<stdio.h>
#include<conio.h>
int main()
{
printf("Logical AND Operator Result : \n");
printf(" 0 && 0 = %d \n",0&&0);
printf(" 1 && 0 = %d \n",1&&0);
printf(" 0 && 1 = %d \n",0&&1);
printf(" 1 && 1 = %d \n",1&&1);
return 0;
}
output
0 && 0 = 0
1 && 0 = 0
0 && 1 = 0
1 && 1 = 1
C program explaining Logical OR ( || ) Operator With Example and Truth table
/*Logical OR ( || ) Operator With Example and Truth table :*/
#include<stdio.h>
#include<conio.h>
int main()
{
printf("Logical OR Operator Result : \n");
printf(" 0 || 0 = %d \n",0||0);
printf(" 1 || 0 = %d \n",1||0);
printf(" 0 || 1 = %d \n",0||1);
printf(" 1 || 1 = %d \n",1||1);
return 0;
}
output
0 || 0 = 0
1 || 0 = 1
0 || 1 = 1
1 || 1 = 1
15. WRITE A C PROGRAM TO UNDERSTAND LOGICAL NOT ( ! ) OPERATOR
/*C Program to Understand Logical NOT ( ! ) operator*/#include <stdio.h>
#include<conio.h>
int main(void)
{
printf(" LOgical NOT Operator Result : \n");
printf(" !1 is : %d \n",!1);
printf(" !0 is : %d \n", !0);
return 0;
}
output
!1 is : 0
!0 is : 1
16. WRITE A C PROGRAM PRE-INCREMENT AND PRE-DECREMENT
/*C program pre-increment and pre-decrement*/#include<stdio.h>
#include<conio.h>
main()
{
int count = 0, loop;
loop = ++count; /* same as count = count + 1; loop = count;
printf("loop = %d, count = %d\n", loop, count);
loop = count++; /* same as loop = count; count = count + 1;
printf("loop = %d, count = %d\n", loop, count);
}
output
loop = 1, count = 1
loop = 1; count = 2
Comments
Post a Comment