+ 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; }
7 Réponses
+ 1
for(int i=0; i>=0 ; i++) //this is infinite loop..
Condition i>=0 always true.. So never stops...
+ 1
Check my profile rupali i correct your own in my code bits decimal to binary
+ 1
Didn't effective sir 😑
+ 1
Yes sir it's working now!!
Thanks to you😄😄
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..
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;
}
0
You're welcome..