Download as pdf or txt
Download as pdf or txt
You are on page 1of 3

19-SE-86

Arslan Haider

Programming Fundamental (SE-108)


(Lab MID)

Q#1: Describe the outputs of following Program? (5+5=10 marks, CLO 1)


a)
Ans:
Output: 012346789

*------------------------*
b)
Ans:

Output:
1

*------------------------*
Q#2: Illustrate the outputs of following program? (5+5=10 mark, CLO 1)
a)
Ans:

Output:
a
0.333333
num2 is greater
1

*------------------------*
b)
Ans:

Output:
*******
******
*****
****
***
**
*

*------------------------*
Q3: Write C++ Program to find perfect numbers between 2 intervals.
Note: A positive integer that is equal to the sum of its proper divisors
is a perfect number. The smallest perfect number is 6, which is the sum
of 1, 2, and 3. (6 marks, CLO 1)
Ans:

Output:
C++ Codes:

#include <iostream>
using namespace std;

bool Perfect(int no)


{
int i = 0;
int sum = 0;

while (i++ < no)


{
if (no % i == 0 && i < no)
{
sum += i;
}
}
return sum == no;
}

int main()
{
float first;
float second;
cout << "Enter the intervals : ";
cin >> first >> second;
cout<< endl;
cout << "Perfect numbers between " << first << " and " << second << " :
is ";
for (int i = first; i <= second; i++)
{
if (Perfect(i))
{
cout << i <<", ";
}
}

return 0;
}

You might also like