|
| 1 | +// Program to illustrate structures and arrays |
| 2 | + |
| 3 | +#include <stdio.h> |
| 4 | + |
| 5 | +int main (void) |
| 6 | +{ |
| 7 | + int i; |
| 8 | + |
| 9 | + struct month |
| 10 | + { |
| 11 | + int numberOfDays; |
| 12 | + char name[3]; |
| 13 | + }; |
| 14 | + |
| 15 | + const struct month months[12] = { |
| 16 | + { 31, {'J', 'a', 'n'} }, { 28, {'F', 'e', 'b'} }, |
| 17 | + { 31, {'M', 'a', 'r'} }, { 30, {'A', 'p', 'r'} }, |
| 18 | + { 31, {'M', 'a', 'y'} }, { 30, {'J', 'u', 'n'} }, |
| 19 | + { 31, {'J', 'u', 'l'} }, { 31, {'A', 'u', 'g'} }, |
| 20 | + { 30, {'S', 'e', 'p'} }, { 31, {'O', 'c', 't'} }, |
| 21 | + { 30, {'N', 'o', 'v'} }, { 31, {'D', 'e', 'c'} } |
| 22 | + }; |
| 23 | + |
| 24 | + printf ("Month Number of Days\n"); |
| 25 | + printf ("----- --------------\n"); |
| 26 | + |
| 27 | + for ( i = 0; i < 12; ++i ) |
| 28 | + printf (" %c%c%c %i\n", |
| 29 | + months[i].name[0], months[i].name[1], |
| 30 | + months[i].name[2], months[i].numberOfDays); |
| 31 | + |
| 32 | + return 0; |
| 33 | +} |
0 commit comments