EG Information
Training Missions
Knowledge Bank
|
|
Enigma Group's Code Bank
Time and distance calculatorBy: mofm - Date Submitted: 2009-07-25 17:39:20 * Program to input 10 sets of data (time and distance) then output a table of time, distance and speed complete with totals and averages. No validation */ #include <stdio.h> #include <stdlib.h> #define MAX 3 void main(void) { float time[MAX],distance[MAX],speed[MAX]; float totaltime=0,totaldistance=0; float averagetime,averagedistance,averagespeed; char buff[20]; int i; /* Input */ for(i=0;i<=MAX-1;i++) { time[i]=atof(gets(buff)); printf("tEnter the distance:"); distance[i]=atof(gets(buff)); } /* Calculation */ for(i=0;i<=MAX-1;i++) { totaltime = totaltime +time[i]; totaldistance = totaldistance + distance[i]; speed[i] = distance[i] / time[i]; } averagetime = totaltime / MAX; averagedistance = totaldistance / MAX; averagespeed = totaldistance / totaltime; /* This is the true average speed */ /* Output*/ printf("nn Table of Results n"); printf("ttDistance(m)t Time(s)t Speed(m/s)nn"); for(i=0;i<=MAX-1;i++) { printf("tt%8.1ft%8.1ft%8.2fn",distance [i ],time [i ],speed [i ]); } printf("Totaltt%8.1ft%8.1fn",totaldistance,totaltime ); printf("Averagett%8.1ft%8.1ft%8.2fn",averagedistance,averagetime,averagespeed ); }
|
| Return to
c category list |
|
|
Who's Online
487 Guests, 100 Users ckryptix, TheRetech, Diznablo, Nicid1, Ios, viper0i0, rabbidmind, Nasrudin, CollapsingWalls, mehtaparag, bitstrike, jnony, C, Nusquam-Redono-Sapientia, bazcrown, saifulfaizan, The End, Ultraminor, psychomarine, st3alth, themastersinner, pgmrlink, login, lionaneesh, ishkur88, mahraja, Mac, chekifr, gandalf88, Vap0r, t0ast, tantrum6226, BnE, Distorted, Psiber_Syn, Ausome1, invas10n, oldgoat, freedaysbecumei, BinaryShinigami, Rex_Mundi, Red_beard, Strobeflux, s0m3nak3dguy, Descent, teehee, machupicchu, Genetix, Anandarl, NotMyOwn, thegamerdude, Godzila, popo12341234, RedEvolution, velocity_b, myne17, teto111, aVoid, Central-Gsm, 1101, JackalReborn, InjectioN, h4lted, c0re, DisPater, markt4death, splatta, Jackowacko, saint556, Pyron2312, Azerion, howsens, white.hat.gone.bad, vazzilly, pwunkz, Inverted, QuarterCask, Infernoe11, deskata, cr4ck3rj4ck, Blizer, jasonmax, j0sh, gwenwavor, N4g4c3N, spizeyboy, Network X, Uino59, Jae Cee, ianFDK, saykov, medhaavee, zofy, demonkiller410, Stumble, SaMTHG, kishore, Raze, helasraizam, Venom1019 |
| |
|
|
|
|
|