# c++ loops

#include <iostream>
#include<cmath>
#include<ctime>
#include<string>
#include <iomanip>
#include <fstream>

using namespace std;

int main()
{
int counter = 1;
int number = 0;
int largest = 0;
int n;
cin >> n;
int occurrence = 0;

cout << "Please enter up to 10 numbers and I will print the largest one on the screen.\n\n";

while (counter <= n)
{
cout << "Number: ";
cin >> number;

if (largest < number)
{
largest = number;
occurrence = 1;

}
else if (number == largest)
{
occurrence++;
}
if (number == 0)
{
break;

}
counter++;
}

cout << "the largest number is "<<largest << endl;
cout << "  the occurrence count " << largest << " is " << occurrence << " time";

}
#include <iostream>
#include<cmath>
#include<ctime>
#include<string>
#include <iomanip>
#include <fstream>

using namespace std;

int main()
{

int f1 = 0, f2 = 1;
int nextTerm = 0;
for (int i = 1; i < 10; i++)
{
//print first 2 numbers
if (i == 1)
{
cout <<  f1<<" ";
continue;
}
if (i == 2)
{
cout << f2 << " ";
continue;
}

nextTerm = f1 + f2;
f1 = f2;
//make f2 = the next term
f2 = nextTerm;
cout << nextTerm<<" ";

}

}

#include <iostream>
#include<cmath>
#include<ctime>
#include<string>
#include <iomanip>
#include <fstream>

using namespace std;

int main()
{
for (int i = 0; i < 8; i++)
{
for (int k = 0; k <= i; k++)
{
cout << "  ";
}
for (int j = i; j < 8; j++)
{
cout <<" "<< static_cast<char>(j+97-i);

}
for (int j = 7; j >= i; j--)
{
cout << " " << static_cast<char>(j + 97 - i);
}
cout << "\n";
}

}

#include <iostream>
#include<cmath>
#include<ctime>
#include<string>
#include <iomanip>
#include <fstream>

using namespace std;

int main()
{

cout << "Enter two positive numbers ";
int n1,n2;
cin >> n1>>n2;
int d = 1;
int gcd = 1;

if (n1 < n2)
d = n1;
else
d = n2;
while (true)
{
if (n1 % d == 0 && n2 % d == 0) {
gcd = d;
break;
}

d--;
}

cout << "the CGD of " << n1 << " and " << n2 << " is " << gcd;

}

#include<iostream>
#include <fstream>
using namespace std;
void selectionSort(double list[], int listSize);
int main()
{
double list[] = { 3.4, 5, 3, 3.5, 2.2, 1.9, 2 };

selectionSort(list, 7);
for (int i = 0; i < 7; i++)
{
cout << list[i]<<" ";
}
}
//decreasing order
void selectionSort(double list[], int listSize)
{
for (int i = listSize-1; i >= 0 ; i--)
{
double currentMax = list[i];
int currentMaxIndex = i;
for (int j = i - 1; j >= 0; j--)
{
if (currentMax < list[j])
{
currentMax = list[j];
currentMaxIndex = j;
}
}
if (currentMaxIndex != i)
{
list[currentMaxIndex] = list[i];
list[i] = currentMax;
}

}
}
//increasing order
void selectionSort(double list[], int listSize)
{
for (int i = 0; i < listSize - 1; i++)
{
double currentMin = list[i];
int currentMinIndex = i;
for (int j = i + 1; j < listSize; j++)
{
if (currentMin > list[j])
{
currentMin = list[j];
currentMinIndex = j;
}
}
if (currentMinIndex != i)
{
list[currentMinIndex] = list[i];
list[i] = currentMin;
}

}
}