Path: ...!3.eu.feeder.erje.net!feeder.erje.net!eternal-september.org!feeder3.eternal-september.org!news.eternal-september.org!.POSTED!not-for-mail From: candycanearter07 Newsgroups: comp.os.linux.advocacy Subject: Re: More Funny Stuff From Joel Date: Tue, 11 Jun 2024 02:40:08 -0000 (UTC) Organization: the-candyden-of-code Lines: 102 Message-ID: References: <17d716103c089ab3$7951$675878$802601b3@news.usenetexpress.com> <2ej96j1mbvgiok4q5c57vdlo94itpfu5dt@4ax.com> <6664e989$0$2363151$882e4bbb@reader.netnews.com> Injection-Date: Tue, 11 Jun 2024 04:40:08 +0200 (CEST) Injection-Info: dont-email.me; posting-host="4b8de5e0235d9d4138e4d44dba56bb9d"; logging-data="913008"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX1+kSXuyqPzMdpx2L4oZgFThJ1etJAKDHQxbMDuBb4f1Ww==" User-Agent: slrn/1.0.3 (Linux) Cancel-Lock: sha1:6S9nO/ZpI1i/xeZzcy2gg3gSqk0= X-Face: b{dPmN&%4|lEo,wUO\"KLEOu5N_br(N2Yuc5/qcR5i>9-!^e\.Tw9?/m0}/~:UOM:Zf]% b+ V4R8q|QiU/R8\|G\WpC`-s?=)\fbtNc&=/a3a)r7xbRI]Vl)r<%PTriJ3pGpl_/B6!8pe\btzx `~R! r3.0#lHRE+^Gro0[cjsban'vZ#j7,?I/tHk{s=TFJ:H?~=]`O*~3ZX`qik`b:.gVIc-[$t/e ZrQsWJ >|l^I_[pbsIqwoz.WGA] 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 #include 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 #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 is generated from /dev/urandom