C Basic data types Syntax: Int, Float, Character and Double
In this post, I'll be discussing C language basic data types that are int, float, double and char.
What are these?
- int - integer: used for a whole number input.
- float - floating point: a number with a fractional part.
- double - a double-precision floating point value.
- char - a single character.
C Basic Datatype Syntax
Method 1 (int method):
#include<stdio.h>
int main() // the int needs to add return
{
//decleration of variable
char c; // char data type variable decleration
int i; // int data type variable decleration
float f; // float data type variable decleration
double d; // double data type variable decleration
printf("Enter Any Character ");
scanf("%c", &c); // %c is used to get character value
printf("Enter Any Integer ");
scanf("%i", &i); // %i or %d is used to get integer value
printf("Enter Any Float ");
scanf("%f", &f); // %f is used to get float value
printf("Enter Any Double ");
scanf("%if", &d); // %lf is used to get double value
printf("\n The value of Character you entered: %c",c);
printf("\n The value of Integer you entered: %i",i);
printf("\n The value of Float you entered: %f",f);
printf("\n The value of Double you entered: %if",d);
return 0;
}
int main() // the int needs to add return
{
//decleration of variable
char c; // char data type variable decleration
int i; // int data type variable decleration
float f; // float data type variable decleration
double d; // double data type variable decleration
printf("Enter Any Character ");
scanf("%c", &c); // %c is used to get character value
printf("Enter Any Integer ");
scanf("%i", &i); // %i or %d is used to get integer value
printf("Enter Any Float ");
scanf("%f", &f); // %f is used to get float value
printf("Enter Any Double ");
scanf("%if", &d); // %lf is used to get double value
printf("\n The value of Character you entered: %c",c);
printf("\n The value of Integer you entered: %i",i);
printf("\n The value of Float you entered: %f",f);
printf("\n The value of Double you entered: %if",d);
return 0;
}
Method 2 (void method):
#include<stdio.h>
void main() // the void doesn't need to add return
{
//decleration of variable
char c; // char data type variable decleration
int i; // int data type variable decleration
float f; // float data type variable decleration
double d; // double data type variable decleration
printf("Enter Any Character ");
scanf("%c", &c); // %c is used to get character value
printf("Enter Any Integer ");
scanf("%d", &i); // %d or %i is used to get an integer value
printf("Enter Any Float ");
scanf("%f", &f); // %f is used to get a float value
printf("Enter Any Double ");
scanf("%lf", &d); // %lf is used get double value
printf("\n The value of Character you entered: %c",c);
printf("\n The value of Integer you entered: %d",i);
printf("\n The value of Float you entered: %f",f);
printf("\n The value of Double you entered: %if",d);
}
void main() // the void doesn't need to add return
{
//decleration of variable
char c; // char data type variable decleration
int i; // int data type variable decleration
float f; // float data type variable decleration
double d; // double data type variable decleration
printf("Enter Any Character ");
scanf("%c", &c); // %c is used to get character value
printf("Enter Any Integer ");
scanf("%d", &i); // %d or %i is used to get an integer value
printf("Enter Any Float ");
scanf("%f", &f); // %f is used to get a float value
printf("Enter Any Double ");
scanf("%lf", &d); // %lf is used get double value
printf("\n The value of Character you entered: %c",c);
printf("\n The value of Integer you entered: %d",i);
printf("\n The value of Float you entered: %f",f);
printf("\n The value of Double you entered: %if",d);
}
Comments
Post a Comment