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

  • Home
  • SEARCH
  • 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 8112129
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 6, 20262026-06-06T02:22:26+00:00 2026-06-06T02:22:26+00:00

I have made a code where I have to input 1 . no of

  • 0

I have made a code where I have to
input

1 . no of questions
2.  difficulty for every question
3 . no. of queries( query is to find median of difficulty questions between questions no. given in next line) 
4 . question no.s to find median

loop goes on till no input is given .

#include<stdio.h>

int main()
{
    int ques,count=0;
    while(scanf("%d",&ques))
    {
        int i,diff,se,fi,j,query,arr[100];
        for(i=0;i<ques;i++)
        {
            scanf("%d",&diff);
            arr[i] = diff;
        }
        count++;
        printf("Case %d:\n",count);
        scanf("%d",&query);
        for(i=0;i<query;i++)
        {

            int sum = 0;
            scanf("%d %d",&fi,&se);
            for(j=fi-1;j<se;j++)
            {
                sum = sum+ arr[j];
            }
            sum = sum/((se-fi)+1);
            printf("%d\n",sum);
        }
    }
    return 0;
}       

Here i give two inputs

5
5 3 2 4 1
3
1 3
2 4
3 5
5
10 6 4 8 2
4
1 3
2 4
3 5
2 3
6
2 56 2 3 5 4
1
2 5

but my output should be upto case 3 only instead:

Case 1:
3
3
2
Case 2:
6
6
4
5
Case 3:
16
Case 4:
4
Case 5:
4
Case 6:
4
Case 7:
4
Case 8:
4
Case 9:
4
Case 10:
4
Case 11:
4
Case 12:
4
Case 13:
4
Case 14:
4
Case 15:
4

and it goes on and on : Tell me why is this happening:

  • 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-06T02:22:29+00:00Added an answer on June 6, 2026 at 2:22 am

    Whwnever you are ending , no more values in there in your input . it returns -1 ; but your code seems to take ‘0’ as quit which is making -1 to be true and your code is running .

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

my question is that I have made multimap.Here is the partial code. if(binary_search(final.begin() ,
I have made this code to open a database(created in SQLite browser) stored in
I have a problem, and I made this test code to show you my
Greetings, SO. I have some code which I've made attempts at compiling using gcc,
I have written some physics simulation code in C++ and parsing the input text
Quick question about CI. I have a view with a form, several text input
I have a very easy question. Unfortunately, I can't find the answer. I just
I have made a question database with id . Now i am using ajax
I have made an application (for my self) for feeds reading, using SyndicationFeed ,
I have made a multiplayer game using the GameKit Framework where 2 iPhones/iPods can

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.