c - Runtime error when running my program -


my code num of digits integer 1000000 @ most. code either using while or for or if :

#include <stdio.h> #include <stdlib.h> #include <math.h>  int main() {   int t,num_of_seven_segment=0;    printf("enter test case: ");    scanf("%d", &t);`   /* for(;t!=0;t=t/10)   {         if(t>=1000001) break;        num_of_seven_segment++;   }*/    while(t!=0) {     t=t/10;     num_of_seven_segment++;    }    printf(" %d",num_of_seven_segment);    getch();  } 
#include <stdio.h>  #include <stdlib.h>  #include <math.h>  int main()   {  int t;    int num_of_sevensegment=0;    printf("enter test cases");    scanf("%d",&t);     if(t<1000000)    num_of_sevensegment+=6;      if (t<100000)    num_of_sevensegment--;      if (t<10000)    num_of_sevensegment--;     if (t<1000)    num_of_sevensegment--;    if (t<100)   num_of_sevensegment--;     if (t<10)    num_of_sevensegment--;    else if(t==1000000)    num_of_sevensegment=7;     printf("%d",num_of_sevensegment);     return 0;   } 

since using online judge, adding return 0; statement @ end of first code should fix it. getch() doesn't work.

additionally (not related runtime error), don't think explicitly prompting user input required in online judges.

also, in statement - printf(" %d",num_of_seven_segment); there seems space before %d - possible source of wrong answer.


Comments

Popular posts from this blog

c# - Validate object ID from GET to POST -

node.js - Custom Model Validator SailsJS -

php - Find a regex to take part of Email -