2/07/2016

Float value in c programming and something more

float value
example of float value
12.6
13.7
3.0
-------------------------------------------
#include<stdio.h>
#include<conio.h>
void main()
{
float a,b,c;
printf("Please enter two numbers:");
scanf("%f%f",&a,&b);
c=a+b;
printf("Sum=%f",c);
getch();
}
Output:
Please enter two numbers:34 6
Sum=40.000000
Other output:
Please enter two numbers:23.5 6.3
Sum=29.800000
------------------------------------------
for float value
5/2=2.500000
2/2=1.000000
---------------------------------------
#include<stdio.h>
#include<conio.h>
void main()
{
float a,b,c;
printf("Enter numbers:");
scanf("%f%f",&a,&b);
c=a/b;
printf("%f",c);
getch();
}
Output:
Enter numbers:14 8
1.750000
Other output:
Enter numbers:8.4 2.4
3.500000
--------------------------------------------
#include<stdio.h>
#include<conio.h>
void main()
{
int a=20;
a=a+1;
printf("%d",a);
getch();
}
Output:
21
--------------------------------------------
#include<stdio.h>
#include<conio.h>
void main()
{
int a=20;
int b=10;
a=a+2;
b=b-1;
printf("%d",a+b);
getch();
}
Output:
31
------------------------------------------
#include<stdio.h>
#include<conio.h>
void main()
{
float a=5,b;
a=b;
printf("%d",b);
getch();
}
Output:
0.000000
-------------------------------------------------------------
#include<conio.h>
#include<stdio.h>
void main()
{
float a=5,b;
b=a;
printf("%f",b);
getch();
}
Output:
5.000000
--------------------------
Note:-Here if value of 'a' is known and value of 'b' is equal to 'a' then must right 'b=a' and then value of b becomes 5.
        Unknown value always in left side.

-------------------------------------------------
#include<stdio.h>
#include<conio.h>
void main()
{
float a;
float b;
a=22.0/7.0;
b=22/7;
printf("%f",a);
printf("\n%f",b);
getch();
}

Output:
3.142857
3.000000




No comments:

Post a Comment