Sujet : Re: More Funny Stuff From Joel
De : candycanearter07 (at) *nospam* candycanearter07.nomail.afraid (candycanearter07)
Groupes : comp.os.linux.advocacyDate : 11. Jun 2024, 04:40:08
Autres entêtes
Organisation : the-candyden-of-code
Message-ID : <slrnv6f9fl.2hg.candycanearter07@candydeb.host.invalid>
References : 1 2 3 4 5 6 7
User-Agent : slrn/1.0.3 (Linux)
DFS <
nospam@dfs.com> wrote at 23:30 this Saturday (GMT):
On 6/8/2024 5:32 PM, Joel wrote:
>
I can't imagine I'd need anything beyond C.
>
>
I hope you're not gonna pull a Feeb and claim you're a C guru that can
'move the Earth', but refuse to show ANY decent code, then make lame
excuses like "I have other fish to fry".
Seems like a fun challenge.. especially since im kinda rusty with c
1) write your own C to sort these 3 names (by last then first):
>
William Thomas
Zachary Jones
Jim Thomas
I'll be honest, I might be bad but I completely forgot how to sort
strings.. sorry
2) write your own C to count the words in:
>
"Now is the time for all good men to come to the aid of their country."
#include <stdio.h>
#include <ctype.h>
const char phrase[] = "Now is the time for all good men to come to the
aid of their country.";
int main()
{
const char *phr = phrase;
int words = 0;
int space = 0; // does c have bool?
while(*phr)
{
if(space && isalpha(*phr))
{
space = 0;
words++;
}
if(isblank(*phr)) space = 1;
phr++;
}
printf("Words: %d, words);
}
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)
Why is it I have a VERY strong feeling you and Feeb and C are about to
be pwned by python?
IMO, both are pretty good languages, with their own strengths..like, C
is good for dealing with the raw data and it can be really satisfying to
get everything working, and python is great for throwing something
together.
-- user <candycane> is generated from /dev/urandom