+ 1

Why it is not giving the output?? What is the error in it??

#include <stdio.h> int main() { printf("***DECIMAL TO BINARY***\n"); int num ,i=0; int arr[10]; printf("Enter a number\n"); scanf("%d",&num); for(int i=0; i>=0; i++){ arr[i] = num % 2; num = num / 2; } for(int j= i-1;j>=0; j--){ printf ("Binary = %d",arr[j]); } return 0; }

20th Aug 2020, 7:47 PM
Rupali Haldiya
Rupali Haldiya - avatar
7 Answers
+ 1
for(int i=0; i>=0 ; i++) //this is infinite loop.. Condition i>=0 always true.. So never stops...
20th Aug 2020, 8:01 PM
Jayakrishna šŸ‡®šŸ‡³
+ 1
Check my profile rupali i correct your own in my code bits decimal to binary
20th Aug 2020, 8:07 PM
HBhZ_C
HBhZ_C - avatar
+ 1
Didn't effective sir šŸ˜‘
20th Aug 2020, 8:14 PM
Rupali Haldiya
Rupali Haldiya - avatar
+ 1
Yes sir it's working now!! Thanks to youšŸ˜„šŸ˜„
20th Aug 2020, 8:32 PM
Rupali Haldiya
Rupali Haldiya - avatar
0
Instead for loop condition write num>0, And don't intilize again int I =0, rupali just put i=0 so for(i=0 ; num>0; i++) Or use while(num>0) { i++; ... ..} Remaining works..
20th Aug 2020, 8:16 PM
Jayakrishna šŸ‡®šŸ‡³
0
//do check this after, your try only.. #include <stdio.h> int main() { printf("***DECIMAL TO BINARY***\n"); int num ,i=0; int arr[10]; printf("Enter a number\n"); scanf("%d",&num); printf("Number = %d, \n in binary :", num) ; for( i=0; num>0; i++){ arr[i] = num % 2; num = num / 2; } for(int j= i-1;j>=0; j--){ printf (" %d",arr[j]); } return 0; }
20th Aug 2020, 8:26 PM
Jayakrishna šŸ‡®šŸ‡³
0
You're welcome..
21st Aug 2020, 4:05 PM
Jayakrishna šŸ‡®šŸ‡³