Question-According to a study, the approximate level of intelligence of a person can be calculated using the following formula:
i = 2 + ( y + 0.5 x )
Write a program, which will produce a table of values of i, y and x, where y varies from 1 to 6, and, for each value of y, x varies from 5.5 to 12.5 in steps of 0.5.
Solution-
I don't what exactly author wants us to do here, i came with this solution. let me know if my opinion is wrong that would be really generous of you.
#include<stdio.h>
int main()
{
int x;
float y,i;
for(y=5.5;y<=12.5;y+=0.5)
{
for(x=1;x<=6;x++)
{
i=2+(y+(0.5*x));
printf("i=%f x=%d y=%f\n",i,y,x);
}
}
return 0;
}
i = 2 + ( y + 0.5 x )
Write a program, which will produce a table of values of i, y and x, where y varies from 1 to 6, and, for each value of y, x varies from 5.5 to 12.5 in steps of 0.5.
Solution-
I don't what exactly author wants us to do here, i came with this solution. let me know if my opinion is wrong that would be really generous of you.
#include<stdio.h>
int main()
{
int x;
float y,i;
for(y=5.5;y<=12.5;y+=0.5)
{
for(x=1;x<=6;x++)
{
i=2+(y+(0.5*x));
printf("i=%f x=%d y=%f\n",i,y,x);
}
}
return 0;
}
a little corection
ReplyDelete#include
int main()
{
int y;
float x,i;
for(x=5.5;x<=12.5;x+=0.5)
{
for(y=1;y<=6;y++)
{
i=2+(y+(0.5*x));
printf("i=%.2f\t\ty=%d\tx=%.2f\n",i,y,x);
}
}
return 0;}
Thanks :)
Delete