CP Exp2 (NEW)
CP Exp2 (NEW)
FE Engineering (Semester 1)
Name: Ritesh Lokhande Branch: IT
Roll No. : 38 Batch: E2
Experiment No. 2:
Demonstrate Operators - Arithmetic, Relational, Logical, Assignment, Unary,
Conditional, Bitwise, Comma, Other Operators.
2. Performance
20/09/2024
3. Punctuality
Total/Average
Verified by
FE Engineering (Semester 1)
Name: Ritesh Lokhande Branch: IT
Roll No. : 38 Batch: E2
Program No. 2.1
#include<stdio.h>
#include<conio>h>
int main()
{
int a, b;
int arithmeticResult;
int relationalResult;
int logicalResult;
clrscr();
// Arithmetic Operators
printf("\nArithmetic Operations:\n");
arithmeticResult = a + b;
printf("Addition: %d + %d = %d\n", a, b, arithmeticResult);
arithmeticResult = a - b;
printf("Subtraction: %d - %d = %d\n", a, b, arithmeticResult);
arithmeticResult = a * b;
printf("Multiplication: %d * %d = %d\n", a, b, arithmetic Result);
Jawahar Education Society’s
A.C. Patil College of Engineering
C Programming Lab (VSEC102)
FE Engineering (Semester 1)
Name: Ritesh Lokhande Branch: IT
Roll No. : 38 Batch: E2
if (b != 0) {
arithmeticResult = a / b;
printf("Division: %d / %d = %d\n", a, b, arithmeticResult);
arithmeticResult = a % b;
printf("Modulus: %d %% %d = %d\n", a, b, arithmetic Result);
} else {
printf("Division by zero is undefined.\n");
}
// Relational Operators
printf("\nRelational Operations:\n");
relationalResult = (a == b);
printf("%d == %d: %d\n", a, b, relationalResult);
relationalResult = (a != b);
printf("%d != %d: %d\n", a, b, relationalResult);
// Logical Operators
printf("\nLogical Operations:\n");
Jawahar Education Society’s
A.C. Patil College of Engineering
C Programming Lab (VSEC102)
FE Engineering (Semester 1)
Name: Ritesh Lokhande Branch: IT
Roll No. : 38 Batch: E2
getch();
return 0;
}
Jawahar Education Society’s
A.C. Patil College of Engineering
C Programming Lab (VSEC102)
FE Engineering (Semester 1)
Name: Ritesh Lokhande Branch: IT
Roll No. : 38 Batch: E2
Program No. 2.2
#include<stdio.h>
#include<conio.h>
int main()
{
int a, b, result;
clrscr();
printf("Enter the first integer for operation: \n");
scanf("%d",&a);
printf("Enter the second integer for operation: \n");
scanf("%d",&b);
// Unary Operators
printf("Unary Operators:\n");
printf("Initial value of a: %d\n", a);
printf("Unary minus of a: %d\n", -a); // Unary minus
printf("Increment of a: %d\n", ++a); // Pre-increment
printf("Decrement of a: %d\n", --a); // Pre-decrement
printf("Post-increment of a: %d\n", a++); // Post-increment
printf("Current value of a: %d\n", a); // After post-increment
printf("Post-decrement of a: %d\n", a--); // Post-decrement
printf("Current value of a: %d\n\n", a); // After post-decrement
FE Engineering (Semester 1)
Name: Ritesh Lokhande Branch: IT
Roll No. : 38 Batch: E2
// Bitwise Operators
printf("Bitwise Operators:\n");
printf("a = %d, b = &d\n", a, b);
printf("a & b = %d\n", a & b); //Bitwise AND
printf("a | b = %d\n", a | b); //Bitwise OR
printf("a ^ b = %d\n", a ^ b); //Bitwise XOR
printf("~a = %d\n", ~a); //Bitwise NOT
printf("a << 1 = %d\n", a << 1); //Left shift
printf("a >> 1 = %d\n", a>>1); //Right shift
getch();
return 0;
}
Jawahar Education Society’s
A.C. Patil College of Engineering
C Programming Lab (VSEC102)
FE Engineering (Semester 1)
Name: Ritesh Lokhande Branch: IT
Roll No. : 38 Batch: E2
#include<stdio.h>
#include <conio.h>
int main()
{
int a = 10, b;
int *ptr = &a; // 'ptr' contains address of 'a'
int x = (a=2,b=3,a+b); clrscr();
//Comma Operator
printf("\nComma wOperator:\n");
printf("Result of comma operator: x = %d (a=%d,b=%d)\n\n",x,a,b);
// Assignment Operator
printf("Assignment Operator:\n");b = a; // Assign value of 'a' to 'b'
printf("b = %d\n\n", b);
// sizeof Operator
printf("sizeof Operator:\n");
printf("Size of int: %lu bytes\n", sizeof(int));
printf("Size of float: %lu bytes\n", sizeof(float));
printf("Size of double: %lu bytes\n", sizeof(double));
printf("Size of char: %lu bytes\n\n", sizeof(char));
FE Engineering (Semester 1)
Name: Ritesh Lokhande Branch: IT
Roll No. : 38 Batch: E2
getch();
return 0;
}