An example Analysis of C language structure body Array
In this article, the editor introduces "c language structure body array example analysis" in detail, the content is detailed, the steps are clear, and the details are handled properly. I hope this article "c language structure body array example analysis" can help you solve your doubts. Let's follow the editor's ideas to learn new knowledge.
An example of structure array program
Ex.: election voting procedure. There are three candidates to participate in the election, the number of voters is n, each person can only cast one vote, enter the number n and the candidate name of each candidate from the keyboard, count and output the number of votes of each candidate.
# include
# include
Struct candicate / / defines the structure type of the candidate
{
Char name [20]; / / name
Int count; / / number of votes obtained
}
Int main ()
{
Struct candicate cand [] = {"zhang", 0, "li", 0, "wang", 0}
Int n,i,j
Char name [20]
Printf ("Please enter the number of voters:")
Scanf ("d", & n)
Printf ("enter candidate names for all [% d] voters:\ n", n)
For (iTunes 1)