Terminal Counting it self

Viewed 47
#include<stdio.h>

int main(){
    int n,m;
    int count = 0;
    scanf("%d" "%d", &n, &m);
    
    for(n=m;n>0;n=n/10);
    
    printf("%d\n",count++);
    
    return 0;
}

How can I do this with this main code or I just need something edit? I struggled how to can it be count like this sample:

Sample Input 1 (standard input)

1 5 

Sample Output 1 (standard output)

1
2
3
4
5
1 Answers

It seems you want a simple counter that counts from one number to some other large number.

#include <stdio.h>

int main(){
  int lowerbound, upperbound;

  scanf("%d %d", &lowerbound, &upperbound);  // string simplyfied
    
  int counter;
  for (counter = lowerbound; counter <= upperbound; counter++)
  {
    printf("%d\n",counter);
  }
    
  return 0;
}

That's the classic introductory sample of the for loop that you can find in about every beginner's C text book.

Note the new selfdescribing variable names which makes your code easier to read and to understand.

Related