33 exercises across functions, recursion, pointers, structures, unions, and file handling
Grade XII • Computer Science Lab • Capstone ⏱️ ~45–50 minBrief Intro — C Programming II Lab
33 exercises, seven walls of C skills — and at the end, you build your own program. This lab walks you through all 33 official C Programming II exercises: from basic functions to recursive algorithms, from pointer memory tricks to file storage. Each task builds on what you learned in the theory pair, and you'll predict outputs before checking your work.
The final Capstone Build asks you to design your own small C program — a menu-driven student-mark analyzer, a calculator with functions, or a person-record system with file save-load — combining several C-II concepts into something you can call your own.
Basic functions without decisions or loops.
Predict the output of C functions, then verify your answer against pre-computed results.
Task 1: Hello and Arithmetic
Write C functions for hello world and arithmetic operations.
Answer: void hello() { printf("Hello world"); } For arithmetic: return a+b for sum, a-b for difference, a*b for product, a/b for quotient, a%b for remainder.
Task 2: Interest, Areas, and Conversions
Write C functions for interest calculation, geometric formulas, and temperature conversion.
Answer: Interest: return (P*T*R)/100. Rectangle area: return length*width. Circle area: return 3.14159*r*r. Cube volume: return side*side*side. Fahrenheit to Celsius: return (F-32)*5/9. Square: return n*n.
Functions using if-else and switch for conditional logic.
Task 3: Comparisons with if-else
Write C functions for comparison and classification.
Answer: Greater: if (a > b) return a; else return b. Negative/positive: if (n < 0) return "negative"; else return "positive". Odd/even: if (n % 2 == 0) return "even"; else return "odd". Greatest of three: compare a with b, then compare result with c.
Task 4: Switch Case Statements
Write C functions using switch for multi-way branching.
Answer: Days: switch(day) { case 1: printf("Monday"); break; ... case 7: printf("Sunday"); }. Vowel: switch(ch) { case 'a': case 'e': case 'i': case 'o': case 'u': printf("vowel"); break; default: printf("consonant"); }
Functions using for, while, and do-while for repetition.
Task 5: Counting Loops
Write C functions for counting and summing with loops.
Answer: Hello N times: for(i=0; i
Task 6: Digit Work
Write C functions for reversing numbers and checking palindromes.
Answer: Reverse: while(n>0) { digit = n%10; rev = rev*10 + digit; n = n/10; }. Palindrome: store original, compute reverse, if(original == rev) then palindrome.
Task 7: Arrays
Write C programs for array operations.
Answer: Pass/fail: for(i=0; i<5; i++) { scanf("%d", &marks[i]); if(marks[i]>=40) pass++; else fail++; }. Bubble sort: for(i=0; i<9; i++) for(j=0; j<9-i; j++) if(arr[j] > arr[j+1]) swap.
Functions that call themselves for elegant problem-solving.
Task 8: Factorial and Fibonacci
Write recursive C functions for factorial and Fibonacci series.
Answer: Factorial: int factorial(int n) { if(n <= 1) return 1; return n * factorial(n-1); }. Fibonacci: int fib(int n) { if(n <= 1) return n; return fib(n-1) + fib(n-2); }. Call fib(0), fib(1), ..., fib(n-1) for series.
Variables that hold memory addresses for direct memory manipulation.
Task 9: Pointer Basics
Write C programs for pointer declaration, assignment, and NULL.
Answer: Pointer declare: int *ptr; Assign: ptr = &var; Access: printf("%d", *ptr); NULL: int *ptr = NULL; if(ptr == NULL) printf("Pointer is NULL");
Task 10: Swap by Value vs Address
Write C functions to swap integers using call by value and call by address.
Answer: Call by value: void swap(int a, int b) { int temp = a; a = b; b = temp; } — caller unchanged. Call by address: void swap(int *a, int *b) { int temp = *a; *a = *b; *b = temp; } — caller swapped via addresses.
User-defined data types and persistent data storage.
Task 11: Structures and Unions
Write C programs for struct Person, distance addition, and sizeof comparison.
Answer: Struct Person: struct Person { char name[50]; int id; float salary; }; Access with p.name, p.id, p.salary. Distance carry: if(inches >= 12) { feet++; inches -= 12; }. Sizeof: printf("Struct: %d, Union: %d", sizeof(struct), sizeof(union));
Task 12: File Handling
Write C programs to write integer to file and read it back.
Answer: Write: FILE *fp = fopen("data.txt", "w"); if(fp != NULL) { fprintf(fp, "%d", num); fclose(fp); }. Read: FILE *fp = fopen("data.txt", "r"); if(fp != NULL) { fscanf(fp, "%d", &num); printf("%d", num); fclose(fp); }
Capstone Build — Your Own C Program
Design and implement your own small C program combining several C-II concepts. Choose one option:
Combine: functions, decisions, loops, pointers/structs, and file handling. Make it personalized — choose your own feature names and display style.
Ready to test your knowledge?
Take the Assessment →