c - Wrong output in printf -


ok simple , scolded im new c , trying learn best can. have problem wich solved , logic works pretty good.but whenever there wrong input shows message on screen , plus condition not true.so whenever there supposed invalid input message ne - wich print out if condition isnt true.this code :

#include <stdio.h>  #include <stdlib.h>  int main() {     int a, b;     scanf("%d %d", &a, &b);     if(a <= 0 || b <= 0) {         printf("invalid input");     } else {         if(a < b) {             int tmp = a;             = b;             b = tmp;         }     }     a/=10;     int c1,c2;     while (a!=0 && b!=0){         c1 = a%10;         c2 = b%10;         /= 100;         b /= 10;     }     if (c1 == c2)         printf("paren\n");     else         printf ("ne\n");     return 0; } 

its because there nothing thats stop so:

if want terminate program return whenever if condition true:

if(a <= 0 || b <= 0) { printf("invalid input"); return 1;  }  

alternative: add rest of code under else clause.


Comments

Popular posts from this blog

java - Static nested class instance -

c# - Bluetooth LE CanUpdate Characteristic property -

JavaScript - Replace variable from string in all occurrences -