
























































































Study with the several resources on Docsity
Earn points by helping other students or get them with a premium plan
This page cannot be seen from the preview
Don't miss anything!

























































































Cover art by the author
- jmf
#include <stdio.h> /* Program three, with errors */ int main( void ) { int x, y; x = 10 y = x + 20; printf(The result is %d\n”,y); }
cc hello.c
ln hello.exe hello.obj stdio.lib
hello.exe
#include <stdio.h> int main( void ) { double v, tol; double rnom, rlow, rhigh; double inom, ilow, ihigh; double pnom, plow, phigh; printf(“This program determines current and power.\n”); printf(“Please enter the voltage source in Volts.\n”); scanf(“%lf”, &v); printf(“Please enter the nominal resistance in Ohms.\n”); scanf(“%lf”, &rnom); printf(“Please enter the resistor tolerance in percent.\n”); scanf(“%lf”, &tol); tol = tol/100.0; /* turn tolerance into a factor / rlow = rnom – rnomtol; rhigh = rnom + rnom*tol; inom = v/rnom; ihigh = v/rlow; ilow = v/rhigh; pnom = v * inom; plow = v * ilow; phigh = v * ihigh; printf(“Resistance (Ohms) Current (Amps) Power (Watts)\n”); printf(“%lf %lf %lf\n”, rnom, inom, pnom ); printf(“%lf %lf %lf\n”, rhigh, ilow, plow ); printf(“%lf %lf %lf\n”, rlow, ihigh, phigh ); }
double find_current( double voltage, double resistance ) { double current; current = voltage/resistance; return( current ); } You could also do this in one step:
#include <stdio.h> /* this is the prototype so the compiler can do type checking */ double find_current( double voltage, double resistance ); int main( void ) { .... } double find_current( double voltage, double resistance ) { return( voltage/resistance ); }
#define WALK_DOG 1 #define LET_OUT_CAT 2 #define COMB_WOMBAT 3 switch( choice ) { case WALK_DOG: /* c’mon poochie... / break; case LET_OUT_CAT: / there’s the door... / break; case COMB_WOMBAT: / first the shampoo... / break; / and so on */ }
#include <stdio.h> #include <math.h> #define VOLTAGE_DIVIDER 1 #define EMITTER 2 #define COLLECTOR_FEEDBACK 3 #define VBE. int main( void ) { int choice; give_directions(); choice = get_choice(); switch( choice ) { case VOLTAGE_DIVIDER: voltage_divider(); break; case EMITTER: emitter(); break; case COLLECTOR_FEEDBACK: collector_feedback(); break; default: /* tell user they’re not so bright... */ printf(“No such choice!\n”); break; } }