C Language Examples - Output Data in Tabular Form
Output the data from 1 to 100 in a 10x10 matrix format.
Example
#include
<
stdio.h
int
main
(
)
{
int
i
,
j
,
count;
for
(
i
=
1
;
i
<=
10
;
i
++
)
{
for
(
j
=
i
;
j
<=
100
;
j
+=
10
)
printf
(
"
%3d
"
,
j
)
;
printf
(
"
\
n
"
)
;
}
return
0
;
}
Running result:
1 11 21 31 41 51 61 71 81 91
2 12 22 32 42 52 62 72 82 92
3 13 23 33 43 53 63 73 83 93
4 14 24 34 44 54 64 74 84 94
5 15 25 35 45 55 65 75 85 95
6 16 26 36 46 56 66 76 86 96
7 17 27 37 47 57 67 77 87 97
8 18 28 38 48 58 68 78 88 98
9 19 29 39 49 59 69 79 89 99
10 20 30 40 50 60 70 80 90 100
Output an arithmetic sequence in a 10x10 matrix format.
Example
#include
<
stdio.h
int
main
(
)
{
int
i
,
j
,
count;
int
start
,
end
;
start
=
2
,
end
=
10
;
for
(
i
=
start
;
i
<=
end
;
i
++
)
{
count
=
i
;
for
(
j
=
1
;
j
<=
10
;
j
++
)
{
printf
(
"
%3d
"
,
count
j
)
;
}
printf
(
"
\
n
"
)
;
}
return
0
;
}
Running result:
2 4 6 8 10 12 14 16 18 20
3 6 9 12 15 18 21 24 27 30
4 8 12 16 20 24 28 32 36 40
5 10 15 20 25 30 35 40 45 50
6 12 18 24 30 36 42 48 54 60
7 14 21 28 35 42 49 56 63 70
8 16 24 32 40 48 56 64 72 80
9 18 27 36 45 54 63 72 81 90
10 20 30 40 50 60 70 80 90 100
Multiplication table format.
Example
#include
<
stdio.h
int
main
(
)
{
int
i
,
j
,
n;
n
=
3
;
j
=
1
;
for
(
i
=
n
;
i
<=
(
n
10
)
;
i
+=
n
)
{
printf
(
"
%3d x %2d = %3d
\
n
"
,
n
,
j
,
i
)
;
j
++;
}
return
0
;
}
Running result:
3 x 1 = 3
3 x 2 = 6
3 x 3 = 9
3 x 4 = 12
3 x 5 = 15
3 x 6 = 18
3 x 7 = 21
3 x 8 = 24
3 x 9 = 27
3 x 10 = 30
C Language Examples