Deutsch   English   Français   Italiano  
<666b0963$0$985$882e4bbb@reader.netnews.com>

View for Bookmarking (what is this?)
Look up another Usenet article

Path: ...!news-out.netnews.com!postmaster.netnews.com!us14.netnews.com!not-for-mail
X-Trace: DXC=eHhEaRI]40kYi@fQk=;MdlHWonT5<]0TmQ;nb^V>PUff=AnO\FUBY[`nF54O@^\1?dESf2LZ4kKliLQ^D7JJN18aankHQ>:kCVbOT>gi^X=X_aCGm4YP8f00j
X-Complaints-To: support@blocknews.net
Date: Thu, 13 Jun 2024 10:59:51 -0400
MIME-Version: 1.0
User-Agent: Betterbird (Windows)
Subject: Re: More Funny Stuff From Joel
Newsgroups: comp.os.linux.advocacy
References: <17d716103c089ab3$7951$675878$802601b3@news.usenetexpress.com>
 <ej496jd0tb59u2l0nqtghq3u9ahhmann3s@4ax.com>
 <lcjnnuF896hU5@mid.individual.net>
 <kma96j1no1tp926ctejldkdk2c19aeruft@4ax.com>
 <lcjvk1F9n7aU1@mid.individual.net>
 <2ej96j1mbvgiok4q5c57vdlo94itpfu5dt@4ax.com>
 <6664e989$0$2363151$882e4bbb@reader.netnews.com>
 <slrnv6f9fl.2hg.candycanearter07@candydeb.host.invalid>
 <66687931$0$3747328$882e4bbb@reader.netnews.com>
 <slrnv6ig9v.13pi.candycanearter07@candydeb.host.invalid>
 <66699f8c$0$966$882e4bbb@reader.netnews.com>
 <slrnv6l2vk.24pu.candycanearter07@candydeb.host.invalid>
Content-Language: en-US
From: DFS <nospam@dfs.com>
In-Reply-To: <slrnv6l2vk.24pu.candycanearter07@candydeb.host.invalid>
Content-Type: text/plain; charset=UTF-8; format=flowed
Content-Transfer-Encoding: 7bit
Lines: 84
Message-ID: <666b0963$0$985$882e4bbb@reader.netnews.com>
NNTP-Posting-Host: 127.0.0.1
X-Trace: 1718290787 reader.netnews.com 985 127.0.0.1:42255
Bytes: 3492

On 6/13/2024 2:05 AM, candycanearter07 wrote:
> DFS <nospam@dfs.com> wrote at 13:15 this Wednesday (GMT):
>> On 6/12/2024 2:35 AM, candycanearter07 wrote:
>>> DFS <nospam@dfs.com> wrote at 16:20 this Tuesday (GMT):
>>
>>
>>>>>> 3) write your own C to calc the mean, median and mode of:
>>>>>>
>>>>>> 1,2,3,4,5,5,6,7,8,9
>>>>>
>>>>> #include <stdio.h>
>>>>> #define COUNT_CNT 10
>>>>>
>>>>> int nums[] = {1, 2, 3, 4, 5, 5, 6, 7, 8, 9, -1};
>>>>>
>>>>> int main()
>>>>> {
>>>>> 	double mean;
>>>>> 	int median, mode, md_count[COUNT_CNT], len;
>>>>>
>>>>> 	for( len = 0; nums[len] != -1; len++ )
>>>>> 	{
>>>>> 		mean += nums[len];
>>>>> 		md_count[nums[len]]++;
>>>>> 	}
>>>>> 	mean /= len;
>>>>>
>>>>> 	if(len % 2 == 0)
>>>>> 	{
>>>>> 		int mid = len / 2;
>>>>> 		median = nums[mid] + nums[mid + 1]];
>>>>> 		median /= 2;
>>>>> 	}
>>>>> 	else
>>>>> 		median = nums[len / 2];
>>>>> 	
>>>>> 	for( int i = 0; i < COUNT_CNT; i++ )
>>>>> 	{
>>>>> 		if(md_count[mode] < md_count[i]) mode = i;
>>>>> 	}
>>>>>
>>>>> 	printf("mean %g, median %d, mode %d", mean, median, mode);
>>>>> }
>>>>>
>>>>> These compiled fine on my machine (gcc 12.2.0)
>>>>
>>>>
>>>> Did you actually run the code?
>>>
>>> Yes, but I also typed it into slrn by hand bc I was worried that pasting
>>> it would mess up word wrapping
>>>
>>>> I got a segfault (WSL Ubuntu, gcc 11.4).  Had to make a few tweaks to
>>>> get it to run and provide correct answers.
>>>>
>>>> Do you want me to tell you what I did, or do you want to figure it out?
>>>>
>>>> Hint: after the line "mean /= len;" print out the contents of
>>>> md_count[].  You should get:
>>>>
>>>> 1. 1
>>>> 2. 1
>>>> 3. 1
>>>> 4. 1
>>>> 5. 2
>>>> 6. 1
>>>> 7. 1
>>>> 8. 1
>>>> 9. 1
>>>
>>> I don't see it sorry ^^:
>>
>>
>> You don't see what?
> 
> 
> The mistake I made.


Did you print the contents of md_count[] ?  That should give you a clue.

The code you posted shouldn't have run.  What answers did it give you?