prog2 - else if(cont=='N goto Nocontinue else goto Retry...

Info iconThis preview shows pages 1–3. Sign up to view the full content.

View Full Document Right Arrow Icon
/* Matt Hergenrether CS2433 C/C++ Programming February 10th, 2009 2:00pm */ #include <stdio.h> void main(void) { int freq_table[101]; int i, n, mean, median, mode, count, mediannum, medianhold; char cont; mean = 0; mode =0; median = 0; count = 0; mediannum = 0; medianhold = 0; for(i=0; i<=100; i++) { freq_table[i]=0; } Top: printf("Enter a number in the range of [0 to 100]."); scanf("%d", &n); if (n < 0) { printf("Invalid Number\n"); goto Top; } else if ( n > 100) { printf("Invalid Number\n"); goto Top; } else { count++; /*setting up frequency table*/ for(i=0; i<=100; i++) { if (n == i) freq_table[i]++; } /*calculating mean*/ mean = (mean + n)/count; } Retry: printf("Would you like to enter another number (y or n).");
Background image of page 1

Info iconThis preview has intentionally blurred sections. Sign up to view the full version.

View Full DocumentRight Arrow Icon
scanf("%c", &cont); if (cont=='y') { goto Top; } else if (cont=='Y') { goto Top; } else if (cont=='n') { goto Nocontinue;
Background image of page 2
Background image of page 3
This is the end of the preview. Sign up to access the rest of the document.

Unformatted text preview: } else if (cont=='N') { goto Nocontinue; } else { goto Retry; } Nocontinue: /*calculatiing mode*/ for(i=0; i<=100; i++) { if( freq_table[i] > mode) mode = freq_table[i]; } /*calculating median*/ mediannum = count/2; for(i=0; i<=100; i++) { medianhold= medianhold + freq_table[i]; if (medianhold >= mediannum) { mean = i; break; } } printf("Total number of valid non negative integers entered is %d.\n", count); for(i=0; i<=100; i++) { printf("%d was entered %d times.\n", i, freq_table[i]); } printf("The mean of the numbers entered was %d.\n", mean); printf("The mean of the numbers entered was %d.\n",median); for(i=0; i<=100; i++) { if(freq_table[i]==mode) { printf("%d is a mode of the numbers entered.\n", i); } } }...
View Full Document

Page1 / 3

prog2 - else if(cont=='N goto Nocontinue else goto Retry...

This preview shows document pages 1 - 3. Sign up to view the full document.

View Full Document Right Arrow Icon
Ask a homework question - tutors are online