0% found this document useful (0 votes)
14 views8 pages

CP Exp2 (NEW)

Uploaded by

suyogkadam078
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
14 views8 pages

CP Exp2 (NEW)

Uploaded by

suyogkadam078
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 8

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

Experiment No. 2:
Demonstrate Operators - Arithmetic, Relational, Logical, Assignment, Unary,
Conditional, Bitwise, Comma, Other Operators.

Experiment Evaluation Report

Sr. Evaluation Criteria Marks Date of


No. Performance
1. Topic Knowledge

2. Performance
20/09/2024
3. Punctuality

Total/Average

Verified by

Prof. Sachin Vaidya


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.1

//C program to implement Arithmetic, Relational and Logical Operators

#include<stdio.h>
#include<conio>h>
int main()
{
int a, b;
int arithmeticResult;
int relationalResult;
int logicalResult;
clrscr();

// Input two numbers


printf("Enter two integers: ");
scanf("%d %d", &a, &b);

// 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);

relationalResult = (a > b);


printf("%d > %d: %d\n", a, b, relationalResult);

relationalResult = (a < b);


printf("%d < %d: %d\n", a, b, relationalResult);

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

logicalResult = (a > 0 && b > 0);


printf("(%d > 0 && %d > 0): %d\n", a, b, logicalResult);

logicalResult = (a > 0 || b > 0);


printf("(%d > 0 || %d > 0): %d\n", a, b, logicalResult);

logicalResult = !(a > 0);


printf("!(%d > 0): %d\n", a, logicalResult);

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

//C program to implement Unary, Conditional and Bitwise Operators

#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

// Conditional (Ternary) Operator


printf("Condition Operator");
result = (a > b) ? a : b; // Conditional operator
printf("Larger of a and b: %d\n\n", 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
// 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

Program No. 2.3

//C program to implement Comma and Other Operators

#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));

// Address-of (&) and Dereferencing (*) Operator


printf("Address-of (&) and Dereferencing (*) Operator:\n");
printf("Address of a: %p\n", (void (*)&a);
printf("Value of a (using dereferencing): %d\n\n",*ptr);
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;
}

You might also like