Print Hello World
#include <stdio.h> // include information about standard library
main(){ //function name
printf("hello, world");
}
Variables and Arithmetic Expression
#include <stdio.h>
main(){
int fahr, celsius;
int lower, upper, step;
}
The For Statement
#include <stdio.h>
main(){
int fahr;
for (fahr = 0; farh <= 300; fahr = fahr + 20)
printf("%3d %5.1f\\n, fahr, (5.0/9.0)*(fahr-30));
}
#define LOWER 0
#define UPPER 300
c = getchar(); //reads the next input character
putchar(c); //print the character
The simplest (i.e., most primitive) form of character I/O is getchar() and putchar(), which read and print a single character
EOF(end of file) is an integer defined in <stdio.h>
scanf() is one of the commonly used function to take input from the user
#include <stdio.h>
int main()
{
int testInteger;
printf("Enter an integer: ");
scanf("%d", &testInteger);
printf("Number = %d",testInteger);
return 0;
}
ASCII Value
#include <stdio.h>
int main()
{
char chr;
printf("Enter a character: ");
scanf("%c", &chr);
// When %c is used, a character is displayed
printf("You entered %c.\\n",chr);
// When %d is used, ASCII value is displayed
printf("ASCII value is %d.", chr);
return 0;
}