#include <iostream>
#include <vector>
#include <cmath> // For pow()
using namespace std;
int main() {
int n;
vector<pair<int, double> > data; // Changed expected frequency to double
// Input the number of terms
cout << "Enter the number of terms: ";
cin >> n;
// Input observed and expected frequencies
for (int i = 0; i < n; ++i) {
int ob;
double ex; // Expected frequency is now a double
cout << "Enter the observed frequency " << i + 1 << ": ";
cin >> ob;
cout << "Enter the expected frequency " << i + 1 << ": ";
cin >> ex;
data.push_back(make_pair(ob, ex));
}
// Display the items
cout << "Items: ";
for (size_t i = 0; i < data.size(); ++i) {
cout << "(" << data[i].first << ", " << data[i].second << ") ";
}
cout << endl;
// Calculate the Chi-square value
double chi = 0;
for (size_t i = 0; i < data.size(); ++i) {
int o = data[i].first;
double e = data[i].second;
chi += pow(o - e, 2) / e;
}
cout << "Calculated Chi-square: " << chi << endl;
// Input critical value
double critical_value;
cout << "Enter the critical value for chi-square test: ";
cin >> critical_value;
// Check if we reject or accept the null hypothesis
if (chi > critical_value) {
cout << "Reject the null hypothesis" << endl;
} else {
cout << "Accept the null hypothesis" << endl;
}
return 0; }