Answers for "c float precision"

C
4

c float

// create float and assign value
// print float value to console
#include <stdio.h>

int main()
{
    float pi = 3.14;
    float dollars;
    dollars = 32.27;

    printf("I have %f dollars", dollars);       
  
	// controls the number of numbers shown after the decimal point
    printf("\nI have %0.2f dollars", dollars);
Posted by: Guest on April-09-2022
3

c float precision

#include <stdio.h>

int main (){
    float a;
    printf("\nEnter a real number here please: ");
    scanf("%f",&a);
    
    printf("\nPrinting Number with different precision: ");
    printf("\n  Number default precision: %f", a);
    printf("\n  Number in (0 d.p.): %.0f", a);
    printf("\n  Number in (1 d.p.): %.1f", a);
    printf("\n  Number in (2 d.p.): %.2f", a);
    printf("\n  Number in (3 d.p.): %.3f", a);
    printf("\n  Number in (3 d.p.): %.4f", a);
    return 0;
}
Posted by: Guest on May-11-2022

Code answers related to "C"

Browse Popular Code Answers by Language