Unit 1
Unit 1
2. Define program.
A program is a sequence of instructions written in a programming language that
performs a specific task.
o Rectangle: Process
o Diamond: Decision
o Finiteness
o Definiteness
o Input/Output
o Effectiveness
o Generality
o Algorithm:
1. Start
4. Output area
5. Stop
o Flowchart: Graphical depiction using input/output, process, and decision
symbols.
o Algorithm:
1. Start
4. Stop
o Algorithm:
1. Start
4. Stop
4o
You said:
unit 2
ChatGPT said:
Unit 2: Answers
1. Define:
o Datatype: Defines the type of data a variable can hold (e.g., int, float, char).
o I/O Function: Input and output functions in C (e.g., scanf and printf).
o Character Set: The set of characters recognized by the language (letters, digits,
symbols).
o Portability
o Modular programming
4. What is a preprocessor?
The preprocessor processes code before compilation. It handles directives like
#include, #define, and conditional compilation.e
6. What do you mean by header file? Write the name of any three header files.
A header file contains declarations for library functions and macros. Examples:
o #include<stdio.h>
o #include<math.h>
o #include<string.h>
1. Define problem
2. Design algorithm
Copy code
o Naming Rules:
▪ No special characters.
Copy code
#include<stdio.h>
int main() {
int num;
scanf("%d", &num);
return 0;
o int: Integer
o char: Character
o Arithmetic: +, -
o Relational: ==, !=
o Logical: &&, ||
o Arithmetic: *
o Relational: >
o Logical: &&
o Conditional: ?:
o Bitwise: &
o int: Integers
Copy code
#include<stdio.h>
int main() {
return 0;
Let me know if you'd like me to continue with Unit 3 or need further clarifications.
4o
You said:
ChatGPT said:
Unit 3: Answers
o if
o if-else
o else if
o switch
3. Explain any two conditional control statements with syntax and example:
o if-else:
Copy code
if (condition) {
} else {
Example:
Copy code
if (x > 0) printf("Positive");
else printf("Non-positive");
o switch:
Copy code
switch (variable) {
break;
default: // Code
Copy code
#include<stdio.h>
int main() {
char op;
int a, b, result;
switch (op) {
return 0;
Copy code
#include<stdio.h>
int main() {
temp = n;
while (temp != 0) {
temp /= 10;
if (n == reverse) printf("Palindrome");
return 0;
Copy code
#include<stdio.h>
int main() {
int a, b, c;
return 0;
Unit 4: Answers
Copy code
Copy code
Copy code
9. Advantages of arrays:
c
Copy code
int arr[3][3];
Copy code
Unit 5: Answers
Copy code
return_type function_name(parameters) {
// Function body
2. Parts of a function:
o Function declaration
o Function definition
o Function call
o Factorial calculation
7. Scope of variable:
Scope defines the lifetime and accessibility of a variable in a program.
Copy code
#include<stdio.h>
#include<math.h>
int main() {
scanf("%lf", &num);
result = sqrt(num);
return 0;
9. User-defined function:
Functions created by users to perform specific tasks.
Copy code
void display() {
printf("Hello, World!");
}
Copy code
int factorial(int n) {
if (n == 0) return 1;