Course Title: CP Assignment No.3: Bahria University, Islamabad
Course Title: CP Assignment No.3: Bahria University, Islamabad
Assignment no.3
Example:
In some texts, it is customary to use n = 1. In that case, the first two terms are defined as 1 and 1 by
default, and therefore: F (1) = 1, 1, 2, 3, 5, 8, 13, 21, 34…….
Program:
#include<iostream>
#include<conio.h>
using namespace std;
int main()
{
int n1 = 0, n2 = 1, sum, number;
cout << "Enter the number of elements: ";
cin >> number;
cout << n1 << " " << n2 << " "; //printing 0 and 1
for (int i = 2; i < number; ++i) //loop starts from 2 because 0 and 1 are already printed
{
sum = n1 + n2;
cout << sum << " ";
n1 = n2;
n2 = sum;
}
_getch();
return 0;
}
Result/Output:
Q2. What is meant by selection sort using an array? Write a program to sort out an
array of 20 integers. Such that you need to user input the array values and sort
them in both ascending and descending order using the selection sort mechanism .
Result/Output:
Result/Output: