Why is the first if ignored?
#include <stdio.h> #include <stdlib.h> int main(void) { int t; int *a; int *b; int diff1=0,diff2=0,diff3=0,diff4=0,diff5=0,diff6=0; int temp1=0,temp2=0; scanf("%d",&t); a=malloc(t*sizeof(int)); b=malloc(t*sizeof(int)); // for t inputs for(int o=0;o<t;o++){ scanf("%d %d",(a+o),(b+o)); //if first element is greater if(a[o]>b[o]){temp1++; diff1=(a[o]-b[o]); if(diff2>=diff1){diff3=diff2; diff2=diff1;} else{diff3=diff1;diff2=diff1;} } // if second element is greater else{temp2++; diff4=(b[o]-a[o]); if(diff5<=diff4){diff6=diff4; diff5=diff4;} else{diff6=diff5;diff5=diff4;} } } if(temp1>temp2){printf("1 ");printf("%d",diff3);} else{printf("2 ");printf("%d",diff6);} return 0; } /*input:7 1 4 1 5 3 7 3 8 3 7 5 2 4 7*/