Painful Giveaway!

This is a companion discussion topic for the original entry at
#include <stdio.h>

int main(){

    long int N,i;
    for(i = 0;i<=N;i++)
        printf("%li ",i);

    return 0;

What’s wrong with my code?


int main() {
    int N,number_of_digits,j,i;


for (j=1;j<=N;j*=10){
     number_of_digits += (N - j + 1); }

if (number_of_digits<=1000000){
    printf("%d ",i);

    return 0;

did i miss understand the last line ?? ( It’s guaranteed that the count of the total printed numbers will never exceed 10^6 .))

pls reply …

  • Your program won’t work if the input, N is negative (yes, N can be negative too)
  • You are printing a space after the last digit which is not allowed.
1 Like

As far as I can understand, the last line will only help you decide the int variable type you should choose (whether it can be int N, or long int N or long long int N or whatever). It’s nothing more than that.