PF - Final Question Fall 2023
PF - Final Question Fall 2023
PF - Final Question Fall 2023
Premier University
Department of Computer Science and Engineering
Course Code: CSE 1113 Course Title: Programming Fundamentals
st
Session: Fall 2023 Semester: 1 Course Teacher: MH, AIH, MHN
NB: Answer any of four (4) from the following six (6) questions.
Each question carries equal marks.
Q1. a. Write a one-line statement using the conditional operator (?:) to find the 2 CO2
maximum value of two numbers a and b.
b. Write down the output of the following C program. 3 CO3
#include <stdio.h>
int main()
{
int i,j,k;
for(i=0, j=0, k=0; i<3; i++)
{
printf("%d %d %d\n",i, j, k);
j+=2;
k+=3;
}
}
c. Write a C program to find the difference between the maximum and 5 CO4
minimum elements of an array.
Sample input:
Number of elements: 4
Elements are: 45 67 89 34
Sample Output:
The difference is: 55
Q2. a. A year y is called a beautiful year if one of the following conditions 2 CO2
hold:
(i) y is divisible by 50.
(ii) y is divisible by 5 but not divisible by 10
Based on the above rules fill out the following condition marked with "???"
symbol to correctly perform the beautiful year testing:
if( ??? )
{
printf("A beautiful year!");
}
else
{
printf("Not a beautiful year!"); }
b. Write down the output of the following C program. 3 CO3
#include<stdio.h>
void main ()
{
int i;
for(i=0;i<10;i++)
{
i = 20;
printf("%d ",i);
}
}
c. Write a C program that takes a string as input and prints the difference 5 CO4
between the number of consonants and vowels.
Sample Input: lumbricoidus Sample Output: 2
Hint: Here the number of consonants is 7 and the number of vowels is 5.
Therefore, the difference between them is 2.
Q3. a. Rewrite the following code snippet using IF-ELSEIF ladder: 2 CO2
char op;
float num1, num2, result=0.0;
scanf("%f %c %f", &num1, &op, &num2);
switch(op){
case '+': result = num1 + num2;
break;
case '-': result = num1 - num2;
break;
default: printf("Invalid operator");}
printf("%.2f %c %.2f = %.2f", num1, op, num2, result);
}
b. The given program is written using a for loop. Rewrite this program using 3 CO3
a while loop instead of a for loop.
#include <stdio.h>
int main() {
int i, sum = 0;
for (i = 1; i <= 10; i++) {
sum += i;
if (i==5)
break;
}
printf("Sum = %d", sum);
return 0;
}
c. Write a C program to take an integer as input and check whether the number 5 CO4
is prime or not using a function named Isprime().
Hint: A prime number is a number that has only two factors, that is, 1 and
the number itself. For example, 2, 3, 5, 7 are prime numbers.
Q4. a. Write a C program to read 10 integer numbers and save in num.txt file. 2 CO1
b. A company will give bonus to its employees based on the gender and total 3 CO2
experience of working in this company:
1 represents the gender of male employees and 0 for the female employees.
If a male employee has more than 10 years working experience, he will
receive 10% bonus. However, the female employees will receive 12% bonus
if they have more than 10 years working experience. All the employees will
be given 5% bonus whatever the gender is if they have less than or equal 10
years of experience. The bonus will be given based on the basic salary.
Now write a C program to calculate the bonus amount where the gender,
working experience, and basic salary will be given.
c. Write the Output of the following program. Rewrite the program with a 2+3 CO4
union (The output should be the same).
#include <stdio.h>
struct student {
int id;
float marks;
};
int main()
{
struct student st1;
st1.id = 12;
st1.marks = 75;
printf("student ID: %d\n",st1.id);
printf("marks: %.2f",st1.marks);
return 0;
}
b. Write down a C program that will generate the following triangle of numbers CO3 3
(using loops).
1
2 2
3 3 3
4 4 4 4
5 5 5 5 5
c. Write a C program to count the number of even and odd integers stored in an CO4 5
array. Your program should read n integers from the user.
Sample input: 5
10 15 20 25 30
Sample Output: 3 2