Here is the fully combined CAT with all questions and answers in one structured format.
You can easily copy everything for your study notes.
INTRODUCTION TO PROGRAMMING AND
ALGORITHMS – CAT QUESTIONS &
ANSWERS
SECTION A: MULTIPLE CHOICE QUESTIONS (MCQs) – 1
Mark Each
1. Which of the following is a high-level programming language?
2. a) Assembly
3. b) Machine Code
4. c) Python
5. d) Binary
6. Which data type is used to store a single character in C?
a) int
b) char
c) float
d) double
7. What will be the output of printf("%d", 5/2); in C?
a) 2.5
b) 2 (Integer division in C discards the decimal part.)
c) 3
d) 5
8. The && operator is used for:
a) Bitwise AND
b) Logical AND
c) Logical OR
d) Bitwise OR
9. Which of the following statements is used to exit a loop prematurely?
a) continue
b) break
c) goto
d) exit
10. What is the output of the following code?
int a = 10, b = 20;
printf("%d", a > b ? a : b);
a) 10
b) 20
c) Error
d) 30
11. In a switch statement, which keyword is used to exit a case?
a) return
b) exit
c) break
d) continue
12. Which loop will always execute at least once?
a) for
b) while
c) do-while
d) foreach
13. What is the default value of an uninitialized int variable in C?
a) 0
b) NULL
c) Garbage value
d) 1
14. In C, how do you open a file for reading?
a) fopen("file.txt", "r");
b) fopen("file.txt", "w");
c) fopen("file.txt", "a");
d) fopen("file.txt", "rw");
SECTION B: SHORT ANSWER QUESTIONS – 3 Marks Each
11. Define programming and list two types of programming languages.
• Programming is the process of writing instructions for a computer to execute.
• Types of Programming Languages:
o Low-Level Languages (e.g., Assembly, Machine Code)
o High-Level Languages (e.g., C, Python, Java)
12. Differentiate between int, float, and double.
| Data Type | Definition | Example |
|-----------|-------------|---------|
| int | Stores whole numbers | int num = 10; |
| float | Stores decimal numbers (low precision) | float num = 3.14; |
| double | Stores high-precision decimals | double num = 3.141592; |
13. Explain the difference between break and continue.
• break exits the loop completely.
• continue skips the current iteration and moves to the next loop cycle.
14. Write a C program that checks whether a number is even or odd using if-else.
#include <stdio.h>
int main() {
int num;
printf("Enter a number: ");
scanf("%d", &num);
if (num % 2 == 0)
printf("Even");
else
printf("Odd");
return 0;
}
15. Explain the purpose of a nested if-else statement with an example.
if (num > 0) {
if (num % 2 == 0)
printf("Positive even number");
else
printf("Positive odd number");
} else {
printf("Negative number or zero");
}
SECTION C: PROGRAMMING QUESTIONS – 5 Marks Each
21. Write a C program using a for loop to print numbers from 1 to 10.
#include <stdio.h>
int main() {
for (int i = 1; i <= 10; i++) {
printf("%d\n", i);
}
return 0;
}
22. Write a C program that accepts two numbers and swaps them using a function.
#include <stdio.h>
void swap(int *a, int *b) {
int temp = *a;
*a = *b;
*b = temp;
}
int main() {
int x, y;
printf("Enter two numbers: ");
scanf("%d %d", &x, &y);
swap(&x, &y);
printf("After swapping: %d %d", x, y);
return 0;
}
25. Write a C program to check if a given character is a vowel or consonant using
switch-case.
#include <stdio.h>
int main() {
char ch;
printf("Enter a character: ");
scanf("%c", &ch);
switch(ch) {
case 'a': case 'e': case 'i': case 'o': case 'u':
case 'A': case 'E': case 'I': case 'O': case 'U':
printf("Vowel");
break;
default:
printf("Consonant");
}
return 0;
}
SECTION D: LONG ANSWER QUESTIONS – 10 Marks Each
27. Write a simple file handling program in C that writes "Hello, World!" to a file and
then reads and prints its content.
#include <stdio.h>
int main() {
FILE *file = fopen("test.txt", "w");
fprintf(file, "Hello, World!");
fclose(file);
file = fopen("test.txt", "r");
char text[50];
fgets(text, 50, file);
printf("File content: %s", text);
fclose(file);
return 0;
}
28. Write a C program that reverses a string without using built-in functions.
#include <stdio.h>
#include <string.h>
int main() {
char str[100], temp;
int i, j;
printf("Enter a string: ");
gets(str);
j = strlen(str) - 1;
for (i = 0; i < j; i++, j--) {
temp = str[i];
str[i] = str[j];
str[j] = temp;
}
printf("Reversed string: %s", str);
return 0;
}
Now you have the complete CAT with all questions and answers in one file! Let
me know if you need anything else!