C Example: Vote Counter: tally, percentages and winner detection

🗓 Last updated: 2026-11-30👤 Written by: Harper✓ Reviewed by: MOTO🏷 Category: Mini Apps

Stores candidate names and vote counts in a struct array, walks 12 ballots (including one abstention) to accumulate valid votes; then computes each candidate's percentage, finds the highest count and prints the winner. Demonstrates index mapping, counting and a simple maximum search.

🌱 Beginner Reference entries: kw-structfn-printfkw-int
🖥 Run OnlineGCC 10.2 · C11 standard · click ▶ to run · Copy code
🖨 Reference OutputMatches the online run in a standard C11 environment
C · GCC 10.2 · -std=c11
ballots: 12, valid: 11, abstain: 1
Alice    5 votes  45.5%
Bob      3 votes  27.3%
Carol    2 votes  18.2%
Dave     1 votes   9.1%
winner: Alice (5 votes)
🧩 Keep Learning

🙏 帮我们做得更好

我们是刚上线的编程教程站,几个人的小团队,精力有限。页面虽经检查,难免还有疏漏——链接失效、排版错乱、内容有误、语言生硬……

如果您发现了,麻烦告诉我们,我们会在收到反馈后第一时间进行修复,再次感谢您的光临 🙏