









Study with the several resources on Docsity
Earn points by helping other students or get them with a premium plan
Prepare for your exams
Study with the several resources on Docsity
Earn points to download
Earn points by helping other students or get them with a premium plan
Community
Ask the community for help and clear up your study doubts
Discover the best universities in your country according to Docsity users
Free resources
Download our free guides on studying techniques, anxiety management strategies, and thesis advice from Docsity tutors
Examples of using arrays in c programming, including character arrays and string manipulation. It also discusses the generation of pseudorandom numbers in c, including the use of the srand function and the time function to randomize the seed. Code examples for a students poll program and a histogram program.
Typology: Slides
1 / 15
This page cannot be seen from the preview
Don't miss anything!
6.4 Examples Using Arrays
char string1[] = "first";
char string1[] = { 'f', 'i', 'r', 's', 't', '\0' };
string1[ 3 ] is character ‘s’
scanf( "%s", string2 );
Outline
fig06_10.c (Part 1 of 2)
Example: Students poll
students. Each student have entered a value
between 1 and 10. Count frequency of each choice
in the given data set.
Outline
fig06_07.c (Part 1 of 2)
Example: Histogram
grades into ranges and plot the number of grades
in each range. Your histogram should have 5 bars,
for the ranges 100-90, 89-70, 69-50, 49-35 and
34-0.
Outline
fig06_08.c (Part 1 of 2)
Rolling a die
rand ( ) % 6 =?
Result has to be between 0 and 5 inclusive
1 + rand ( ) % 6
It will randomly generate number between
1 and 6
It has only two possibilities 0 / 1
rand ( ) % 2 ;
Example: Tossing a Coin