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 8327871
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 9, 20262026-06-09T01:15:38+00:00 2026-06-09T01:15:38+00:00

Here is my code:when my input for input for array is 10001 .then also

  • 0

Here is my code:when my input for input for array is 10001 .then also it is entering in else block for input[1]=0,where as i have put condition in outer if that if(input[j]==1).can any body tell me why it is happening?

#include<stdio.h>
int main()
{
        unsigned int tcase=0,build=0,i=0,j=0,k=0,count=0;
        unsigned int input[1000];
        scanf("%d",&tcase);
        while(tcase--)
        {
                scanf("%d",&build);
                for(i=0;i<build;i++)
                        scanf("%d",&input[i]);

                for(j=0;j<build;j++)
                {
                        if(input[j]==1)
                        {
                                if(j==0)
                                {       input[j+1]=1;

                                        printf("fddf");
                                }
                                else if(j==(build-1))
                                {
                                        input[j-1]=1;

                                        printf("Gfgf");
                                }
                                else
                                {
                                        input[j+1]=1;
                                        input[j-1]=1;
                                        printf("awGfgf");
                                }
                        }
                }
                for(k=0;k<build;k++)

               {
                        if(input[k]==0)
                                ++count;
                }
                printf("%d\n",count);
        }
        return 0;
}
  • 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-09T01:15:39+00:00Added an answer on June 9, 2026 at 1:15 am

    I will answer your question based your comment to Eric J’s answer:

    J.no u got it wrong by i/p 10001 i mean for input[0]=1,input[1]=0 and so on... so it only occupies 5 array spaces
    

    The gist of the answer is that the first input you are entering as 1 which causes the condition to succeed first time. Later on in each iteration, you keep changing the values of your input array which causes subsequent iterations to enter into the condition.

    As you mentioned your input is

    input[0] = 1
    input[1] = 0
    input[2] = 0
    input[3] = 0
    input[4] = 1
    

    Now, see the behavior in the below code:

    for(j=0;j< build;j++)
    {
        if(input[j]==1) /* First for input[0], this condition succeeds */
        {
             if(j==0)
             {
                input[j+1]=1; /* This line changes input[1] to 1, so next time in the loop the condition if(input[j] == 1 will succeed */
                printf("fddf");
             }
             else if(j==(build-1)) /* This condition will cause input[4] to be set to 1 and will cause if(input[j] == 1) to succeed for the last iteration of the loop */
             {
               input[j-1]=1;
    
               printf("Gfgf");
             }
            else /** This condition will cause input[2] & input[3] to be set to 1 and will again cause if(input[j] == 1) to succeed in successive loop iterations **/
            {
               input[j+1]=1;
               input[j-1]=1;
               printf("awGfgf");
            }
        }
      }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

So I have some code here that takes user input from a standard web
I have made an array that take an input say 12345 and splits it
I have this code here: <?php while($rowequipment = mysql_fetch_assoc($sqlequipment)) { echo '<input type=checkbox name=equipment[]
Here is my jquery code: $('input').click(function(){ $('h1').empty().queue(function(){ console.log('queue'); }); }); }); Only the first
Here is the input form code <tr valign=top> <td align=right class=innertablestyle><font class=normal><strong>Homepage</strong></font></td> <td>&nbsp;</td> <td>
Here is the code I am having: <div id=removequestions></div> var html += '<input type=radio
Here is the code: string str; cin>>str; cout<<first input:<<str<<endl; getline(cin, str); cout<<line input:<<str<<endl; The
Here's the relevant code: <div data-bind=foreach: chats, visible: chats().length > 0> <input data-bind='value: $parent.newCommentText'
This is my html Code: <input type=checkbox name=test id=test /> Here i want to
Here's what I'm trying to do, simplified: <input rel=TimeStart> // bunch of HTML code

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.