Search the Community

Showing results for tags 'c help'.



More search options

  • Search By Tags

    Type tags separated by commas.
  • Search By Author

Content Type


Forums

  • Raid Gaming Main Area
    • Raid Gaming News
    • Official Rules & Help
    • Donations
    • Applications
  • Raid Gaming Servers
    • General Gameserver Discussions
    • CoD4 Servers
    • Raid TTT
    • Raid CS:GO Surf
  • Plugins, Tutorials, Maps & More
    • Tutorials
    • Maps
    • Plugins
    • General Help
  • Raid Gaming General
    • Introduction
    • General Discussions
    • Media
    • Forum Games
    • Suggestions

Found 1 result

  1. Hey everyone, I'm writing this program in order to further understand two-dimensional arrays and the manipulation of them in c. Basically what the program is supposed to do is the following: Prompt the user for the borders of the arrays. Prompt the user for the amount of iterations they want to go through the arrays and find averages. Ensure epsilon (the error checking value) is less than the largest change in value. Calculate convergence. If you don't know what epsilon or convergence is, don't worry about it. I'm having issues with my while/for/for nested loops working properly. At the moment, no matter what iteration is set to, it's only iterating once. It's probably a simple mistake that I'm overlooking, and a fresh set of eyes would be glorious. The program is supposed to look at a single element, and then take the element "above" it, to the "left" of it, to the "right" of it, and then the "bottom" element. Then it multiplies (or divides it) by a 4th. Meaning if the user enters 1 0 0 1 as the border input, it should look like this after ONE iteration (which mine does). 1.00 1.00 1.00 1.00 1.00 1.00 1.00 1.00 1.00 1.00 1.00 0.50 0.25 0.25 0.25 0.25 0.25 0.25 0.25 0.00 1.00 0.25 0.00 0.00 0.00 0.00 0.00 0.00 0.00 0.00 1.00 0.25 0.00 0.00 0.00 0.00 0.00 0.00 0.00 0.00 1.00 0.25 0.00 0.00 0.00 0.00 0.00 0.00 0.00 0.00 1.00 0.25 0.00 0.00 0.00 0.00 0.00 0.00 0.00 0.00 1.00 0.25 0.00 0.00 0.00 0.00 0.00 0.00 0.00 0.00 1.00 0.25 0.00 0.00 0.00 0.00 0.00 0.00 0.00 0.00 1.00 0.25 0.00 0.00 0.00 0.00 0.00 0.00 0.00 0.00 1.00 0.00 0.00 0.00 0.00 0.00 0.00 0.00 0.00 0.00 If you need a further explanation, please ask and I will expand best I can. Please note that I've written all of this myself with minimal assistance. I would love to hear about your opinion of my styling, logic, and neatness. #include <stdio.h> #include <stdlib.h> int i, j, iterations, sTop, sRight, sBottom, sLeft, counter = 0; double ep; float diff; float array1[10][10]; float array2[10][10]; float aTemp[10][10]; int main(void) { puts("Please enter the epsilon variable:"); scanf("%lf", &ep); printf("Ep: %lf\n", ep); if (ep <= .1 && ep > 0) { puts("Valid input."); } else { puts("Invalid input."); return 0; } puts("Please enter the maximum number of iterations:"); scanf("%d", &iterations); puts("Please enter the top, right, bottom, and left boundary. (example: 1 2 3 4)"); scanf("%d %d %d %d", &sTop, &sRight, &sBottom, &sLeft); //Print statements (Mainly for debugging) printf("Ep: %lf\n", ep); printf("Iterations: %d\n", iterations); printf("Top: %d Right: %d Bottom: %d Left: %d\n", sTop, sRight, sBottom, sLeft); //Fill boundaries with user input. for (i = 0; i < 10; i++) { array2[0][i] = array1[0][i] = sTop; array2[i][9] = array1[i][9] = sRight; array2[9][i-1] = array1[9][i-1] = sBottom; array2[i+1][0] = array1[i+1][0] = sLeft; } //Fill interior with 0s. for (i = 1; i < 9; i++) { for (j = 1; j < 9; j++) { array1[i][j] = 0; } } //Calculate next grid fill. Multiply by .25 because faster than division by 1/4. while (iterations != 0) { for (i = 1; i <= 9; i++) { for (j = 1; j <= 9; j++) { array2[i][j] = ((array1[i-1][j] + array1[i+1][j] + array1[i][j-1] + array1[i][j+1]) * 0.25); } } aTemp[i][j] = array2[i][j]; array1[i][j] = aTemp[i][j]; iterations--; counter++; } //} //Print out the matrix1. puts("Matrix 1!"); for (i = 0; i < 10; i++) { for (j = 0; j < 10; j++) { printf("%.2f ", array1[i][j]); } puts(" "); } //Print out the matrix12. printf("Converged in %d steps.\n", counter); puts("Matrix 2!"); for (i = 0; i < 10; i++) { for (j = 0; j < 10; j++) { printf("%.2f ", array2[i][j]); } puts(" "); } return 0; }