Write a program on various constants.

variables
#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.

  1. The program starts by including the standard input/output header file stdio.h and the non-standard conio.h header file which provides the getch() function.
  2. Inside the main() function, it declares four variables x, y, z and p with the int, float, char and double data types respectively.
  3. It assigns the value 20 to the variable x, the value 2e1 to the variable y, the value ‘a’ to the variable z and 3.2e20 to the variable p. It’s important to note that 2e1 and 3.2e20 are both in scientific notation. The number before the e is the mantissa and the number after the e is the exponent. So 2e1 is equal to 2*10^1 = 20.
  4. The program uses the printf() function to print the values of the variables x, y, z and p. The format specifiers used are %d for integer, %20.2f for floating point, %c for character and %.21f for double.
  5. The %20.2f format specifier is used to format the floating-point variable y. The 20 specifies the field width, and the .2 specifies the number of digits to be printed after the decimal point.
  6. The %c format specifier is used to format the character variable z. It prints the value of the variable as a single character.
  7. The %.21f format specifier is used to format the double precision variable p. The .21 specifies the number of digits to be printed after the decimal point.
  8. 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.

Leave a Reply

Your email address will not be published. Required fields are marked *

Scroll to top