Code Point Blog
Iam presenting here ,all type of knowledge if you want to interest knowing about any topic then click below thumbnail view button and knowing.
In C, input is typically read from the keyboard, while output is displayed on the screen. C provides several standard library functions for input and output operations, such as:
1.printf() :
This function is used to display output on the screen. It allows you to print formatted text, variables, and constants.
#include <stdio.h>
int main(){
int age= 25;
printf("My age is %d years.\n",age);
return 0;
}
2.scanf() :This function is used to read input from the keyboard. It allows you to read data into variables based on specified format specifiers.
#include <stdio.h>
int main() {
int age;
printf("Enter your age: ");
scanf("%d", &age);
printf("You entered: %d\n", age);
return 0;
}
}
3.puts() and gets() :These functions are used for simple input/output. 'puts()' prints a string to the screen with a newline, and 'gets()' reads a line of text from the keyboard.
#include <stdio.h>
int main() {
char name[50];
printf("Enter your name: ");
gets(name);
printf("Hello, %s!\n", name);
return 0;
}
}
4.getchar() and putchar() :These functions are used to read a single character from the keyboard and print a single character on the screen, respectively.
#include <stdio.h>
int main() {
char ch;
printf("Enter a character: ");
ch = getchar();
putchar(ch);
return 0;
}
}
}