FORMAT SPECIFIER

This used to define the type of data while printing the value. 

int - %d

float - %f

char - %c

 

#include <stdio.h>

void main()

{

  int a=100;

  float b=20.50;

  char c=”h”;

  printf(“%d”,a);

  printf(“%f”,b);

  printf(“%c”,c);

}

 

If you want to remove the extra zeros (set decimal precision), you can use a dot (.) followed by a number that specifies how many digits that should be shown after the decimal point:

float myFloatNum = 3.5;

printf(“%f\n”, myFloatNum); // Default will show 6 digits after the decimal point
printf(“%.1f\n”, myFloatNum); // Only show 1 digit
printf(“%.2f\n”, myFloatNum); // Only show 2 digits
printf(“%.4f”, myFloatNum);   // Only show 4 digits

 

 

Scanf:this is used to take input from user on runtime.

#include<stdio.h>

void main()

{

  int principle,time;

  float rate,simpleIntrest;

  printf(“enter input in form 1principle 2 rate 3time”);

  scanf(“%d %f %d”,&principle,&rate,&time);

  simpleIntrest=(principle*rate*time)/100;

  printf(“%f”,simpleIntrest);

}

 

 

&:In C programming, the ampersand (&) is used as the address-of operator and is also used in bitwise operations.

                      Rate                                  principle

1

2

3

4

5

6

7

8

9

10

11

12

13

14

15

16

17

18

19

20


                         time       simpleIntrest