Write a program to declare variables with different names and data types.

DATA TYPE
#include<stdio.h>
#include<conio.h>
int main()
{
	int Num=12;
	int WEIGHT=25;
	float HeIgHt=4.5;
	char name[10]="NESARK";    //not more then ten 
	printf("Num: %d \nWeight: %d \nHeight: %g \nName: %s",Num,WEIGHT,HeIgHt,name);
	getch();
}


/*The variable name may be a combination of uppercase and lowercase characters,
For int use %d or %i,
For float use %f or %g, */

The above code is a C program that declares and assigns values to four variables: an integer variable Num, an integer variable WEIGHT, a floating-point variable HeIgHt and a character array name.

  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 Num, WEIGHT, HeIgHt and name with the int, int, float and char array data types respectively and assigns values to them.
  3. The program uses the printf() function to print the values of the variables Num, WEIGHT, HeIgHt and name using format specifiers %d,%d,%g and %s respectively.
  4. The getch() function is used to wait for the user to press a key before terminating the program.

The program also includes comments explaining the code and some rules for naming a variable in C language.

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.

Also, you are right that variable names in C can be a combination of uppercase and lowercase characters. And also, it’s good to use format specifiers which are specific to the data types, like %d for int, %g for float and %s for char array.

Thanks

Write a program to declare variables with different names and data types.

Leave a Reply

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

Scroll to top