Answer to Question #237502 in C for Aadi

Question #237502
Write a program that inserts 25 random integers from 0 to 100 in sorted order in a linked list.
The program should calculate the sum of the elements and the floating-point average of the
element
1
Expert's answer
2021-09-15T17:24:21-0400


    #include <stdio.h>
    #include <stdlib.h>
    #include <assert.h>
    #include <time.h>
    int randRange(int m)
    {
       int limit;
       int n;
   
       limit = RAND_MAX - (RAND_MAX % m);
   
       while((n = rand()) >= limit);
   
       return n % m;
   }
   
   int
   main(int argc, char **argv)
   {
       int i,sum;
       float average;
       srand(time(0));
   
       for(i = 0; i < 25; i++) {
           printf("%d ->", randRange(100)+1);
       }
       putchar('\n');
        for(i=0;i<25;i++){
              sum=sum+i;
              average=sum/25;
          }
          printf("Sum of Numbers is:%d",sum);
          printf("\nAverage is: %.2f",average);
       return 0;
   }

Need a fast expert's response?

Submit order

and get a quick answer at the best price

for any assignment or question with DETAILED EXPLANATIONS!

Comments

No comments. Be the first!

Leave a comment

LATEST TUTORIALS
New on Blog
APPROVED BY CLIENTS