Blog
Programming Fundamentals Past Paper 2024 – BSCS, BSSE, BSIT | UOS
Download Programming Fundamentals Past Paper 2024 for BSCS, BSSE, and BSIT students of University of Sargodha (UOS). Ideal for first term exam prep.
Programming Fundamentals Past Paper 2024 – BSCS, BSSE, BSIT | UOS University of Sargodha
If you’re preparing for the BSCS, BSSE, or BSIT first term exams at the University of Sargodha (UOS), this Programming Fundamentals Past Paper 2024 is a must-have resource.
This paper is suitable for:
- Bachelor of Science in Computer Science (BSCS)
- Bachelor of Science in Software Engineering (BSSE)
- Bachelor of Science in Information Technology (BSIT)
Use this past paper to practice core programming concepts, understand question patterns, and get a clear idea of how to prepare for your upcoming Programming Fundamentals exam.
Programming Fundamentals Past Paper 2024 (text version)
University of Sargodha – BS 1st Term Examination 2024, IT/CS/SE
Paper: Programming Fundamentals (CMPC-101) · Time: 2:30 hours · Maximum marks: 40
Objective part (compulsory, 8 × 2)
- Evaluate the expression 2 – 3 % 5 * 8 / 2 – 1
- What is the address-of operator? Why is it used?
- Write the conditional operator used in C. How many operands does it take?
- Is the statement
int abc_cd = 6;valid or invalid? Give a reason. - What does the following code display?
int a = 3, b = 2, c = -2; if ((a - c) > 10 || (c < a - 3)) printf("%d\n", a + c); else printf("%d\n", b - a); - What is the scope and lifetime of a local variable?
- How is the constant value 3L interpreted – as float or double? Justify your answer.
- What will be displayed?
int *p, var = 4; p = &var; *p = *p - 2; printf("%d\n", var);
Subjective part (attempt any three, 8 marks each)
- Q.2 Write a program that accepts an integer from the user and passes it to a function that finds the sum of its factors that are less than half of the number. The result is displayed by main(). Example: 12 has factors 1, 2, 3, 4, 6 and 12; the sum of factors less than half of 12 is 1 + 2 + 3 + 4 = 10.
- Q.3 Write a program that accepts a string from the user and passes it to a function that finds the total number of characters in the string (not counting the null terminator). The result is displayed by main(). Example: “Fortune Teller” has 14 characters.
- Q.4 Write a program that displays the lower half of a diamond (7, 5, 3, 1 stars).
- Q.5 Write only the output of the following program in its correct format:
int i, j = 9, k = 2; for (i = 3; i < j; i = i + 4) { k = i + k / 2 + j; printf("%d\t%d\t%d\n", i - 1, j + 1, k / 2); j++; k += 2; } printf("%d\t%d\n", k - j, i + k); - Q.6 Create a structure named Book with data members subject (C-string) and price (float). Create three instances, find their average price and display the subject of the book(s) priced above the average.
Short questions solved
- % and * and / have equal precedence, left to right: 3 % 5 = 3, 3 * 8 = 24, 24 / 2 = 12; then 2 − 12 − 1 = −11.
- & (address-of) returns the memory address of a variable, e.g.
p = &x;. It is used to assign pointers and to pass variables by reference, e.g.scanf("%d", &x);. - The conditional (ternary) operator
condition ? expr1 : expr2takes three operands, e.g.max = (a > b) ? a : b; - Valid. Identifiers may contain letters, digits and underscores and must not start with a digit; abc_cd follows these rules.
- (a − c) = 5, which is not > 10, but c < a − 3 is −2 < 0, which is true, so the condition is true and it prints a + c = 1.
- A local variable’s scope is the block or function in which it is declared; its lifetime starts when control enters that block and ends when it exits (automatic storage), unless it is declared static.
- Neither: the suffix L makes 3L a long int constant. A floating constant needs a decimal point or exponent – 3.0 is double, 3.0f is float and 3.0L is long double.
- p points to var, so *p = *p − 2 changes var to 4 − 2; it prints 2.
Solved subjective questions
Q.2
#include <stdio.h>
int sumOfFactors(int n) {
int sum = 0;
for (int i = 1; 2 * i < n; i++) /* factors less than half of n */
if (n % i == 0)
sum += i;
return sum;
}
int main(void) {
int num;
printf("Enter an integer: ");
scanf("%d", &num);
printf("Sum of factors less than half of %d = %d\n", num, sumOfFactors(num));
return 0;
}Sample run: input 12 → output 10.
Q.3
#include <stdio.h>
int countChars(char s[]) {
int count = 0;
while (s[count] != '\0') /* stop at the null terminator */
count++;
return count;
}
int main(void) {
char str[100];
printf("Enter a string: ");
scanf(" %99[^\n]", str); /* reads spaces too */
printf("Number of characters = %d\n", countChars(str));
return 0;
}Sample run: “Fortune Teller” → 14 (the space is counted; the null terminator is not).
Q.4
#include <stdio.h>
int main(void) {
int rows = 4;
for (int i = 0; i < rows; i++) {
for (int s = 0; s < i; s++)
printf(" ");
for (int j = 0; j < 2 * (rows - i) - 1; j++)
printf("*");
printf("\n");
}
return 0;
}Output:
*******
*****
***
*Q.5 Output (values separated by tabs):
2 10 6
6 11 12
15 37Trace: i = 3: k = 3 + 1 + 9 = 13 → prints 2, 10, 6; then j = 10, k = 15. i = 7: k = 7 + 7 + 10 = 24 → prints 6, 11, 12; then j = 11, k = 26. i = 11 is not < 11, so the loop ends and it prints k − j = 15 and i + k = 37.
Q.6 (the paper says “having price than average price”; it means above average)
#include <stdio.h>
struct Book {
char subject[50];
float price;
};
int main(void) {
struct Book b[3];
float total = 0, avg;
for (int i = 0; i < 3; i++) {
printf("Enter subject of book %d: ", i + 1);
scanf(" %49[^\n]", b[i].subject);
printf("Enter price of book %d: ", i + 1);
scanf("%f", &b[i].price);
total += b[i].price;
}
avg = total / 3;
printf("Average price = %.2f\n", avg);
printf("Books priced above average:\n");
for (int i = 0; i < 3; i++)
if (b[i].price > avg)
printf("%s\n", b[i].subject);
return 0;
}All programs were compiled and tested with GCC.
Answers prepared by Shining Study for revision. Check them against your class notes and teacher’s guidance.
