Awesome q2a theme
0 votes
49 views

THE PROBLEM

Code→ 

#include<iostream>
using namespace std;

int main()
{
     long int s,t,a,b,m,n; //m=number of apples, n=number of orranges
     long int ap[m], orr[n];
    cin>>s;
    cin>>t;
    cin>>a;
    cin>>b;
    cin>>m;
    cin>>n;

 long int d1= s-a;
 long int d2= t-a;

 long int q1= s-b;
 long int q2= t-b;

long int c1=0,c2=0;

    for(int i=0;i<m;i++)
    {
        cin>>ap[i];
        if(ap[i]>=d1 && ap[i]<=d2)
        {
            c1++;
        }
    }

    for(int i=0;i<n;i++)
    {
        cin>>orr[i];
        if(orr[i]<=q1 && orr[i]>=q2)
        {
            c2++;
        }
    }

cout<<c1<<"\n"<<c2;
return 0;


}

Why does it give Segmentation fault in Hacker Rank and In dev c++ the code stops by saying Windows is looking for a solution.

in Programming by (1.7k points) | 49 views
+1

I think this line

long int ap[m], orr[n];

should be after taking input of m and n

0
@Satbir why that line??
+1
since m and n are uninitialized uptil that line what will be the size of array created ?
0
@satbir..

Ya, i figured it out later...Thanks Man

Please log in or register to answer this question.

Quick search syntax
tags tag:apple
author user:martin
title title:apple
content content:apple
exclude -tag:apple
force match +apple
views views:100
score score:10
answers answers:2
is accepted isaccepted:true
is closed isclosed:true
Welcome to GATE CSE Doubts, where you can ask questions and receive answers from other members of the community.
Top Users Jun 2020
  1. nehaPal13

    7 Points

  2. Radheram

    6 Points

  3. vps123

    4 Points

  4. ummokkate

    1 Points

  5. Musa

    1 Points

  6. AliH

    1 Points

  7. DukeThunders

    1 Points

  8. Doraemon

    1 Points

  9. kpc

    1 Points

  10. Kushagra गुप्ता

    1 Points

7,393 questions
1,744 answers
10,711 comments
90,368 users