EG Information

Main Index
EG Manual
Disclaimer
Legal Information
Hall of Fame
Hall of Shame
Member Rankings
Members List
Meet the Staff

Training Missions

Read Me First New
Basic Skills
Realistic Scenarios
Cryptography
Software Cracking
Linux ELF Binary Cracking
Logical Thinking
Programming
Patching
Steganography
Deface This Wall
/dev/null
/dev/urandom

Knowledge Bank

Discussion Forums
Enigma Chat New
RSS Feeds RSS
Articles / Tutorials
Videos
Online EG MP3 Player Radio
Enigma Zine
Downloads
Tools New

Code Resources

Submit Code
Ajax
ASM
Bash
C
CPP
Csharp
Delphi
Haskell
Java
Javascript
Jython
Lisp
mIRC
MySQL
Perl
PHP
Python
QBASIC
VisualBasic

Hakipedia: An open collaborative for all your information security needs.

The Urinal

Click Here To Vote For EG!

Has Enigma Group Helped You? Then Help Us By Advertising For Us. Place One Of The Following Images On Your Site.

enigma group

enigma group

enigma group

enigma group

Enigma Group's Code Bank


Time and distance calculator

By: mofm  -  Date Submitted: 2009-07-25 17:39:20

  1. * Program to input 10 sets of data (time and distance) then output
  2. a table of time, distance and speed complete with totals and averages.
  3.  
  4. No validation
  5. */
  6. #include <stdio.h>
  7. #include <stdlib.h>
  8. #define MAX 3
  9. void main(void)
  10. {
  11. float time[MAX],distance[MAX],speed[MAX];
  12. float totaltime=0,totaldistance=0;
  13. float averagetime,averagedistance,averagespeed;
  14. char buff[20];
  15. int i;
  16.  
  17.  
  18. /* Input */
  19. for(i=0;i<=MAX-1;i++)
  20. {
  21. printf("Data set %dn",i+1);
  22. printf("tEnter the time:");
  23. time[i]=atof(gets(buff));
  24. printf("tEnter the distance:");
  25. distance[i]=atof(gets(buff));
  26. }
  27.  
  28.  
  29. /* Calculation */
  30. for(i=0;i<=MAX-1;i++)
  31. {
  32. totaltime = totaltime +time[i];
  33. totaldistance = totaldistance + distance[i];
  34. speed[i] = distance[i] / time[i];
  35. }
  36. averagetime = totaltime / MAX;
  37. averagedistance = totaldistance / MAX;
  38. averagespeed = totaldistance / totaltime; /* This is the true average speed */
  39.  
  40. /* Output*/
  41. printf("nn Table of Results n");
  42. printf("ttDistance(m)t Time(s)t Speed(m/s)nn");
  43. for(i=0;i<=MAX-1;i++)
  44. {
  45. printf("tt%8.1ft%8.1ft%8.2fn",distance[i],time[i],speed[i]);
  46. }
  47. printf("Totaltt%8.1ft%8.1fn",totaldistance,totaltime);
  48. printf("Averagett%8.1ft%8.1ft%8.2fn",averagedistance,averagetime,averagespeed);
  49. }
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