Back to Problem Solutions forum
Hello i am trying to solve the problem but there are some cases where the program works and others dont. Can someone help me??? Some of the numbers round and others dont
#include <stdio.h>
int main(void)
{
int size;
int i = 0;
float f = 0.0;
int pro = 0;
scanf("%d", &size);
int res[size];
int arr1[size];
int arr2[size];
for (i = 0; i < size; i++)
{
scanf("%d ", &arr1[i]);
scanf("%d ", &arr2[i]);
}
for (i = 0; i < size; i++)
{
f = arr1[i] / arr2[i];
pro = f;
f - pro;
f * 10;
if (f >= 5)
{
f + 1;
}
res[i] = f;
printf("\n %d \n", res[i]);
}
return 0;
}
Hi Friend!
Just check your code carefully. You wanted to do right thing but your code seems to have mistakes:
f = arr1[i] / arr2[i];
pro = f;
f - pro;
f * 10;
if (f >= 5)
{
f + 1;
}
In this part:
f - pro
does nothing (you probably forgot assignment)0
because f
equals to pro
after line above;Try debugging the code by including printf
s for various variables, e.g.
printf("F=\%d, PRO=%d, F-PRO=%d\n", f, pro, f-pro);