Write a C Program to Perform input/output of all basic data types - Basic C program



 

Write a C Program to Perform input/output of all basic Data Types


Write a C program to demonstrate input and output of all basic and derived types. How to use scanf() and printf() function perform input and output on primitive types in C programming.


  • Note:

\n is an escape sequence character used to print new line (move to next line).
The getchar() function reads single character and stores to some character variable. During a character input suppose we input C and then enter which is also considered as a character. Internally, getchar() reads and stores C character to charVal and tries to store the enter character to uCharVal. This is because I have used an extra getchar() to eliminate the enter character.

  • Signed - it takes input from users in negative type value.
  • Unsigned - it takes input from users in positive type value.


Solution Code:
//Write a C Program to Perform input/output of all Basic Data Type By CodexRitik. #include <stdio.h> int main() { //char data types(char,unsigned char) char charVal; unsigned char uCharVal; //all number data types(short,int,long,long long) short shortVal; unsigned short uShortVal; int intVal; unsigned int uIntVal; long longVal; unsigned long uLongVal; long long longLongVal; unsigned long long uLongLongVal; //floating number data types(float,double,long double) float floatVal; double doubleVal; long double longDoubleVal; //for display any msg or value we use printf.
//for taking user input we use scanf. printf("Enter a character: "); charVal = getchar(); getchar(); // <-- Dummy getchar() to capture enter printf("Enter another character: "); uCharVal = getchar(); getchar(); // <-- Dummy getchar() to capture enter printf("Enter a signed short value: "); scanf("%hi", &shortVal); printf("Enter an unsigned short value: "); scanf("%hu", &uShortVal); printf("Enter an signed integer value: "); scanf("%d", &intVal); printf("Enter an unsigned integer value: "); scanf("%lu", &uIntVal); printf("Enter a signed long value: "); scanf("%ld", &longVal); printf("Enter an unsigned long value: "); scanf("%lu", &uLongVal); printf("Enter a signed long long value: "); scanf("%lld", &longLongVal); printf("Enter an unsigned long long value: "); scanf("%llu", &uLongLongVal); printf("Enter a float value: "); scanf("%f", &floatVal); printf("Enter a double value: "); scanf("%lf", &doubleVal); printf("Enter a long double value: "); scanf("%Lf", &longDoubleVal); /* * Print the value of all variable */ printf("\nYou entered character: '%c' \n", charVal); printf("You entered unsigned character: '%c' \n\n", uCharVal); printf("You entered signed short: %hi \n", shortVal); printf("You entered unsigned short: %hu \n\n", uShortVal); printf("You entered signed int: %d \n", intVal); printf("You entered unsigned int: %lu \n\n", uIntVal); printf("You entered signed long: %ld \n", longVal); printf("You entered unsigned long: %lu \n\n", uLongVal); printf("You entered signed long long: %lld \n", longLongVal); printf("You entered unsigned long long: %llu \n\n", uLongLongVal); printf("You entered float: %f \n", floatVal); printf("You entered double: %lf \n", doubleVal); printf("You entered long double: %Lf \n", longDoubleVal); return 0; }



Input Output Preview:





Note:

This Code is Verified by CodexRitik.If any error occurs then Comment correct code Below in comment box.

Disclaimer:-

The above hole solution is generated by the CodexRitik . if any of the query regarding this post or website fill the following contact form Thank You.

Write a C Program to Perform input/output of all basic data types - Basic C program Write a C Program to Perform input/output of all basic data types - Basic C program Reviewed by CodexRitik on January 03, 2021 Rating: 5

No comments:

Powered by Blogger.