Quiz
Quiz
Quiz
PROGRAMMING FUNDAMENTAL
NAME: MUHAMMAD FAROOQ
ROLL NO: 014
MINHAJ UNIVERSITY LAHORE
………………………………………………………………
QUESTION NO 1:-
Write an iterative function void printPattern(num) that takes as a parameter a nonnegative
integer and generates the following pattern of stars to generate the following pat- tern.
#include <iostream>
cout<< endl;
int main() {
int num;
printPattern(num);
return 0;
QUESTION NO 2:-
#include <iostream>
#include <algorithm>
if (n < 3) {
return;
}
third = second;
second = first;
first = arr[i];
third = second;
second = arr[i];
} else if (arr[i] > third && arr[i] != first && arr[i] != second) {
third = arr[i];
if (third == INT_MIN) {
cout << "Array does not have three distinct elements" << endl;
} else {
cout << "The three largest distinct elements are: " << first << ", " << second << ", "
<< third << endl;
}
}
int main() {
findThreeLargest(arr, n);
return 0;
QUESTION NO 3:-
#include<iostream>
int main()
int a[5],b[5],c[10];
for(int i=0;i<5;i++)
cin>>a[i];
for(int i=0;i<5;i++)
{
cin>>b[i];
for(int i=0;i<5;i++)
c[i]=a[i];
c[5+i]=b[i];
for(int i=0;i<10;i++)
cout<<c[i]<<" ";
return 0;
}
QUESTION NO 4:-
int count = 0;
if (arr[i] == x) {
count++;
if (arr[i] > x) {
break;
return count;
int main()
int x = 3;
cout << "The number of occurrences of " << x << " is " << count << endl;
return 0;
}
QUESTION NO 5:-
#include <iostream>
#include<math.h>
void addition();
void subtraction();
void multiplication();
void division();
void cube();
void squar();
void sqrt();
void pow();
void factorial();
int main()
while (1)
int number;
switch (number)
case 1:
addition();
break;
case 2:
subtraction();
break;
case 3:
multiplication();
break;
case 4:
division();
break;
case 5:
cube();
break;
case 6:
squar();
break;
case 7:
sqrt();
break;
case 8:
pow();
break;
case 9:
factorial();
break;
case 0:
exit(0);
break;
default:
break;
return 0;
void addition()
int a,b;
cin>>a;
cin>>b;
void subtraction(){
cout<<"Enter the numbers to subtract: \n";
int a,b;
cin>>a;
cin>>b;
void multiplication(){
int a,b;
cin>>a;
cin>>b;
void division(){
float a,b;
cin>>a;
void cube(){
int a;
cin>>a;
void squar()
int a;
cin>>a;
void sqrt()
int a;
void pow()
int a;
cin>>a;
int b;
cout<<"Enter exponent";
cin>>b;
cout<<"The power of " << a << " and " << b << " is ""=" <<pow(a,b)
<<endl;
void factorial()
int a,fac=1;
for(int i=1;i<=a;i++)
fac=fac*i;
cout<<"The factorial of " << a << " is ""=" << fac <<endl;