Programmin in C
Programmin in C
PROGRAMING IN C
A Simple C program
#include <stdio.h> int main( ) { printf("hello, world"); return 0; }
} printf("hello, world");
n = 511; printf("What is the value of %d in octal?", n); printf("%s! %d decimal is %o octal\n", "Right", n, n);
What is the value of 511 in octal? Right! 511 decimal is 777 octal
== equal to != not equal to > greater than < less than >= greater than or equal to <= less than or equal to
for Statement
for( initialization; expression; increment ) statement
initialization; while( expression ) { statement increment; }
for Statement
sum = 0;
for( i=0; i<n; i++)sum = sum + i;
Arithmetic
x = a%b;
c = c + 'A' - 'a';
main( ) { char c; while( (c=getchar( )) != '\0' ) if( 'A'<=c && c<='Z' ) putchar(c+'a'-'A'); else putchar(c); }
Arrays
int x[10]; x[0], x[1], x[2], ..., x[9]
main( ) { int n, c; char line[100]; n = 0; while( (c=getchar( )) != '\n' ) { if( n < 100 ) line[n] = c; n++; } printf("length = %d\n", n); }