#include <stdio.h>
#include<math.h>
int binary_to_decimal(int n){
int ostatok, i=0, pom, decimal=0;
pom=n;
while(pom)
{
ostatok=pom%10;
decimal+=ostatok*pow(2,i);
pom/=10;
i++;
}
return decimal;
}
int main()
{
int m, n, i, max=0, number;
scanf(" %d %d", &n, &m);
int array[n];
for(i=0; i<n ;i++){
scanf(" %d", &number);
binary_to_decimal(number);
if(number>m) // this if statement doesn't seem to be doing it's job
array[i]=number;
if(array[i]>max)
max=array[i];
}
for(i=0; i<n ;i++){
printf(" %d %d\n", array[i], binary_to_decimal(array[i]));
}
printf("Max %d %d", max, binary_to_decimal(max));
return 0;
}
The program is: you enter two int values, m and n. m is used as a value for comparison, while n is the number of binary number the user is inputting in the loop. If the inputted number is greater than the number m print out the values of the inputted number in binary then in decimal. At the end, print out the number with the biggest value in binary and decimal. My problem is the if where i am comparing m and the inputted number and i can't seem to find the problem.
Aucun commentaire:
Enregistrer un commentaire