@naman00b its because of condition for(i=1;i<=t;i++). Problem states that t is number of integers in number
Now, in an array, numbers are indexed from 0 to n-1. Meaning, the first number has index 0, second has index 2…and hence n has index n-1. In final iteration, it makes a reference to index n, for which array size should had been n+1. But since array is of size n, its’ maximum index is n-1. So when it calls for index n, it gives fault
(PS: Please upvote if you find the explanation correct and good )
hello everyone, I have recently shifted from C to C++, can someone please tell me why I’m getting sigsegv despite, it runs fine on Dev C++ ide.
Please tell me which should I choose C++(4.9.2),(4.3.2) or 14.
Hello… Am new to CodeChef… And tried one program in beginners… but is showing me Runtime Error(SIGSEGV)… i know that its related to program taking too much memory because of FOR loop… but i don’t know any other way to store that amount of data without FOR loop… so… plz… if Anyone can help with that… MY CODE AT: CodeChef: Practical coding for everyone
Y is this a runtime error??
#include<stdio.h>
#include<conio.h>
int main()
{
int t,n,p,i,j,e,h,s[10];
clrscr();
printf("\nEnter the no. of test cases:");
scanf("%d",&t);
for(i=0;i<t;i++)
{
e=0;
h=0;
printf("\nEnter the no.of problems and no.of people solving 'em:");
scanf("%d%d",&n,&p);
printf(“Enter the no.of people solving the resp problems:”);
for(j=0;j<n;j++)
{
scanf("%d",&s[j]);
if(s[j]>=p/2)
e++;
else if(s[j]<=p/10)
h++;
}
if(e==1&&h==2)
printf("\nYes!");
else
printf("\nNo!");
}
getch();
return 0;
}