1. What is an algorithm? An algorithm is a step-by-step procedure to solve a problem. Finite steps Logical sequence Definite input/output Clear and unambiguous steps 2. What is a flowchart? A flowchart is a graphical representation of a process or algorithm using symbols like oval, rectangle, diamond, arrows etc. 3. Draw any two flowchart symbols. Oval: Start/Stop Rectangle: Process Diamond: Decision Parallelogram: Input/Output 4. What are the various data types in C? int float char double void 5. What is a programming language? A programming language is a formal language used to write instructions that a computer can understand and execute. 6. What is pseudo-code? Pseudo-code is an informal, English-like way of writing an algorithm without strict syntax. 7. Define compiler. A compiler is a program that translates the entire source code of a high-level language into machine code. 8. What is interpreter? An interpreter translates and executes programs line-by-line. 9. Algorithm to find factorial. Start Read $n$ Set $f = 1$ Repeat $i = 1$ to $n$: $f = f \times i$ Print $f$ Stop 10. Algorithm to print Fibonacci series. Start Read $n$ Set $a=0, b=1$ Print $a, b$ Loop $i=3$ to $n$: $c = a + b$, print $c$, $a = b$, $b = c$ Stop 11. Differences between machine language and assembly language. Machine Language Assembly Language Binary 0s & 1s Uses mnemonics (ADD, SUB) Hard to understand Easy to understand Fast execution Slower than machine code Hardware dependent Hardware dependent 12. Explain structure of a C program. A C program typically contains: Header files (e.g., <stdio.h> ) Global variables main() function Local declarations Statements User-defined functions 13. Explain history of C language. Developed by Dennis Ritchie In 1972 at Bell Laboratories Evolved from B and BCPL languages Used for system programming and OS development 14. Program to check even/odd. #include <stdio.h> int main() { int n; printf("Enter an integer: "); scanf("%d", &n); if(n % 2 == 0) { printf("Even\n"); } else { printf("Odd\n"); } return 0; } 15. C program to find largest of two numbers. #include <stdio.h> int main() { int a, b; printf("Enter two numbers: "); scanf("%d%d", &a, &b); if(a > b) { printf("%d is larger\n", a); } else { printf("%d is larger\n", b); } return 0; } 16. Write if-else statement with example. The if-else statement is used for decision-making, executing one block of code if a condition is true, and another if it's false. Example: if(a > b) { printf("A is greater\n"); } else { printf("B is greater\n"); } C Programming Examples 1. Even-Odd Number #include <stdio.h> int main() { int n; printf("Enter number: "); scanf("%d", &n); if(n % 2 == 0) printf("Even\n"); else printf("Odd\n"); return 0; } 2. Biggest of Two Numbers #include <stdio.h> int main() { int a, b; printf("Enter two numbers: "); scanf("%d %d", &a, &b); if(a > b) printf("%d is bigger\n", a); else printf("%d is bigger\n", b); return 0; } 3. Factorial of a Number #include <stdio.h> int main() { int n, i, fact = 1; printf("Enter a number: "); scanf("%d", &n); for(i = 1; i <= n; i++) { fact = fact * i; } printf("Factorial %d\n", fact); return 0; } 4. Sum of First N Natural Numbers #include <stdio.h> int main() { int n, sum = 0; printf("Enter N: "); scanf("%d", &n); for(int i = 1; i <= n; i++) { sum += i; } printf("Sum = %d\n", sum); return 0; } 5. Check Prime Number #include <stdio.h> int main() { int n, i, flag = 0; printf("Enter a number: "); scanf("%d", &n); if (n <= 1) { // 0, 1, and negative numbers are not prime flag = 1; } else { for(i = 2; i <= n / 2; i++) { if(n % i == 0) { flag = 1; break; } } } if(flag == 0) printf("Prime\n"); else printf("Not Prime\n"); return 0; } 6. Fibonacci Series #include <stdio.h> int main() { int n, a = 0, b = 1, c; printf("Enter number of terms: "); scanf("%d", &n); printf("Fibonacci Series: "); if (n >= 1) printf("%d ", a); if (n >= 2) printf("%d ", b); for(int i = 3; i <= n; i++) { c = a + b; printf("%d ", c); a = b; b = c; } printf("\n"); return 0; } 7. Reverse a Number #include <stdio.h> int main() { int n, rev = 0, rem; printf("Enter a number: "); scanf("%d", &n); while(n != 0) { rem = n % 10; rev = rev * 10 + rem; n /= 10; } printf("Reverse = %d\n", rev); return 0; } 8. Palindrome Number #include <stdio.h> int main() { int n, temp, rev = 0, rem; printf("Enter a number: "); scanf("%d", &n); temp = n; // Store original number while(temp != 0) { rem = temp % 10; rev = rev * 10 + rem; temp /= 10; } if (n == rev) printf("Palindrome\n"); else printf("Not Palindrome\n"); return 0; } 9. Sum of Digits #include <stdio.h> int main() { int n, sum = 0, rem; printf("Enter a number: "); scanf("%d", &n); while(n != 0) { rem = n % 10; sum += rem; n /= 10; } printf("Sum of digits = %d\n", sum); return 0; } 10. Swapping Without Third Variable #include <stdio.h> int main() { int a, b; printf("Enter two numbers (a b): "); scanf("%d %d", &a, &b); printf("Before swap: a = %d, b = %d\n", a, b); a = a + b; // a now holds sum b = a - b; // b now holds original a a = a - b; // a now holds original b printf("After swap: a = %d, b = %d\n", a, b); return 0; }