FIRST YEAR UNIVERSITY EXAM – C PROGRAMMING DETAILED SOLVED ANSWERS
Q1. Short Answers (Detailed)
Define Algorithm: An algorithm is a finite sequence of well-defined steps to solve a problem and
must terminate.
Explain printf(): A standard C library function to print formatted output (from stdio.h).
Data Types: Primary – int, float, char, double; Derived – arrays, pointers, structures.
C is high level – True. It supports both low-level and high-level operations.
Types of Arrays: 1D, 2D, and multidimensional arrays.
C Token: Smallest elements – keywords, identifiers, constants, operators, symbols.
Types of Loops: for, while, do-while loops.
Define Recursion: Function calling itself with a base condition.
Compiler: Converts entire source code into machine code before execution.
Keyword: Reserved words like int, if, for that cannot be used as variable names.
Q2. Detailed Answers
Flowchart Example (Describe shapes: Start → Input → Process → Output → Stop)
Library vs User-defined Functions: Library functions are predefined (printf). User-defined functions
are created by the programmer.
2-D Array Declaration Example:
int a[3][3];
Ternary Operator Example:
int max = (a > b) ? a : b;
Swap Program:
#include <stdio.h>
int main() {
int a, b, temp;
printf("Enter two numbers: ");
scanf("%d %d", &a, &b);
temp = a;
a = b;
b = temp;
printf("After swap: %d %d", a, b);
return 0;
}
Q3. Detailed Answers
Area of Circle Program:
#include <stdio.h>
int main() {
double r, area;
printf("Enter radius: ");
scanf("%lf", &r);
area = 3.14159 * r * r;
printf("Area = %.4lf", area);
return 0;
}
Factorial Program:
#include <stdio.h>
int main() {
int n, i;
unsigned long long fact = 1;
scanf("%d", &n);
for(i = 1; i <= n; i++)
fact *= i;
printf("%llu", fact);
return 0;
}
If-Else Example:
#include <stdio.h>
int main() {
int n;
scanf("%d", &n);
if(n % 2 == 0)
printf("Even");
else
printf("Odd");
return 0;
}
Q4. Detailed Answers
Transpose of Matrix:
#include <stdio.h>
int main() {
int m, n, i, j;
scanf("%d %d", &m, &n);
int a[m][n], t[n][m];
for(i=0;i<m;i++)
for(j=0;j<n;j++)
scanf("%d", &a[i][j]);
for(i=0;i<m;i++)
for(j=0;j<n;j++)
t[j][i] = a[i][j];
for(i=0;i<n;i++){
for(j=0;j<m;j++)
printf("%d ", t[i][j]);
printf("\n");
}
return 0;
}
Maximum of Two Numbers:
if(a > b)
printf("%d", a);
else
printf("%d", b);
While vs Do-While explanation included.
Q5. Short Note
Switch Statement Example:
switch(choice) {
case 1: printf("One"); break;
case 2: printf("Two"); break;
default: printf("Invalid");
}
Variable Definition: A variable is a named memory location. Rules: must start with letter/underscore,
cannot use keywords, case-sensitive.