Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8825307
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 14, 20262026-06-14T06:50:49+00:00 2026-06-14T06:50:49+00:00

I need to make a C program to read the number of students( 1<=students<=25

  • 0

I need to make a C program to read the number of students(1<=students<=25) in a class and for every student to read his exam score ex 10/20 15/20 etc(1<=score<=20) and print the max and the max score of students and the average score of class.

I made the program but it performs the for loop only once for some reason.

Can you please help me understand why?

here is the code :

#include <stdio.h>

int main(void) {
    int m,i,b,sum,min,max,mo;
    sum=0;
    while (m<1 || m>25) {
            printf("give number of students ");
            scanf("%d",&m);
    }
    for (i=1; i<(m+1); i++) {
            while (b<1 || b>20) {
            printf("give score of  %d student",i);
            scanf("%d",&b);
            }

            if(i==1) {
                    min=b;
                    max=b;
            }
            else {
                    if(b<min) min=b;
                    if(b>max) max=b;
            }
            sum=sum+b;
    }
    mo=sum/m;
    printf("max is  %d and min is  %d and avg is  %d",max,min,mo);
}
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-14T06:50:50+00:00Added an answer on June 14, 2026 at 6:50 am

    First – initialize your variables:

    int m,i,b,sum,min,max,mo; // these are declared and uninitialized
    
    m = 0;  // now it's initialized to 0
    i = 0;
    ...
    

    If you don’t initialize them to something, you don’t know what they are to start with.

    Second – You need to change the value of b:

    for (i=1; i<(m+1); i++) {
            while (b<1 || b>20) {  <-- here you're checking for b being valid
            printf("give score of %d student",i);
            scanf("%d",&b);
            }
    

    So the first time in b will be between 1 and 20, if you don’t reset it to something invalid you’ll never get here again. After you record the value of b:

        sum=sum+b;
        b = 0;   // we're done with b for now, set it to something invalid for the while()
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I need to make a program that adds long integers without using the biginteger
I need to make the program which have one form that contains PNG image
I need to make a java program with a security and a login system
I need make some action (dump statistical data) before the Dart program ends. The
Need to make certain Ruby strings in my program to be immutable. What is
I need to be able to make a program that looks through a mailbox
So basically I'm making a program in C# and I need to make a
Ok I need to make this program to display cal 3 month(one month before
I need to make a file truly read only - to keep it as
I need to make a program that runs a process (my another programm) and

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.