C I/O (input/output)

2018-12-29  本文已影响0人  玖_氼乚

Two commonly used functions for I/O (Input/Output) are

The scanf() function reads formatted input from standard input (keyboard) whereas the printf() function sends formatted output to the standard output (screen).

🌲C output (="hello world")

C output

🍀#include <stdio.h>
🍀int main()
🍀{
🍀 printf("C Programming");
🍀 return 0;
🍀}

🌲integer output

integer output

🍀#include <stdio.h>
🍀int main()
🍀{
🍀 int testInteger = 5;
🍀 printf("Number = %d", testInteger);
🍀 return 0;
🍀}

🌲integer input/output

integer input/output

🍀#include <stdio.h>
🍀int main()
🍀{
🍀 int testInteger;
🍀 printf("Enter an integer: ");
🍀 scanf("%d",&testInteger);
🍀 printf("Number = %d",testInteger);
🍀 return 0;
🍀}

🌲floats input/output

floats input/output

🍀#include <stdio.h>
🍀int main()
🍀{
🍀 float f;
🍀 printf("Enter a number: ");
🍀 scanf("%f",&f);
🍀 printf("Value = %f", f);
🍀 return 0;
🍀}

🌲character input/output

character input/output

🍀#include <stdio.h>
🍀int main()
🍀{
🍀 char chr;
🍀 printf("Enter a character: ");
🍀 scanf("%c",&chr);
🍀 printf("You entered %c.",chr);
🍀 return 0;
🍀}

🌲ASCII Code

The ASCII value of character 'g' is 103. When, 'g' is entered, 103 is stored in variable var1 instead of g.

🍀#include <stdio.h>
🍀int main()
🍀{
🍀 char chr;
🍀 printf("Enter a character: ");
🍀 scanf("%c",&chr);
🍀 printf("You entered %c.\n",chr);
🍀 printf("ASCII value of %c is %d.", chr, chr);
🍀 return 0;
🍀}

🌲character input/output

reference: programiz

上一篇下一篇

猜你喜欢

热点阅读