Problem link Click here
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.
Input Sample | Output Sample |
8 | 9 11 13 15 17 19 |
Solution...
#include<stdio.h>
int main()
{
int a,i,j=0;
scanf("%d",&a);
if(a%2==0){
for(i=a+1;j<6;i=i+2){
printf("%d\n",i);
j++;
}
}
if(a%2!=0){
for(i=a;j<6;i=i+2){
printf("%d\n",i);
j++;
}
}
return 0;
}
No comments:
Post a Comment