Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

program in C laguage the first problem requires that the student take in charact

ID: 3871500 • Letter: P

Question

program in C laguage the first problem requires that the student take in character input from a prompt "> " on a character by character basis. There should be no more than 80 characters in a single line of input. You might look at the library function getchar() to help with this. Then, output the resulting string in the line in reverse. Note that a string must have a '' at the end of the character array. The second problem is to determine some basic statistics on set of integers. The required statistics are the: mean, mode, min, max, and median. The set of integers to use in your array is: 36, 14, 9, 24, 16, 25, 9, 13, 2, 28. Build a table like the previous homework to show your results. You should be able to find definitions for these statistical terms on the web.

Explanation / Answer

#include<stdio.h>
#include<stdlib.h>


int main(){

    char data[80];
    int i,j ,temp;
    int count = 0;
    int max_count;
    int mode;
    double median;
    double mean;
    int min,max;
    char ch;
    printf("Enter characters ");
    count = 0;
    ch = 'a';
    while (ch != ' '){
         ch = getchar();
         data[count] = ch;
         count++;
         if (count > 80){
             printf("Number of characters in a single line exceeding 80 ");
             return 0;
         }
    }
  
   
    for (i = count-1; i >= 0; i--)
        printf("%c",data[i]);
    printf(" ");
    int a[] = {36,14,9,24,16,25,9,13,2,28};
    min =a[0];
    max = a[0];
    int sum = 0;
    for (i = 0; i<10; i++){
        sum = sum + a[i];
        if (max < a[i]){
           max = a[i];
        }
        if (min > a[i]){
           min = a[i];
        }
    }
    max_count = 0;
    mode = a[0];
    for (i = 0; i<10; i++){
      count = 0;
      for (j = 0; j<10; j++){
          if (a[i] == a[j])
              count++;
      }
      if (count > max_count){
          max_count = count;
          mode = a[i];
      }
    }
    for (i = 0; i<10; i++){
        for (j = i; j<10; j++){
            if (a[i] > a[j]){
                temp = a[i];
                a[i] = a[j];
                a[j] = temp;
            }
        }
    }
    median = (a[4] + a[5])/2;
    mean = sum/10;

    printf("Max : %d ",max);
    printf("Min : %d ",min);
    printf("Median : %.2f ",median);
    printf("Mode : %d ",mode);
    printf("Mean : %.2f ",mode);
   

}