Problem :
Six Odd Numbers
Adapted by Neilor Tonin, URI Brazil
Timelimit: 1
Read an integer value X and print the 6 consecutive odd numbers from X, a value per line, including X if it is the case.
Input
The input will be a positive integer value.
Output
The output will be a sequence of six odd numbers.
Sample Input | Sample Output |
8 | 9 11 13 15 17 19 |
Solution:
#include<cstdio>
int
main()
{
int
X , i;
scanf
(
"%d"
,&X);
if
(X % 2 != 0){
for
(i = X; i < X + (2*6); i++){
if
(i % 2 != 0)
printf
(
"%d\n"
,i);
}
}
else
{
for
(i = X; i < X + (2*6)+1; i++){
if
(i % 2 != 0)
printf
(
"%d\n"
,i);
}
}
return
0;
}
No comments:
Post a Comment