How many of you...
Dheeraj Lohana pointed out that the examples wouldn't compile as
I presented in class. Some c compilers don't require the include
statement for standard librarys. (My compiler didn't complain...)
The line
#include<stdio.h>
tells the compiler that you want to use the functions which are
declared in the library for standard input/output. printf
and scanf don't
belong to the core C language, so you've to add this line in the
beginning of the program if you're doing in/output.
#include<stdio.h> int main() { /* this is the classic * hello world example */ printf("hello, world!\n"); }
#include<stdio.h> int main() { /* what's the difference to the * program above? * what are the rules for placing * semicola? */ printf("hello "); printf("world!"); printf("\n"); }
#include<stdio.h> int main(int argc, char** argv) { /* you don't have to understand * all of this... */ printf("%s\n",argv[1]); }
#include<stdio.h> int main() { int i; int j; int sum; i = 1; j = 2; sum = i+j; printf("i, j, i+j, %d %d %d\n",i,j,i+j); }
#include<stdio.h> int main() { /* what does this compute? * do you remember more digits of pi? */ float pi, r, A; pi = 3.1415; r = 2.0; A = pi * r * r; printf("r, A, %f %f\n",r,A); }
#include<stdio.h> int main() { float r; scanf("%f",&r); printf("%f",r); }
#include<stdio.h> int main() { float pi; float r; float A; pi = 3.1415; printf("enter radius:"); scanf("%f",&r); A = pi * r * r; printf("r, A, %f %f\n",r,A); }
How many of you are using