#include<stdio.h>
#include<conio.h>
int main()
{
int x;
float y;
char z;
double p;
x=20;
y=2e1; //e is called mantissa exp 2.4561 is the mantissa and +3 is the exponent//
z='a'; //single quotation mark use for one character and double quotation mark use for string//
p=3.2e20;
printf("\n %d %20.2f %c %.21f",x,y,z,p);
getch();
}
The above code is a C program that declares and assigns values to four variables: an integer variable x, a floating-point variable y, a character variable z, and a double precision variable p.
- The program starts by including the standard input/output header file
stdio.hand the non-standard conio.h header file which provides thegetch()function. - Inside the
main()function, it declares four variablesx,y,zandpwith the int, float, char and double data types respectively. - It assigns the value 20 to the variable
x, the value 2e1 to the variabley, the value ‘a’ to the variablezand 3.2e20 to the variablep. It’s important to note that2e1and3.2e20are both in scientific notation. The number before theeis the mantissa and the number after theeis the exponent. So 2e1 is equal to 2*10^1 = 20. - The program uses the
printf()function to print the values of the variablesx,y,zandp. The format specifiers used are%dfor integer,%20.2ffor floating point,%cfor character and%.21ffor double. - The
%20.2fformat specifier is used to format the floating-point variabley. The20specifies the field width, and the.2specifies the number of digits to be printed after the decimal point. - The
%cformat specifier is used to format the character variablez. It prints the value of the variable as a single character. - The
%.21fformat specifier is used to format the double precision variablep. The.21specifies the number of digits to be printed after the decimal point. - The
getch()function is used to wait for the user to press a key before terminating the program.
It’s important to note that the getch() function is not a part of the standard C library, it is provided by the non-standard conio.h header file and it’s use is not recommended in most cases.
Thanks
Write a program on various constants.