1. ## unable to remember

can anyone please tell me what is the specifier for float and double datatypes? i know its %d for int datatypes and %c for char datatypes. unable to find it anywhere as well. thanks in advance!!!

2. %f and %lf

3. printf family: %f for both float and double.
scanf family: %f for float and %lf for double.

google for "scanf man" or "printf man" depending on what type of function you want to use.

4. ## the actual problem

i am facing this problem actually which i thought was due to a mistake in my %specifier but after making the correction also the problem persisted. the problem is whatever the value of the 4 variables i give the answer always comes out to be 0.0000. here is the code and everything:
Code:
```/*very basic program. Just revising for fun*/

/* c program to make the code for the following question:
the frequency 'n' of a vibrating string which depends on length 'l',
tension'T',and linear density 'm' is given by n=(k/l)sqrt(T/m) where
k is a constant.write a c program to find n when l=50,60,70,80 cm. i might
be programming for any value of l*/

#include<stdio.h>
#include<conio.h>
#include<stdlib.h>
#include<math.h>/*the maths library*/

int main()
{
/*i will be writting this for integer values. since it is a program
to be used for scientific calculations, it would be better to use floats
or doubles but for the sake of simplicity, the compensation.*/

int length,tension,linear_density,constant;
float frequency=0;/*i am forced to make the frequency as float since the
answer will be comming in decimals*/
char ch;
printf("\n Enter value of tension:");
scanf("%d",&tension);
printf("\n Enter value of linear density:");
scanf("%d",&linear_density);
printf("\n Enter value of constant:");
scanf("%d",&constant);
while(1)
{
printf("\n Enter value of length:");
scanf("%d",&length);
frequency=(constant/length)*sqrt(tension/linear_density);
printf("\n Frequency is given by:%f",frequency);
fflush(stdin);
printf("\n Continue:");
scanf("%c",&ch);
if(ch=='n')break;
}
getch();

return 0;
}```

5. Probably because you are dividing an int by an int here:
Code:
`frequency=(constant/length)`
This will NOT yield a decimal number, it will yield a whole number in floating point form. Eg, if constant is 5 and length is 3, frequency will be 0.0f.

You need to cast the ints to get the arithmetic to work properly:
Code:
`frequency=(float)constant/(float)length`

6. <code>
/*very basic program. Just revising for fun*/

/* c program to make the code for the following question:
the frequency 'n' of a vibrating string which depends on length 'l',
tension'T',and linear density 'm' is given by n=(k/l)sqrt(T/m) where
k is a constant.write a c program to find n when l=50,60,70,80 cm. i might
be programming for any value of l*/

#include<stdio.h>
#include<conio.h>
#include<stdlib.h>
#include<math.h>/*the maths library*/

int main()
{
/*i will be writting this for integer values. since it is a program
to be used for scientific calculations, it would be better to use floats
or doubles but for the sake of simplicity, the compensation.*/

int length,tension,linear_density,constant;
float frequency=0;/*i am forced to make the frequency as float since the
answer will be comming in decimals*/
char ch;
printf("\n Enter value of tension:");
scanf("%d",&tension);
printf("\n Enter value of linear density:");
scanf("%d",&linear_density);
printf("\n Enter value of constant:");
scanf("%d",&constant);
system("pause");
while(1)
{
printf("\n Enter value of length:");
scanf("%d",&length);

// This is what i added...
printf("--> %d\n", constant);
printf("--> %d\n", length);
printf("%f", sqrt(tension/linear_density));
//>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>

frequency=(constant/length)*sqrt(tension/linear_density);
printf("\n Frequency is given by:%f",frequency);
fflush(stdin);
printf("\n Continue:");
scanf("%c",&ch);
if(ch=='n')break;
}
getch();

return 0;
}
</code>
check this!

7. Originally Posted by nullifyed
<code>

Code:
```/*very basic program. Just revising for fun*/

/* c program to make the code for the following question:
the frequency 'n' of a vibrating string which depends on length 'l',
tension'T',and linear density 'm' is given by n=(k/l)sqrt(T/m) where
k is a constant.write a c program to find n when l=50,60,70,80 cm. i might
be programming for any value of l*/

#include<stdio.h>
#include<conio.h>
#include<stdlib.h>
#include<math.h>/*the maths library*/

int main()
{
/*i will be writting this for integer values. since it is a program
to be used for scientific calculations, it would be better to use floats
or doubles but for the sake of simplicity, the compensation.*/

int length,tension,linear_density,constant;
float frequency=0;/*i am forced to make the frequency as float since the
answer will be comming in decimals*/
char ch;
printf("\n Enter value of tension:");
scanf("%d",&tension);
printf("\n Enter value of linear density:");
scanf("%d",&linear_density);
printf("\n Enter value of constant:");
scanf("%d",&constant);
system("pause");
while(1)
{
printf("\n Enter value of length:");
scanf("%d",&length);

// This is what i added...
printf("--> %d\n", constant);
printf("--> %d\n", length);
printf("%f", sqrt(tension/linear_density));
//>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>

frequency=(constant/length)*sqrt(tension/linear_density);
printf("\n Frequency is given by:%f",frequency);
fflush(stdin);
printf("\n Continue:");
scanf("%c",&ch);
if(ch=='n')break;
}
getch();

return 0;
}
</code>
check this!```
Maybe this helps others read it. I've learnt this from someone .

You are doing integer division instead of floating point division

1) Change this:

printf("%f", sqrt(tension/linear_density));

to this:

printf("%f", sqrt((tension + 0.0)/linear_density));

2) Change this:

frequency=(constant/length)*sqrt(tension/linear_density);

to this:

frequency=((constant+0.0)/length)*sqrt((tension+0.0)/linear_density);

3) Remove this:

fflush(stdin);

It has undefined behavior.