Thursday, April 23, 2020

how to print the range between two numbers in text format

int main() 
{
    int a, b;
    char *str[] = {"one""two""three""four""five""six""seven",  "eight",  "nine""even""odd"};
    scanf("%d\n%d", &a, &b);
    // Complete the code.
         
  for (int i=a; i<=b; i++) {
    if (i <= 9
         printf ("%s\n", str[i-1]);
    else 
        printf ("%s\n", str[9+(i%2)]);

  }
  return 0;
}

output:
input:
8
11
output:
eight
nine
even
odd

No comments:

Post a Comment

python class topic video