CSCI 1730 March 27 th, 2012. Text System Programming with C and Unix by Hoover Ch 1: Introduction Ch...
-
Upload
lindsay-hunter -
Category
Documents
-
view
214 -
download
0
Transcript of CSCI 1730 March 27 th, 2012. Text System Programming with C and Unix by Hoover Ch 1: Introduction Ch...
TextSystem Programming with C and Unix by
Hoover Ch 1: Introduction Ch 2: Bits, Bytes and Data Types Ch 3: Arrays and Strings Ch 4: Pointers and Structures
Ch 5: Input/OutputCh 6: Program Management
Ch 7: System CallsCh 8: Libraries Ch 9: Scripting Languages
Read sections in Ch. 1:Text editors & how to use (we’ve covered
this)How to debug
try out the sample programs providesProgram development
C review – 4 data types
/* A review of the basic data types in C. (pg 36) */
#include <stdio.h>
int main(){int x,y;char a;float f,e;double d;
x=4;y=7;a='H';f=-3.4;d=54.123456789;e=54.123456789;
printf("%d %c %f %lf\n",x,a,e,d);printf("%d %c %.9f %.9lf\n",x,a,e,d);}
C review – arithmetic
/* A review of the basic arithmetic operators in C. (pg 37) */
#include <stdio.h>
int main(){int x,y;int r1,r2,r3,r4,r5;
x=4;y=7;r1=x+y;r2=x-y;r3=x/y;r4=x*y;printf("%d %d %d %d\n",r1,r2,r3,r4);
r3++;r4--;r5=r4%r1;printf("%d %d %d\n",r3,r4,r5);}
C review – loops#include <stdio.h>
/* A review of the loop types in C. (pg 38) */int main(){int i,x;
x=0;for (i=0; i<4; i++) { x=x+i; printf("%d\n",x); }while (i<7) { x=x+i; i++; printf("%d\n",x); }do { x=x+i; i++; printf("%d\n",x); }while (i<9);}
C review – blocks
/* A review of conditionals and blocks in C. (pg 39) */
#include <stdio.h>
int main(){int i,x;
x=0;for (i=0; i<5; i++) { if (i%2 == 0 || i == 1) x=x+i; else x=x-i; printf("%d\n",x); }}