Search results

  • Users: faust9
  • In Programming and Computer Science
  • Content: Threads, Posts
  • Order by date
  1. F

    Array arithmetic in C?

    One of the best ways to learn C is to test these sorts of questions. #include <stdio.h> main() { int f[5]={0}, i; for(i=0;i<5;i++) { printf(" i = %d \n", i); printf(" f[i] = %d \n", f[i]); f[i]+=i; printf("incremented f[1] = %d \n", f[i]); } }...
  2. F

    General best practices: commenting code

    Both: The outer comment explains what the procedure does. The inner comments explain what each part of the procedure is for. If you clog the outer comment with too much info it makes quick reading of code difficult---when scanning code you should get enough info about code execution from the...
  3. F

    Java Java and missing images

    Do you have your images folder and java .jar file in the same directory?
  4. F

    Recursion in C

    Sorry the above was so long, but that's one of the bad things about recursive functions. They consume a lot of memory when easire methods ususally exist. You have to keep in mind that when a function is called a new function is created using the function code as a framework. Each new function...
  5. F

    Recursion in C

    Your function (I removed the unsigned type) int factorial(int a) { //test used to see if the factoral process is at the last stage if (a == 1) return 1; //recursive step of the factoral else { a *= factorial(a-1); //calls the factoral function. //The...
  6. F

    Recursion in C

    I don't know what you mean by this. In C, a function can only return one value (you can get around this using structures/unions and more importantly pointers). I don't know if you understand what is really happening here or not. The program doesn't get to the 'return a' command until the...
  7. F

    Recursion in C

    unsigned int factorial(unsigned int a) { if (a == 1) return 1; else { a *= factorial(a-1); return a; } } Talk it through... let a=4 4 != 1 so the if portion is skipped for now. 4*=factorial(3) 3 != 1 3*=factoral(2) 2 != 1...
Top