#include<stdio.h>
int main()
{
int t,j,i;
scanf("%d",&t);//entering test cases
float arr[t];
char str[t][3];// declaring array as per as test cases
for(i=0;i<t;i++)
{j=0;
scanf("%f %s",&arr[i],str[i]);//entering the no: to be converted and un
its for the required conversion
if(str[i][j]=='k')//checking if unit is kg
{
arr[i]=(float)arr[i]*2.2046;
printf("%d %0.4f lb\n",i+1,arr[i]);
}
else
if(str[i][j]=='l')// checking if it is lb or l
{
if(str[i][++j]=='b')// checking if it lb
{
arr[i]=(float)arr[i]*0.4536;
printf("%d %0.4f kg\n",i+1,arr[i]);
}
else
if(str[i][++j]=='\0')//checking if it l
{
arr[i]=(float)arr[i]*0.2642;
printf("%d %0.4f g\n",i+1,arr[i]);
}
}
else if(str[i][j]=='g')//checking if it g
{
arr[i]=(float)arr[i]*3.7854;
printf("%d %0.4f l\n",i+1,arr[i]);
}
}
return 0;
}
input:
5
1 kg
2 l
7 lb
3.5 g
0 l
output:
1 2.2046 lb
3 3.1752 kg
4 13.2489 l
BUT IF I REMOVE THE LINE [color=#FF0000][b]if(str[i][++j]=='\0')[/b][/color]
PROGRAM RUNS FINE.. Not even that .. it got accepted!!
[color=#FF0040]but my doubt is why so ???
str[i][++j] will be a null character for that string.. no matter what[/color]