Computer Programming
Part 3. Problem 1 Write a function that prints 100 random numbers Problem 2 Write a function that calculates average grade of students Problem 3 Write a function to find gcd of two numbers. Header should be like this: int gcd(int num1, int num2)
//gcd
#include <iostream>
using namespace std;
int gcd(int num1, int num2) {
while (num2 != 0) {
int temp = num2;
num2 = num1 % num2;
num1 = temp;
}
return num1;
}
int main() {
int a, b;
cout << "Enter two numbers: ";
cin >> a >> b;
cout << "GCD = " << gcd(a, b);
return 0;
}
😭9❤1
Computer Programming
Part 3. Problem 1 Write a function that prints 100 random numbers Problem 2 Write a function that calculates average grade of students Problem 3 Write a function to find gcd of two numbers. Header should be like this: int gcd(int num1, int num2)
// Problem 1
#include <iostream>
#include <cstdlib> // rand(), srand()
#include <ctime> // time()
using namespace std;
int main() {
srand(time(0)); // Har safar boshqa natija chiqishi uchun
for (int i = 0; i < 100; i++) {
cout << rand() << " ";
}
return 0;
}
😭11❤3
Computer Programming
Part 3. Problem 1 Write a function that prints 100 random numbers Problem 2 Write a function that calculates average grade of students Problem 3 Write a function to find gcd of two numbers. Header should be like this: int gcd(int num1, int num2)
// Problem 2
#include <iostream>
using namespace std;
int main() {
int n, grade, sum=0;
cout << "Enter the number of students(1-100): "; cin>>n;
for (int i = 1; i <= n; i++) {
cout<<"Enter the grade of student "<<i<<" (0-100): "; cin>>grade;
sum+=grade;
}
cout<<"Average grade: "<<sum/n;
return 0;
}❤3