c program practical VCACS (1)
c program practical VCACS (1)
int main() {
int a = 10, b = 5, c = 2, result;
result = a + b - c; // '+' and '-' have the same precedence; evaluated left to right
printf("Result of a + b - c = %d\n", result);
result = a * b / c; // '*' and '/' have the same precedence; evaluated left to right
printf("Result of a * b / c = %d\n", result);
return 0;
}
int main() {
int num1, num2, max;
return 0;
}
int main() {
int num1, num2, num3;
return 0;
} #include <stdio.h>
int main() {
// Default values for num1, num2, and num3
int num1 = 15, num2 = 25, num3 = 20;
return 0;
}
int main() {
// Default values for num1 and num2
int num1 = 25, num2 = 4, quotient, remainder;
return 0;
}
5) Write a C Program which illustrate increment and decrement operators (use of pre and post
increment is expected)
#include <stdio.h>
int main() {
int num = 5;
return 0;
}
int main() {
// Display size of various data types
printf("Size of char: %zu bytes\n", sizeof(char));
printf("Size of int: %zu bytes\n", sizeof(int));
printf("Size of float: %zu bytes\n", sizeof(float));
printf("Size of double: %zu bytes\n", sizeof(double));
printf("Size of long: %zu bytes\n", sizeof(long));
printf("Size of long long: %zu bytes\n", sizeof(long long));
printf("Size of short: %zu bytes\n", sizeof(short));
printf("Size of unsigned int: %zu bytes\n", sizeof(unsigned int));
return 0;
}
7)Write a program to swap the values of two variables using bitwise operator(^).
#include <stdio.h>
int main() {
int a = 5, b = 9;
return 0;
}
8)Write a c program which illustrate the use of Bitwise And, Bitwise Or and Bitwise XOR operator.
#include <stdio.h>
int main() {
int a = 5; // Binary: 0101
int b = 3; // Binary: 0011
return 0;
}
a & b: Performs bitwise AND. Example: 0101 & 0011 = 0001 (Decimal 1).
a | b: Performs bitwise OR. Example: 0101 | 0011 = 0111 (Decimal 7).
a ^ b: Performs bitwise XOR. Example: 0101 ^ 0011 = 0110 (Decimal 6).
9)Write a c program which illustrate biutwise left shift and right shift operators.
#include <stdio.h>
int main() {
int num = 8; // Binary: 1000
return 0;
}
```
### Explanation:
1. **Left Shift (`<<`)**:
- Shifts all bits of the number to the left by the specified number of positions.
- Adds `0` bits on the right.
- Example: `8 << 1` shifts `1000` to `10000` (Decimal `16`).
### Output:
```
Original number: 8
After left shift (num << 1): 16
After right shift (num >> 1): 4
10) Write a C program to check Least Significant Bit(LSB) of a number is set or not.
#include <stdio.h>
int main() {
int num = 10; // Default number, you can change this value
return 0;
}
Explanation:
The program uses num = 10 as the default value. You can modify this default value as needed.
It then checks whether the LSB is set (1) or not (0) using num & 1.
11) Write a c program to check most Significant Bit of a number is set or not.
#include <stdio.h>
#include <limits.h> // For CHAR_BIT
int main() {
int num = -1; // Default number (you can change this value)
return 0;
}
12) Write a C program to flip bits of a binary number using bitwise operator.
#include <stdio.h>
int main() {
unsigned int num = 10; // Default number (Binary: 1010)
printf("Original number: %u\n", num);
return 0;
}
13)Write a C program to check whether a number is even or odd using bitwise operator.
#include <stdio.h>
int main() {
int num = 7; // Default number (you can change this value)
return 0;
}