Open study

is now brainly

With Brainly you can:

  • Get homework help from millions of students and moderators
  • Learn how to solve problems with step-by-step explanations
  • Share your knowledge and earn points by helping other students
  • Learn anywhere, anytime with the Brainly app!

A community for students.

how to use double in c programming?

Computer Science
I got my questions answered at brainly.com in under 10 minutes. Go to brainly.com now for free help!
At vero eos et accusamus et iusto odio dignissimos ducimus qui blanditiis praesentium voluptatum deleniti atque corrupti quos dolores et quas molestias excepturi sint occaecati cupiditate non provident, similique sunt in culpa qui officia deserunt mollitia animi, id est laborum et dolorum fuga. Et harum quidem rerum facilis est et expedita distinctio. Nam libero tempore, cum soluta nobis est eligendi optio cumque nihil impedit quo minus id quod maxime placeat facere possimus, omnis voluptas assumenda est, omnis dolor repellendus. Itaque earum rerum hic tenetur a sapiente delectus, ut aut reiciendis voluptatibus maiores alias consequatur aut perferendis doloribus asperiores repellat.

Join Brainly to access

this expert answer

SEE EXPERT ANSWER

To see the expert answer you'll need to create a free account at Brainly

i have a program. the types of my variables are float. But when I replace float with double, the program doesn't run right anymore
let me be specific...
this is my original program: ``` #include #include #include #include void menu(); void polyeval(); float pevalf(float *polynomial); void statalgo(); float tot(float *result); float meanf(float *ave); float stddevf(float *standarddev); void matrix(); int choice, cntr; int degree; float x, sum, peval, constant; float coefficient[10]; int dataNum; float data[10]; float total, mean, square, squaresum, stddev; int row, column, counter, ctr, choicemat, temp = 0; int mat1[3][3], mat2[3][3], summat[3][3], product[3][3], transpose[3][3]; main() { char yn[2]; while (1) { menu(); if (choice == 1) { while (1) { polyeval(); while (1) { printf("\n\n Repeat? "); scanf("%s", yn); yn[0] = toupper(yn[0]); if (yn[0] != 'Y' && yn[0] !='N') { system("cls"); printf("\n\n Invalid choice!"); printf("\n\n\n "); system("pause"); system("cls"); } else break; } if (yn[0] == 'Y') { system("cls"); continue; } else break; } } else if (choice == 2) { while (1) { statalgo(); while (1) { printf("\n\n Repeat? "); scanf("%s", yn); yn[0] = toupper(yn[0]); if (yn[0] != 'Y' && yn[0] !='N') { system("cls"); printf("\n\n Invalid choice!"); printf("\n\n\n "); system("pause"); system("cls"); } else break; } if (yn[0] == 'Y') { system("cls"); continue; } else break; } } else if (choice == 3) { while (1) { matrix(); while (1) { printf("\n\n Repeat? "); scanf("%s", yn); yn[0] = toupper(yn[0]); if (yn[0] != 'Y' && yn[0] !='N') { system("cls"); printf("\n\n Invalid choice!"); printf("\n\n\n "); system("pause"); system("cls"); } else break; } if (yn[0] == 'Y') { system("cls"); continue; } else break; } } else if (choice == 4) return 0; else continue; } } void menu() { system("cls"); printf("\n Main Menu"); printf("\n =========\n\n"); printf("\n 1) Polynomial Evaluation\n"); printf("\n 2) Statistical Algorithms\n"); printf("\n 3) Matrix Operations\n"); printf("\n 4) Exit\n"); printf("\n\n Choice > "); scanf("%d", &choice); system("cls"); } void polyeval() { while (1) { system("cls"); printf("\n POLYNOMIAL EVALUATION"); printf("\n =====================\n"); printf("\n Enter the degree of the polynomial "); scanf("%d", °ree); if (degree > 10 || degree < 0) { system("cls"); printf("\n\n Invalid choice!"); printf("\n\n\n "); system("pause"); system("cls"); continue; } if (degree > 0) { printf("\n Enter the value of x > "); scanf("%f", &x); } for (cntr = 0; cntr < degree; cntr ++) { printf("\n Enter the value of coefficient #%d > ", cntr + 1 ); scanf("%f", &coefficient[cntr]); } printf("\n Enter the value of the constant > "); scanf("%f", &constant); if (degree == 0) peval = constant; else pevalf(&peval); printf("\n\n The sum of the polynomial is %f\n", peval); printf("\n\n\n "); system("pause"); break; } } float pevalf(float *polynomial) { sum = coefficient[0]; for(cntr = 1; cntr < degree && cntr < 16; cntr++) sum = sum*x + coefficient[cntr]; *polynomial = sum*x + constant; } void statalgo() { while (1) { system("cls"); printf("\n STATISTICAL ALGORITHMS"); printf("\n ======================\n\n"); printf("\n Enter the number of the data "); scanf("%d", &dataNum); if (dataNum <= 0 || dataNum > 10) { system("cls"); printf("\n\n Invalid choice!"); printf("\n\n\n "); system("pause"); system("cls"); continue; } else { for (cntr = 0; cntr < dataNum; cntr++) { printf("\n\n Enter data %d > ", cntr + 1); scanf("%f", &data[cntr]); } system("cls"); printf("\n STATISTICAL ALGORITHMS"); printf("\n ======================\n\n"); printf("\n Select which one you wish to solve for\n"); printf("\n <1> Total\n"); printf("\n <2> Mean\n"); printf("\n <3> Standard Deviation\n"); printf("\n\n\n Choice > "); scanf("%d", &choice); if (choice == 1) { tot(&total); printf("\n\n The total is %f", total); } else if (choice == 2) { meanf(&mean); printf("\n\n The mean is %f", mean); } else if (choice == 3) { stddevf(&stddev); printf("\n\n The standard deviation is %f", stddev); } else { system("cls"); printf("\n\n Invalid choice!"); printf("\n\n\n "); system("pause"); system("cls"); break; } } printf("\n\n\n "); system("pause"); break; } } float tot(float *result) { *result = 0; for (cntr = 0; cntr < dataNum; cntr++) *result = *result + data[cntr]; } float meanf(float *ave) { tot(&total); *ave = total/dataNum; } float stddevf(float *standarddev) { meanf(&mean); squaresum = 0; for (cntr = 0; cntr < dataNum; cntr++) { square = (data[cntr] - mean) * (data[cntr] - mean); squaresum = squaresum + square; } *standarddev = sqrt(squaresum/dataNum); } void matrix() { while (1) { printf("\n Matrix Operations"); printf("\n =================\n"); printf("\n Enter the number of rows of each matrix > "); scanf("%d", &row); printf("\n\n Enter the number of columns of each matrix > "); scanf("%d",&column); if (row < 3 && row > 0 && column < 3 && column > 0) { printf("\n\n\n Enter the elements of the first matrix >\n\n "); for (cntr = 0; cntr < row; cntr++) for (counter = 0; counter < column; counter++) { printf("\n\t Enter element for Row %d Column %d > ", cntr + 1, counter + 1); scanf("%d", &mat1[cntr][counter]); } printf("\n\n\n Matrix 1 is >\n\n"); for (cntr = 0; cntr < row; cntr++) { for (counter = 0; counter < column; counter++) printf(" %d\t", mat1[cntr][counter]); printf("\n\n"); } printf("\n\n Enter the elements of the second matrix>\n "); for (cntr = 0; cntr < row; cntr++) for (counter = 0; counter < column; counter++) { printf("\n\t Enter element for Row %d Column %d > ", cntr + 1, counter + 1); scanf("%d", &mat2[cntr][counter]); } printf("\n\n\n Matrix 2 is >\n\n"); for (cntr = 0; cntr < row; cntr++) { for (counter = 0; counter < column; counter++) printf(" %d\t", mat2[cntr][counter]); printf("\n\n"); } printf("\n\n\n What do you want to do?\n"); printf("\n <1> Sum\n"); printf("\n <2> Product\n"); printf("\n <3> Transpose\n"); printf("\n\n Choice > "); scanf("%d", &choicemat); system("cls"); if (choicemat == 1) { printf("\n Matrix Operations"); printf("\n =================\n"); for (cntr = 0; cntr < row; cntr++) for (counter = 0; counter < column; counter++) summat[cntr][counter] = mat1[cntr][counter] + mat2[cntr][counter]; printf("\n The sum of the matrices is \n\n"); for (cntr = 0; cntr < row; cntr++) { for (counter = 0; counter < column; counter++) printf(" %d\t", summat[cntr][counter]); printf("\n\n"); } } else if (choicemat == 2) { printf("\n Matrix Operations"); printf("\n =================\n"); printf("\n The product of the matrices is \n\n"); for (cntr = 0; cntr < row; cntr++) { for (counter = 0; counter < column; counter++) { for (ctr = 0; ctr < row; ctr++) temp = temp + mat1[cntr][ctr]*mat2[ctr][counter]; product[cntr][counter] = temp; temp = 0; printf(" %d\t", product[cntr][counter]); } printf("\n\n"); } } else if (choicemat == 3) { printf("\n Matrix Operations"); printf("\n =================\n"); printf("\n Select matrix to transpose:\n"); printf("\n <1> Matrix 1\n"); printf("\n <2> Matrix 2\n"); printf("\n\n Choice > "); scanf("%d", &choice); system("cls"); if (choice == 1) { printf("\n Matrix Operations"); printf("\n =================\n"); for (cntr = 0; cntr < row; cntr++) for (counter = 0; counter < column; counter++) transpose[counter][cntr] = mat1[cntr][counter]; printf("\n The transpose of the first matrix is\n\n"); for (cntr = 0; cntr < column; cntr++) { for (counter = 0; counter < row; counter++) printf(" %d\t", transpose[cntr][counter]); printf("\n\n"); } printf("\n\n\n "); system ("pause"); } else if (choice == 2) { printf("\n Matrix Operations"); printf("\n =================\n"); for (cntr = 0; cntr < row; cntr++) for (counter = 0; counter < column; counter++) transpose[counter][cntr] = mat2[cntr][counter]; printf("\n The transpose of the second matrix is\n\n"); for (cntr = 0; cntr < row; cntr++ ) { for (counter = 0; counter < column; counter++ ) printf(" %d\t",transpose[counter][cntr]); printf("\n\n"); } printf("\n\n\n "); system("pause"); } } else { system("cls"); printf("\n\n Invalid choice!"); printf("\n\n\n "); system("pause"); system("cls"); break; } break; } else { system("cls"); printf("\n\n Invalid choice!"); printf("\n\n\n "); system("pause"); system("cls"); break; } } } ```

Not the answer you are looking for?

Search for more explanations.

Ask your own question

Other answers:

then this is the program that won't work ``` #include #include #include #include void menu(); void polyeval(); double pevalf(double *polynomial); void statalgo(); double tot(double *result); double meanf(double *ave); double stddevf(double *standarddev); void matrix(); int choice, cntr; int degree; double x, sum, peval, constant; double coefficient[10]; int dataNum; double data[10]; double total, mean, square, squaresum, stddev; int row, column, counter, ctr, choicemat, temp = 0; int mat1[3][3], mat2[3][3], summat[3][3], product[3][3], transpose[3][3]; main() { char yn[2]; while (1) { menu(); if (choice == 1) { while (1) { polyeval(); while (1) { printf("\n\n Repeat? "); scanf("%s", yn); yn[0] = toupper(yn[0]); if (yn[0] != 'Y' && yn[0] !='N') { system("cls"); printf("\n\n Invalid choice!"); printf("\n\n\n "); system("pause"); system("cls"); } else break; } if (yn[0] == 'Y') { system("cls"); continue; } else break; } } else if (choice == 2) { while (1) { statalgo(); while (1) { printf("\n\n Repeat? "); scanf("%s", yn); yn[0] = toupper(yn[0]); if (yn[0] != 'Y' && yn[0] !='N') { system("cls"); printf("\n\n Invalid choice!"); printf("\n\n\n "); system("pause"); system("cls"); } else break; } if (yn[0] == 'Y') { system("cls"); continue; } else break; } } else if (choice == 3) { while (1) { matrix(); while (1) { printf("\n\n Repeat? "); scanf("%s", yn); yn[0] = toupper(yn[0]); if (yn[0] != 'Y' && yn[0] !='N') { system("cls"); printf("\n\n Invalid choice!"); printf("\n\n\n "); system("pause"); system("cls"); } else break; } if (yn[0] == 'Y') { system("cls"); continue; } else break; } } else if (choice == 4) return 0; else continue; } } void menu() { system("cls"); printf("\n Main Menu"); printf("\n =========\n\n"); printf("\n 1) Polynomial Evaluation\n"); printf("\n 2) Statistical Algorithms\n"); printf("\n 3) Matrix Operations\n"); printf("\n 4) Exit\n"); printf("\n\n Choice > "); scanf("%d", &choice); system("cls"); } void polyeval() { while (1) { system("cls"); printf("\n POLYNOMIAL EVALUATION"); printf("\n =====================\n"); printf("\n Enter the degree of the polynomial "); scanf("%d", °ree); if (degree > 10 || degree < 0) { system("cls"); printf("\n\n Invalid choice!"); printf("\n\n\n "); system("pause"); system("cls"); continue; } if (degree > 0) { printf("\n Enter the value of x > "); scanf("%f", &x); } for (cntr = 0; cntr < degree; cntr ++) { printf("\n Enter the value of coefficient #%d > ", cntr + 1 ); scanf("%f", &coefficient[cntr]); } printf("\n Enter the value of the constant > "); scanf("%f", &constant); if (degree == 0) peval = constant; else pevalf(&peval); printf("\n\n The sum of the polynomial is %f\n", peval); printf("\n\n\n "); system("pause"); break; } } double pevalf(double *polynomial) { sum = coefficient[0]; for(cntr = 1; cntr < degree && cntr < 16; cntr++) sum = sum*x + coefficient[cntr]; *polynomial = sum*x + constant; } void statalgo() { while (1) { system("cls"); printf("\n STATISTICAL ALGORITHMS"); printf("\n ======================\n\n"); printf("\n Enter the number of the data "); scanf("%d", &dataNum); if (dataNum <= 0 || dataNum > 10) { system("cls"); printf("\n\n Invalid choice!"); printf("\n\n\n "); system("pause"); system("cls"); continue; } else { for (cntr = 0; cntr < dataNum; cntr++) { printf("\n\n Enter data %d > ", cntr + 1); scanf("%f", &data[cntr]); } system("cls"); printf("\n STATISTICAL ALGORITHMS"); printf("\n ======================\n\n"); printf("\n Select which one you wish to solve for\n"); printf("\n <1> Total\n"); printf("\n <2> Mean\n"); printf("\n <3> Standard Deviation\n"); printf("\n\n\n Choice > "); scanf("%d", &choice); if (choice == 1) { tot(&total); printf("\n\n The total is %f", total); } else if (choice == 2) { meanf(&mean); printf("\n\n The mean is %f", mean); } else if (choice == 3) { stddevf(&stddev); printf("\n\n The standard deviation is %f", stddev); } else { system("cls"); printf("\n\n Invalid choice!"); printf("\n\n\n "); system("pause"); system("cls"); break; } } printf("\n\n\n "); system("pause"); break; } } double tot(double *result) { *result = 0; for (cntr = 0; cntr < dataNum; cntr++) *result = *result + data[cntr]; } double meanf(double *ave) { tot(&total); *ave = total/dataNum; } double stddevf(double *standarddev) { meanf(&mean); squaresum = 0; for (cntr = 0; cntr < dataNum; cntr++) { square = (data[cntr] - mean) * (data[cntr] - mean); squaresum = squaresum + square; } *standarddev = sqrt(squaresum/dataNum); } void matrix() { while (1) { printf("\n Matrix Operations"); printf("\n =================\n"); printf("\n Enter the number of rows of each matrix > "); scanf("%d", &row); printf("\n\n Enter the number of columns of each matrix > "); scanf("%d",&column); if (row < 3 && row > 0 && column < 3 && column > 0) { printf("\n\n\n Enter the elements of the first matrix >\n\n "); for (cntr = 0; cntr < row; cntr++) for (counter = 0; counter < column; counter++) { printf("\n\t Enter element for Row %d Column %d > ", cntr + 1, counter + 1); scanf("%d", &mat1[cntr][counter]); } printf("\n\n\n Matrix 1 is >\n\n"); for (cntr = 0; cntr < row; cntr++) { for (counter = 0; counter < column; counter++) printf(" %d\t", mat1[cntr][counter]); printf("\n\n"); } printf("\n\n Enter the elements of the second matrix>\n "); for (cntr = 0; cntr < row; cntr++) for (counter = 0; counter < column; counter++) { printf("\n\t Enter element for Row %d Column %d > ", cntr + 1, counter + 1); scanf("%d", &mat2[cntr][counter]); } printf("\n\n\n Matrix 2 is >\n\n"); for (cntr = 0; cntr < row; cntr++) { for (counter = 0; counter < column; counter++) printf(" %d\t", mat2[cntr][counter]); printf("\n\n"); } printf("\n\n\n What do you want to do?\n"); printf("\n <1> Sum\n"); printf("\n <2> Product\n"); printf("\n <3> Transpose\n"); printf("\n\n Choice > "); scanf("%d", &choicemat); system("cls"); if (choicemat == 1) { printf("\n Matrix Operations"); printf("\n =================\n"); for (cntr = 0; cntr < row; cntr++) for (counter = 0; counter < column; counter++) summat[cntr][counter] = mat1[cntr][counter] + mat2[cntr][counter]; printf("\n The sum of the matrices is \n\n"); for (cntr = 0; cntr < row; cntr++) { for (counter = 0; counter < column; counter++) printf(" %d\t", summat[cntr][counter]); printf("\n\n"); } } else if (choicemat == 2) { printf("\n Matrix Operations"); printf("\n =================\n"); printf("\n The product of the matrices is \n\n"); for (cntr = 0; cntr < row; cntr++) { for (counter = 0; counter < column; counter++) { for (ctr = 0; ctr < row; ctr++) temp = temp + mat1[cntr][ctr]*mat2[ctr][counter]; product[cntr][counter] = temp; temp = 0; printf(" %d\t", product[cntr][counter]); } printf("\n\n"); } } else if (choicemat == 3) { printf("\n Matrix Operations"); printf("\n =================\n"); printf("\n Select matrix to transpose:\n"); printf("\n <1> Matrix 1\n"); printf("\n <2> Matrix 2\n"); printf("\n\n Choice > "); scanf("%d", &choice); system("cls"); if (choice == 1) { printf("\n Matrix Operations"); printf("\n =================\n"); for (cntr = 0; cntr < row; cntr++) for (counter = 0; counter < column; counter++) transpose[counter][cntr] = mat1[cntr][counter]; printf("\n The transpose of the first matrix is\n\n"); for (cntr = 0; cntr < column; cntr++) { for (counter = 0; counter < row; counter++) printf(" %d\t", transpose[cntr][counter]); printf("\n\n"); } printf("\n\n\n "); system ("pause"); } else if (choice == 2) { printf("\n Matrix Operations"); printf("\n =================\n"); for (cntr = 0; cntr < row; cntr++) for (counter = 0; counter < column; counter++) transpose[counter][cntr] = mat2[cntr][counter]; printf("\n The transpose of the second matrix is\n\n"); for (cntr = 0; cntr < row; cntr++ ) { for (counter = 0; counter < column; counter++ ) printf(" %d\t",transpose[counter][cntr]); printf("\n\n"); } printf("\n\n\n "); system("pause"); } } else { system("cls"); printf("\n\n Invalid choice!"); printf("\n\n\n "); system("pause"); system("cls"); break; } break; } else { system("cls"); printf("\n\n Invalid choice!"); printf("\n\n\n "); system("pause"); system("cls"); break; } } } ```

Not the answer you are looking for?

Search for more explanations.

Ask your own question