Me 1ppsc03.10.2024finalsolutionscse2
Me 1ppsc03.10.2024finalsolutionscse2
ii. Define a keyword. Write any five keyworks in C language [1] R CO1
Keywords in C language has fixed meaning given by the C developers which cannot
be changed. Keywords serve as basic building blocks for program statements.
iii. Define a variable in C language. Identify the valid variable [1] R CO1
names from the following by applying naming rules.
a) 2024CSE
b) classCount
c) int
d) cse_2024
OUTPUT:
Left Shift: 36
Bitwise AND: 8
Write a C program to read four numbers from the user and print [4]
their sum, product and average.
Characteristics of an Algorithm
1. Finiteness: The algorithm must terminate after a finite number of steps.
2. Definiteness: Each step of the algorithm must be precisely defined.
3. Input: An algorithm must take zero or more inputs.
4. Output: The algorithm should produce at least one output.
5. Effectiveness: All operations in the algorithm should be simple and basic enough to be
carried out, ideally, by a human or a machine.
Algorithm to Check Whether a Number is Even or Odd
1. Step 1: Start.
2. Step 2: Input the number n.
3. Step 3: Check if n % 2 == 0.
o If true, print "Even number."
o If false, print "Odd number."
4. Step 4: Stop.
C Program:
#include <stdio.h>
int main() {
int num1, num2, num3, num4;
int sum, product;
float average;
return 0;
}
ii. Define an Operator & an Expression in C language. List the [3] Ap CO1
Types of operators.
Types of Operators in C
1. Arithmetic Operators: +, -, *, /, % (modulus)
2. Relational Operators: ==, !=, >, <, >=, <=
3. Logical Operators: && (AND), || (OR), ! (NOT)
4. Bitwise Operators: &, |, ^, ~, <<, >>
5. Assignment Operators: =, +=, -=, *=, /=, %=
6. Increment/Decrement Operators: ++, --
7. Conditional (Ternary) Operator: ? :
8. Comma Operator: ,
9. Sizeof Operator: sizeof()
10. Pointer Operators: *, &
Draw a flow chart that takes diameter of a circle as input and [3]
computes and prints the Area and Circumference of that circle.
C Program:
#include <stdio.h>
#define PI 3.14159 // Define the value of Pi
int main() {
float diameter, radius, area, circumference;
// Input the diameter of the circle
printf("Enter the diameter of the circle: ");
scanf("%f", &diameter);
// Calculate the radius
radius = diameter / 2;
// Calculate the area
area = PI * radius * radius;
// Calculate the circumference
circumference = 2 * PI * radius;
// Print the results
printf("Area of the circle: %.2f\n", area);
printf("Circumference of the circle: %.2f\n", circumference);
return 0;
}
SAMPLE OUTPUT:
Enter the diameter of the circle: 2
Area of the circle: 3.14
Circumference of the circle: 6.28
Flowchart:
iv. Develop a C program to find the value of a2+b2+2ab. The values [5] Ap CO1
of a and b input through the keyboard.
Explain the usage of conditional operator and write its syntax. [2]
#include <stdio.h>
int main() {
int a, b, result;
return 0;
}
SAMPLE OUTPUT:
Enter the value of a: 1
Enter the value of a: 2
The result of a^2 + b^2 + 2ab is: 9
The conditional operator (also known as the ternary operator) is a shorthand way to
evaluate an expression based on a condition. It consists of three parts: a condition, a result for
true, and a result for false.
Syntax:
condition ? expression_if_true : expression_if_false;
The conditional operator is particularly useful for replacing simple if-else constructs in a
concise manner.
#include <stdio.h>
int main() {
int num1, num2, largest;
S. No Faculty Name
1. Dr. P. Niranjan, Professor
2. Dr. P. Vijay Kumar, Associate Professor
3. Sri. D. Naveen Kumar, Assistant Professor
4. Smt. R. Radhika, Assistant Professor
5. Sri. A. Venkatesh, Assistant Professor