Actully i have a exam tomorrow iam sending to you
previous year ques paper i want answer for that ques
paper remember every question contain 7 marks so you
give me answer for 7 marks and also iam reading these
ques paper so you give me answers in understandble and
readable
Thanks, Praveen! I see your previous year question paper clearly. Since each question
carries 7 marks and needs to be easy to understand, I’ll write the answers in a clear and
exam-ready style.
I'll now start preparing answers unit-wise, each question for 7 marks, in simple and
understandable format.
✅ UNIT-I
1a. Discuss briefly about various Computer Programming Languages. (7M)
[Answer will include types of languages: machine, assembly, high-level, and examples like
C, Java, Python.]
1b. Write an algorithm for finding factorial of a number and draw flowchart. (7M)
[Includes step-by-step algorithm and a basic flowchart.]
OR
2a. Write an algorithm & C program for finding area of a triangle. (7M)
[Answer with algorithm and full C code.]
2b. Briefly explain about different operators in C. (7M)
[Types: Arithmetic, Relational, Logical, Assignment, Bitwise, etc.]
✅ UNIT-II
3a. Difference between switch & else-if with example. (7M)
[Conceptual difference with sample C code.]
3b. What is the purpose of do-while and while loops? Discuss usage. (7M)
[Explains syntax, difference, use cases.]
OR
4a. Develop a C program for printing the following pattern on the screen: (7M)
markdown Copy Edit
*
**
***
****
*****
4b. Explain about selection statements in C with example. (7M)
[Includes if , if-else , nested if , switch statements.]
✅ UNIT-III
5a. What is an array? How to create and access it? Explain with example. (7M)
[Definition, syntax, example.]
5b. Explain different string functions with examples. (7M)
[strcpy, strcat, strlen, strcmp, etc.]
OR
6a. Write a C program to reverse the contents of an integer array without using another
array. (7M)
[Full code with logic.]
6b. Write a C program to interchange the largest and smallest elements in an array.
(7M)
[Simple program with explanation.]
✅ UNIT-IV
7a. Briefly explain about storage classes. Scope and lifetime. (7M)
[auto, static, extern, register – with examples.]
7b. Develop a C program using pointers to compute the sum of all elements stored in
an array. (7M)
[Code + explanation.]
OR
8a. What is recursion? Explain with an example. (7M)
[Definition + example of factorial or Fibonacci.]
8b. Explain call by value and call by reference in functions. (7M)
[Difference + examples.]
Let me know if you want me to start with Unit I or you want all units one by one now?
all units one by one
Great! Let’s begin with Unit-I. I’ll provide all answers in a clear, understandable format
suitable for a 7-mark answer. You can copy them into your notes or revise directly.
✅ UNIT-I
1a. Discuss briefly about various Computer Programming
Languages. (7 Marks)
Computer programming languages are tools used to write instructions for a computer to
perform specific tasks. They are categorized as:
1. Machine Language:
Lowest-level language.
Written in binary (0s and 1s).
Directly understood by the computer.
Hard to learn and debug.
2. Assembly Language:
Uses mnemonics like MOV, ADD, SUB, etc.
Easier than machine language but still low-level.
Requires an assembler to convert to machine code.
3. High-Level Languages (HLL):
Easy to read and write (close to English).
Examples: C, C++, Java, Python.
Requires a compiler or interpreter.
4. Procedural Languages:
Follows step-by-step instructions.
Example: C.
5. Object-Oriented Languages:
Based on objects and classes.
Example: C++, Java.
6. Scripting Languages:
Used for automation and web development.
Example: Python, JavaScript.
✅ Conclusion: Programming languages help communicate with computers. Choice
depends on the application, ease of use, and performance requirements.
1b. Write an algorithm for finding factorial of a number and draw
flowchart. (7 Marks)
✅ Algorithm:
vbnet Copy Edit
Step 1: Start
Step 2: Read number n
Step 3: Initialize fact = 1
Step 4: Repeat from i = 1 to n
fact = fact * i
Step 5: Display fact
Step 6: Stop
✅ Flowchart:
(You can draw this in your exam)
less Copy Edit
[Start]
|
[Read n]
|
[Set fact = 1, i = 1]
|
[i <= n?] --No--> [Display fact] --> [End]
|
Yes
|
[fact = fact * i]
[i = i + 1]
|
[Go back to i <= n?]
2a. Write an algorithm & C Program for finding area of a triangle.
(7 Marks)
✅ Algorithm:
vbnet Copy Edit
Step 1: Start
Step 2: Read base and height
Step 3: area = (0.5) * base * height
Step 4: Display area
Step 5: Stop
✅ C Program:
c Copy Edit
#include <stdio.h> int main() { float base, height, area; printf("Enter base
and height: "); scanf("%f%f", &base, &height); area = 0.5 * base * height;
printf("Area of triangle = %.2f\n", area); return 0; }
2b. Briefly Explain About Different Operators in C. (7 Marks)
In C, operators are symbols used to perform operations. Types of operators:
1. Arithmetic Operators:
+, -, *, /, %
Used for basic calculations.
2. Relational Operators:
== , != , > , < , >= , <=
Used to compare values.
3. Logical Operators:
&& , || , !
Used for logical operations (AND, OR, NOT).
4. Assignment Operators:
= , += , -= , *= , /= , %=
Assign values to variables.
5. Increment/Decrement Operators:
++ , --
Used to increase/decrease value by 1.
6. Bitwise Operators:
& , | , ^ , ~ , << , >>
Used for bit-level operations.
7. Conditional (Ternary) Operator:
condition ? true_value : false_value;
✅ Conclusion: Operators are essential to perform operations in C programs.
Let me know when you’re ready for UNIT-II.
yes
Awesome! Here's the complete set of answers for ✅ UNIT-II, written clearly for 7 marks
each.
✅ UNIT-II
3a. Differentiate between Switch Statement & Else If with Example.
(7 Marks)
✅ if-else Statement:
Used when multiple range-based conditions or logical conditions are involved.
Supports relational and logical expressions.
Flexible but sometimes less readable.
✅ switch Statement:
Used when checking equality of a variable against multiple constant values.
Only works with integers, characters (not conditions or ranges).
Cleaner for multiple choices based on same variable.
✅ Example Using if-else :
c Copy Edit
int n = 2; if (n == 1) printf("One"); else if (n == 2) printf("Two"); else
printf("Other");
✅ Example Using switch :
c Copy Edit
int n = 2; switch (n) { case 1: printf("One"); break; case 2: printf("Two");
break; default: printf("Other"); }
✅ Conclusion:
Use switch when values are fixed and known. Use if-else for ranges or complex logic.
3b. What is the purpose of do while and while loops? Discuss their
usage. (7 Marks)
✅ while Loop:
Checks condition before executing the loop.
Entry-controlled loop.
c Copy Edit
int i = 1; while (i <= 5) { printf("%d ", i); i++; }
✅ do while Loop:
Executes the loop at least once, checks condition after.
Exit-controlled loop.
c Copy Edit
int i = 1; do { printf("%d ", i); i++; } while (i <= 5);
✅ Key Differences:
Feature while do-while
Condition Check Before loop body After loop body
Execution May not run if false Runs at least once
Use Case When condition may be false When body must run once
✅ Conclusion:
Choose do-while when the loop must run at least once. Use while when pre-checking is
needed.
4a. C program to print the following pattern: (7 Marks)
markdown Copy Edit
*
**
***
****
*****
✅ C Program:
c Copy Edit
#include <stdio.h> int main() { int i, j; for (i = 1; i <= 5; i++) { for (j =
1; j <= i; j++) { printf("*"); } printf("\n"); } return 0; }
✅ Output:
markdown
Copy Edit
*
**
***
****
*****
4b. Explain Selection Statements in C with Example. (7 Marks)
Selection statements help to make decisions in C.
✅ 1. if Statement:
c Copy Edit
if (a > b) printf("A is greater");
✅ 2. if-else Statement:
c Copy Edit
if (a > b) printf("A"); else printf("B");
✅ 3. else if Ladder:
c Copy Edit
if (a > b) printf("A"); else if (a == b) printf("Equal"); else printf("B");
✅ 4. switch Statement:
Used when multiple fixed values:
c Copy Edit
switch (ch) { case 1: printf("One"); break; case 2: printf("Two"); break;
default: printf("Other"); }
✅ Conclusion:
Selection statements guide the flow of control based on conditions and make programs
intelligent.
Let me know when you’re ready for ✅ UNIT-III!
yes
Great! Let’s now move to ✅ UNIT-III with clear and exam-ready answers, each suitable
for 7 marks.
✅ UNIT-III
5a. What is an array? How to create elements and access it? Explain
with example. (7 Marks)
✅ What is an Array?
An array is a collection of similar data types stored in contiguous memory locations.
Elements are accessed using index (starting from 0).
✅ Syntax:
c Copy Edit
datatype array_name[size];
✅ Example:
c Copy Edit
int marks[5] = {90, 85, 75, 60, 95};
✅ Accessing Elements:
c Copy Edit
printf("%d", marks[0]); // prints 90 marks[2] = 80; // modifies 3rd element
✅ Program to input and display array:
c Copy Edit
#include <stdio.h> int main() { int a[5], i; for(i=0; i<5; i++) { scanf("%d",
&a[i]); } for(i=0; i<5; i++) { printf("%d ", a[i]); } return 0; }
✅ Conclusion: Arrays help store multiple values under a single variable name and
simplify data handling.
5b. Explain different string functions with examples. (7 Marks)
String functions are available in string.h header file in C.
✅ Common String Functions:
1. strlen(str) – Returns the length of the string.
c Copy Edit
int len = strlen("Hello"); // Output: 5
2. strcpy(dest, src) – Copies source string to destination.
c Copy Edit
char a[10], b[10] = "Hi"; strcpy(a, b); // a = "Hi"
3. strcat(str1, str2) – Appends str2 to str1.
c Copy Edit
char a[20] = "Hello ", b[] = "World"; strcat(a, b); // a = "Hello World"
4. strcmp(str1, str2) – Compares two strings.
c Copy Edit
int x = strcmp("abc", "abc"); // x = 0 (equal)
✅ Example Program:
c Copy Edit
#include <stdio.h> #include <string.h> int main() { char a[20] = "Good", b[10]
= "Morning"; strcat(a, b); printf("%s", a); // Output: GoodMorning return 0; }
6a. C Program to Reverse an Array Without Using Another Array. (7
Marks)
✅ Code:
c Copy Edit
#include <stdio.h> int main() { int a[5] = {1, 2, 3, 4, 5}; int i, temp; for(i
= 0; i < 5/2; i++) { temp = a[i]; a[i] = a[4 - i]; a[4 - i] = temp; } for(i =
0; i < 5; i++) { printf("%d ", a[i]); } return 0; }
✅ Output:
Copy Edit
5 4 3 2 1
✅ Note: It uses swapping logic without extra array.
6b. C Program to Interchange Largest and Smallest Elements in an
Array. (7 Marks)
✅ Code:
c Copy Edit
#include <stdio.h> int main() { int a[5] = {10, 30, 5, 25, 100}; int i, max =
0, min = 0, temp; for(i = 1; i < 5; i++) { if(a[i] > a[max]) max = i; if(a[i]
< a[min]) min = i; } temp = a[max]; a[max] = a[min]; a[min] = temp; for(i = 0;
i < 5; i++) { printf("%d ", a[i]); } return 0; }
✅ Explanation:
Finds the index of largest & smallest elements.
Swaps their values.
Let me know when you’re ready for ✅ UNIT-IV!
yes
Perfect! Let's now cover ✅ UNIT-IV with full, clear answers suitable for 7 marks.
✅ UNIT-IV
7a. Briefly explain about Storage Classes in C: Scope and Lifetime.
(7 Marks)
✅ Storage classes define:
Scope (visibility)
Lifetime (how long the variable exists in memory)
Default initial value
✅ Types of Storage Classes in C:
Storage Class Scope Lifetime Default Value Keyword
auto Local Inside function Garbage auto (default)
register Local Inside function Garbage register
static Local/Global Entire program 0 static
extern Global Entire program 0 extern
✅ Explanation:
1. auto:
Default for local variables.
Created when function starts, destroyed when it ends.
c Copy Edit
void fun() { auto int a = 5; }
2. register:
Stored in CPU register for fast access.
c Copy Edit
register int speed = 100;
3. static:
Retains value between function calls.
c Copy Edit
void counter() { static int count = 0; count++; printf("%d ", count); }
4. extern:
Accesses global variables from other files.
c Copy Edit
extern int x;
✅ Conclusion: Storage classes control how variables behave in terms of memory, scope,
and life span in C.
7b. Develop a C program using pointers to compute the sum of all
elements stored in an array. (7 Marks)
✅ Code:
c Copy Edit
#include <stdio.h> int main() { int a[5] = {10, 20, 30, 40, 50}; int *ptr, sum
= 0, i; ptr = a; // pointer points to first element of array for(i = 0; i < 5;
i++) { sum += *(ptr + i); // pointer arithmetic } printf("Sum = %d\n", sum);
return 0; }
✅ Output:
ini Copy Edit
Sum = 150
✅ Explanation:
ptr is a pointer to the array.
Using *(ptr + i) accesses elements like a[i] .
8a. What is Recursion? Explain with an Example. (7 Marks)
✅ Definition:
Recursion is when a function calls itself to solve smaller parts of a problem.
✅ Key parts:
Base case: Stops the recursion.
Recursive case: Function calls itself.
✅ Example: Factorial using Recursion
c Copy Edit
#include <stdio.h> int fact(int n) { if(n == 0) return 1; // base case else
return n * fact(n - 1); // recursive case } int main() { int n = 5;
printf("Factorial = %d\n", fact(n)); return 0; }
✅ Output:
ini Copy Edit
Factorial = 120
✅ Conclusion: Recursion simplifies problems like factorial, Fibonacci, tower of Hanoi, etc.,
but must have a base case to prevent infinite calls.
8b. Explain Call by Value & Call by Reference in Functions. (7 Marks)
✅ 1. Call by Value:
Copies the actual value to the function.
Changes made inside function don’t affect original variable.
c Copy Edit
void modify(int x) { x = x + 5; }
✅ 2. Call by Reference:
Passes address of the variable.
Changes affect the original variable.
c Copy Edit
void modify(int *x) { *x = *x + 5; }
✅ Example Program:
c Copy Edit
#include <stdio.h> void addValue(int a) { a = a + 10; } void addRef(int *a) {
*a = *a + 10; } int main() { int x = 5; addValue(x); printf("Call by Value:
%d\n", x); // Output: 5 addRef(&x); printf("Call by Reference: %d\n", x); //
Output: 15 return 0; }
✅ Conclusion: Use call by reference when you want to modify original values, and call by
value when you just need a copy.
🎉 All four units are now complete! Let me know if you want:
A quick revision summary
MCQs or test practice
Or any other help for the exam!
Uploaded an image
iam send one more unit so give that answers also
Great! Let's now complete ✅ UNIT-V with clear, readable 7-mark answers.
✅ UNIT-V
9a. What are Unions? How are they different from Structures? Give
an Example. (7 Marks)
✅ Union:
A union is a user-defined data type in C.
It allows storing different data types in the same memory location.
Only one member can contain a value at a time.
✅ Syntax:
c Copy Edit
union Data { int i; float f; char str[20]; };
✅ Difference Between Structure and Union:
Feature Structure Union
Memory Allocates memory for all Allocates memory for largest
members member only
Access All members accessed at once Only one member at a time
Usage Used when all values needed Used when one value at a time
✅ Example:
c Copy Edit
#include <stdio.h> union Data { int i; float f; char str[20]; }; int main() {
union Data data; data.i = 10; printf("i = %d\n", data.i); data.f = 220.5;
printf("f = %.2f\n", data.f); return 0; }
✅ Note: When data.f is assigned, the previous value of data.i is lost.
9b. Discuss Structure Variable and Array of Structures in C. (7
Marks)
✅ Structure Variable:
A structure groups different data types into a single unit.
c Copy Edit
struct Student { int id; char name[20]; }; int main() { struct Student s1;
[Link] = 101; strcpy([Link], "Praveen"); }
✅ Array of Structures:
You can create an array of structure to hold multiple records.
c Copy Edit
struct Student { int id; char name[20]; }; int main() { struct Student s[3] =
{ {101, "Rahul"}, {102, "Asha"}, {103, "John"} }; for(int i = 0; i < 3; i++) {
printf("%d %s\n", s[i].id, s[i].name); } }
✅ Conclusion: Structures help organize data efficiently, and arrays of structures help
manage a group of records.
10a. Develop a C program to append the contents of one file to
another file. (7 Marks)
✅ Code:
c Copy Edit
#include <stdio.h> int main() { FILE *f1, *f2; char ch; f1 =
fopen("[Link]", "r"); // source file f2 = fopen("[Link]", "a"); //
destination file if (f1 == NULL || f2 == NULL) { printf("Error in opening
file!"); return 1; } while ((ch = fgetc(f1)) != EOF) { fputc(ch, f2); }
printf("Contents appended successfully."); fclose(f1); fclose(f2); return 0; }
✅ Explanation:
[Link] content is appended at the end of [Link] .
fgetc reads each character; fputc writes it.
10b. What do you mean by Command-Line Arguments? Give an
Example. (7 Marks)
✅ Command-line arguments:
Arguments passed to main() from the command line.
Syntax:
c Copy Edit
int main(int argc, char *argv[])
argc : Number of arguments
argv[] : Array of arguments (as strings)
✅ Example Program:
c Copy Edit
#include <stdio.h> int main(int argc, char *argv[]) { if (argc < 3) {
printf("Usage: program name arg1 arg2\n"); return 1; } printf("First argument:
%s\n", argv[1]); printf("Second argument: %s\n", argv[2]); return 0; }
✅ If you run:
bash Copy Edit
./[Link] Hello World
✅ Output:
sql Copy Edit
First argument: Hello
Second argument: World
✅ Conclusion: Command-line arguments are useful to pass input without hardcoding or
using scanf .
✅ UNIT-V Done! Now all units are completed in an exam-ready format.
Would you like:
Summary Notes?
Quick Revision Sheet?
Practice MCQs?
Let me know how else I can help you revise quickly.
yeah
Great! Since all 5 units are now covered and you're preparing for
tomorrow's Programming in C exam, here are 3 quick add-ons to boost your revision:
✅ Quick Summary Sheet (One-Liners)
Topic Quick Summary
Data Types C supports int, float, char, double, etc.
Control Statements if , if-else , switch , while , do-while , for
Functions Use call by value and call by reference
Recursion Function calling itself
Arrays Collection of similar data types
Strings Sequence of characters ending with \0
Structures Group of variables of different types
Unions Like structures, but shares memory
Pointers Stores address of another variable
File Handling fopen , fclose , fgetc , fputc , fprintf , fscanf
Command-line Args Passed using main(int argc, char *argv[])
✅ Top 5 Exam Tips
1. Write Syntax + Output if applicable
2. Use Simple Language – avoid complex words
3. Draw Flowcharts or Patterns Clearly
4. Mention Example Programs (even if short)
5. Label Each Section (e.g., Definition, Example, Explanation)
✅ Do You Want?
🧠 MCQs for Practice
📑 Printable PDF of all answers
📊 One-page Mind Map
👨💻 Online Compiler Links for practicing
Just reply with what you want and I’ll send it right away. All the best, Praveen – you got
this! 💪📚