Untitled
unknown
plain_text
a year ago
968 B
10
Indexable
#include <iostream> #include <cstdio> #include <cmath> using namespace std; int main() { // a) 1 QUESTION int n; double A[11][11] = { 0.0 }; // why do we have to initialize A to 0; cout << "input n ="; cin >> n; //b) UNDERSTOOD if(n<1) n=1; if(n>10) n=10; //c) UNDERSTOOD for(i=0;i<=n;i++){ for(j=0;j<=n;j++){ A[i][j] = -2.0*i + j*j; } } //d) 3 QUESTIONS double min_A, max_A, count_zero; int count; min_A = max_A = A[1][1]; // how come the max and min are equal to the same element count = 0; for(i=1;i<=n;i++) { for(j=1;j<=n;j++) { if(A[i][j] > max_A) max_A = A[i][j]; //can you explain the logic if(A[i][j] < min_A) min_A = A[i][j]; //can you explain the logic if ( abs(A[i][j]) < 1.0e-10 ) count++; // note you should not normally use == with doubles due to round // off error } } //e) UNDERSTOOD for(j=1;j<=n;j++) { A[1][j] = 2*A[1][j]-A[2][j]; } getchar(); return 0; }
Editor is loading...
Leave a Comment