PF Terminal
PF Terminal
Q1. Write the output of the following programs in the box provided (CLO1-C1) (10 marks)
a)
int main () {
int i,j;
for(i=0;i<7;i++){
j=i; Output
printf("B ");
while(j<2*i){
printf("A ");
j++;
}
printf("B\n");
}
}
b)
#include <stdio.h>
int main ()
{
int i;
char arr[]={'A','B','C','D','E','F','G'};
for(i=4;i>0;i--){
switch(arr[i]){ Output
case 'A':
printf("Apple\n");
break;
case 'B':
printf("Ball\n");
break;
case 'C':
printf("Cat\n");
break;
case 'D':
printf("Doll\n");
break;
default:
printf("Not Present\n");
}
}
}
COMSATS University Islamabad (CUI)
Islamabad Campus
Department of Electrical & Computer Engineering
Terminal Exam Spring 2022
CSC141 Introduction to Computer Programming
Class BEE 2A
Marks: 40 Time: 2 hours, 30 minutes
Date: 1st July 2022 Instructor: Dr Junaid Ahmed
Q2. If the ages of Asad, Ali and Umer are input through the keyboard, write a program to
determine the youngest of the three. (CL02-C2) (5 marks)
Q3. Write a program to enter 10 numbers. At the end it should display the count of positive
numbers, negative numbers and zeros entered. (CL02-C2) (10 marks)
Q4. Write a function that calculates minimum and maximum of 10 numbers; this function can have
maximum 4 parameters. Write a program that inputs 10 numbers, finds their minimum and
maximum using your function and displays the result on screen.
(CLO3-C3) (10 Marks)
Q5. Write a program that takes the number of students in a class then inputs their data (name and
age) using the data structure given below and saves the data in a file names “class.bin”.
Hint: Dynamic memory allocation is required.
struct data{
char name[30];
int age; (CLO3-C3) (15 + 5 (bonus) Marks)
};