Download as docx, pdf, or txt
Download as docx, pdf, or txt
You are on page 1of 5

Mid-term PF Lab

Registration No. :
FA22-BSE-046
Submitted By:
UNS YASEEN
Submitted To:
Sir Ahsan Maqsood
Subject:
Mid-term PF lab
Question No.01:

Write a program using function that find out the factorial of a


registration number?

Answer:

#include <iostream>

using namespace std;

int main() {

int rollNumber;

int factorial = 1;

cout << "Enter your roll number: ";

cin >> rollNumber;

int i = 1;

while (i <= rollNumber) {

factorial *= i;

i++;

cout << "Factorial of " << rollNumber << " is: " << factorial << endl;

return 0;

}
Output:

Enter your registration number: 46

Factorial of 46 is:
5502622159812088949850305428800254892961651752960000000000
Question No.02:

A class of ten students took a quiz. The grades (integers in the


range 0 to 100) for this quiz are available to you. Determine the class
average on the quiz???

Answer:

#include <iostream>

using namespace std;

int main() {

const int NUM_STUDENTS = 10;

int grades[NUM_STUDENTS];

int sum = 0;

float average;

cout << "Enter the quiz grades for " << NUM_STUDENTS <<endl;

for (int i = 0; i < NUM_STUDENTS; i++) {

cout << "Student " << i + 1 << ": ";

cin >> grades[i];

sum += grades[i];

average = static_cast<float>(sum) / NUM_STUDENTS;

cout << "Class average: " << average << endl;

return 0;}
Output:

Enter the quiz grades for 10

Student 1: 91

Student 2: 76

Student 3: 88

Student 4: 60

Student 5: 72

Student 6: 85

Student 7: 74

Student 8: 90

Student 9: 63

Student 10: 70

Class average: 76.9

You might also like