C Programming Week7
C Programming Week7
Multi-Dimensional Arrays
• Arrays with two or more dimensions can be
defined
A[4][3]
CS1100 0 1 2 0 1
B[2][4][3]
2 0 1 2
Introduction to Programming 0
0
Matrix Operations 1 1
Madhu Mutyam 2 2
Department of Computer Science and Engineering
Indian Institute of Technology Madras 3
3
Course Material – SD, SB, PSK, NSN, DK, TAG – CS&E, IIT M 1 0 1
SD, PSK, NSN, DK, TAG – CS&E, IIT M 2
1
14/10/17
2
14/10/17
Mathematical Recreations
Hailstone Numbers http://users.swing.be/TGMSoft/hailstone.htm
• A Hailstone Sequence is generated by a simple
algorithm:
• 7, 22, 11, 34, 17, 52, 26, 13, 40, 20, 10, 5, 16, 8, 4, 2,
1, 4, 2, 1, ... repeats
• 12, 6, 3, 10, 5, 16, 8, 4, 2, 1, 4, 2, 1 ….
Exercise : Write a program to accept an input and count the number of
• 909, 2726, 1364, 682, 341, 1024, 512, 256, 128, 64, iterations needed to get to 1, and the highest number reached. Generate a table
32, 16, 8, 4, 2, 1, 4, 2, 1… 210 of results…
SD, PSK, NSN, DK, TAG – CS&E, IIT M 13 SD, PSK, NSN, DK, TAG – CS&E, IIT M 14