Home > Mobile >  How do you make a code that print numbers between N and M in C
How do you make a code that print numbers between N and M in C

Time:10-04

I need to make a code that have the output of 1 to 10 when you input the number 1 and 10, but also have the output of 10 to 19 when you input the number 10 and 10.

I've tried the following :

#include <stdio.h>

int main()
{
    int N;
    int M;

    scanf ("%d %d", &N, &M);
    
    for (int i = N ; i <= M ; i   )
    while (N <= M) {
    printf ("%d\n", N   );
    }

    return 0;
}

but when I put 10 and 10, the output is also 10. Thanks for your answer in advance, I only recently started learning and I'm already stuck.

CodePudding user response:

for ( int i = N; i < ( N   M ); i   )
    printf( "%d\n" , i )

Just a loop from the bottom number, to the max. From your description, I assume the max is N M.

Alternatively, you can loop fro 0 to M, but do addition in the output to get the min back in.

for ( int i = 0; i < M; i   )
    printf( "%d\n" , i   N )
  •  Tags:  
  • c
  • Related