Thread: average(mean) of matrix

  1. #1
    Registered User
    Join Date
    Apr 2003
    Posts
    17

    average(mean) of matrix

    hi everyone...hope somebody can help me on this.
    i'm suppose to find the average(mean) of 4 number entered.
    i have to use array...thax.


    Code:
    void mean_matrix()
    {
    	int iArrayFirst[4];
    	int i;
    	int mean;
    	int total;
    	total=0;
    
    	for(i=0;i<4;i++)
    	{
    			printf("enter value:");
    			scanf("%d", &iArrayFirst[i]);
    		}
    			printf("\n");
    		}
    			for(i=0;i<4;i++)
    			total=total + i;
    			mean=total/4;
    		}
    		}
    	}
    	printf("the mean is %d", mean);
    
    }

  2. #2
    Lead Moderator kermi3's Avatar
    Join Date
    Aug 1998
    Posts
    2,595
    I am posting this because you did not use code tags on this thread. In the furture please use Code Tags. They make your code MUCH easier to read and people will be much more likely to help you if you do. And they'll be happier about helping you

    For example:

    Without code tags:

    for(int i=0;i<5;i++)
    {
    cout << "No code tags are bad";
    }

    With Code Tags:
    Code:
    for(int i=0;i<5;i++)
    {
         cout << "This code is easy to read";
    }
    This is of course a basic example...more complicated code is even easier to read with code tags than without.

    I've added code tags for you this time. They can be added by putting [code] at the beginning of your code and [/code] at the end. More information on code tags may be found on the code tag post at the top of every forum. I also suggest you take a look at the board guildlines if you have not done so already.

    This is a common first post mistake, just remember to use [code] tags in the future and you'll get much more help.

    If this is your first time posting here the welcome, and if there's anything I can do or any questions I can answer about these forums, or anything else, please feel free and welcome to PM me.


    Good Luck with your program,

    Kermi3
    Lead Moderator
    Kermi3

    If you're new to the boards, welcome and reading this will help you get started.
    Information on code tags may be found here

    - Sandlot is the highest form of sport.

  3. #3
    Registered User
    Join Date
    May 2003
    Posts
    7
    you dont use reference operator & for arrays in scanf(); (some exceptions). study more about arrays.

    *Since you are a student, I recommend paying more attention in class and reading the book CAREFULLY. I am also a student and I just finished a basic C class. You should know these simple issues.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. C - access violation
    By uber in forum C Programming
    Replies: 2
    Last Post: 07-08-2009, 01:30 PM
  2. Matrix Help
    By HelpmeMark in forum C++ Programming
    Replies: 27
    Last Post: 03-06-2008, 05:57 PM
  3. Gauss-Jordan Matrix Inversion in C++
    By Max_Power82 in forum C++ Programming
    Replies: 3
    Last Post: 12-03-2006, 08:31 PM
  4. Matrix and vector operations on computers
    By DavidP in forum A Brief History of Cprogramming.com
    Replies: 11
    Last Post: 05-11-2004, 06:36 AM