#include<stdio.h>
int main()
{
int x;
float y,total;
scanf("%d %f",&x,&y);
if(x%5==0 && x<=y)
{
total=(y-x)-0.50;
printf("%.2f\n",total);
}
else
{
printf("%.2f\n",y);
}
}
why do i get run time error(SIGSEV) for thi code
https://www.codechef.com/viewsolution/8927820
#include <stdio.h>
void main()
{
int x;
float y;
scanf("%d",&x);
scanf("%f",&y);
if(x%5==0)
{
if(x<y)
{
y=y-x;
y=y-0.5;
printf("%.2f",y);
}
else
{ printf("%.2f",y);
}
}
else
{
printf("%.2f",y);
}
Why an i getting run-time error in this program even if its running in my Net Beans ?CodeChef: Practical coding for everyone
//Sum of palindromic numbers
#include<stdio.h>
main()
{
int n,r,sum=0,count=0,temp;
printf(“Enter a number:”);
scanf("%d",&n);
temp = n;
while(n>0)
{
r =n%10;
sum = (sum * 10) + r;
n = n/10;
count = count + r;
}
if(sum==temp)
{
printf("%d is a palindrome!\n",temp);
printf(“The sum is:%d\n”,count);
}
else
{
printf("%d is not a palindrome!\n",temp);
}
}
Why i am getting run time error? I am running it on linux platform.
runtime errors occurs when there is any logic error in that program or in any exceptional cases
My code is wprking fine on all ides including ideone and even on codechef compiler but still it is not getting successful submission . Please can somebody help me on this? here is the link to my java code:
#include<stdio.h>
int main()
{
int t;
scanf("%d",&t);
while(t–)
{
int n,m,p,i,j,b;
scanf("%d%d",&n,&m);
int a[n];
for(i=0;i<n;i++)
a[i]=0;
while(m–)
{ b=1;
scanf("%d",&p);
if(a[p]<=0)
a[p]=0;
for(i=p-1,j=p+1;i>=0||j<=n-1;i–,j++)
{
if(a[i]<b)
a[i]=b;
if(a[j]<b)
a[j]=b;
b++;
}
}
for(i=0;i<n;i++)
printf("%d ",a[i]);
printf("\n");
}
return 0;
}
#include<stdio.h>
int main()
{
int t;
scanf("%d",&t);
while(t–)
{
int n,m,p,i,j,b;
scanf("%d%d",&n,&m);
int a[n];
for(i=0;i<n;i++)
a[i]=0;
while(m–)
{ b=1;
scanf("%d",&p);
if(a[p]<=0)
a[p]=0;
for(i=p-1,j=p+1;i>=0||j<=n-1;i–,j++)
{
if(a[i]<b)
a[i]=b;
if(a[j]<b)
a[j]=b;
b++;
}
}
for(i=0;i<n;i++)
printf("%d ",a[i]);
printf("\n");
}
return 0;
}
include
int main()
{
int t;
scanf("%d",&t);
while(t–)
{
int n,m,p,i,j,b;
scanf("%d%d",&n,&m);
int a[n];
for(i=0;i<n;i++)
a[i]=0;
while(m–)
{ b=1;
scanf("%d",&p);
if(a[p]<=0)
a[p]=0;
for(i=p-1,j=p+1;i>=0||j<=n-1;i–,j++)
{
if(a[i]<b)
a[i]=b;
if(a[j]<b)
a[j]=b;
b++;
}
}
for(i=0;i<n;i++)
printf("%d ",a[i]);
printf("\n");
}
return 0;
}
#include <stdio.h>
#include <stdlib.h>
int main()
{
int n,i,j,k,T,a[n],sum=0;
scanf("%d",&T);
if(T<1 || T>30)
{
exit(0);
}
for(i=1;i<=T;i++)
{
int sum=0;
int sum1=sum;
scanf("%d",&n);
int q=n;
for(j=0;j<n;j++)
{
scanf("%d",&a[j]);
if(a[j]<1 || a[j]>1000000)
{
exit(0);
}
}
for(k=0;k<n;k++)
{
sum=sum+a[k];
}
sum1=sum;
if(sum1%2==0)
{
printf("%d\n",n);
}
else
{
for(k=0;k<n;k++)
{
q–;
sum1=sum1-a[k];
if(sum1%2==0)
{
printf("%d\n",q);
break;
}
}
}
}
return 0;
}
#include<stdio.h>
void disp( );
void mergesort(int,int,int);
void msortdiv(int,int);
int a[50],n;
void main( )
{
int i;
printf("\nEnter the n value:");
scanf("%d",&n);
printf("\nEnter elements for an array:");
for(i=0;i<n;i++)
scanf("%d",&a[i]);
printf("\nBefore Sorting the elements are:");
disp( );
msortdiv(0,n-1);
printf("\nAfter Sorting the elements are:");
disp( );
return 0;
}
void disp( )
{
int i;
for(i=0;i<n;i++)
printf("%d ",a[i]);
}
void mergesort(int low,int mid,int high)
{
int t[50],i,j,k;
i=low;
j=mid+1;
k=low;
while((i<=mid) && (j<=high))
{
if(a[i]>=a[j])
t[k++]=a[j++];
else
t[k++]=a[i++];
}
while(i<=mid)
t[k++]=a[i++];
while(j<=high)
t[k++]=a[j++];
for(i=low;i<=high;i++)
a[i]=t[i];
}
void msortdiv(int low,int high)
{
int mid;
if(low!=high)
{
mid=((low+high)/2);
msortdiv(low,mid);
msortdiv(mid+1,high);
mergesort(low,mid,high);
}
}
import java.util.Scanner;
class Fibo
{
int x;
int y;
Fibo(int a, int b)
{
x=a;
y=b;
}
int fibo2(int z)
{
if(z==1)
return x;
if(z==2)
return y;
int result = (fibo2(z-1)-fibo2(z-2))%1000000007;
if(result >=0)
return result ;
else
return (result+1000000007);
}
}
class Fibo2
{
public static void main(String[] args)
{
int i;
Scanner in = new Scanner(System.in);
short m = in.nextShort();
int n[] = new int[m];
int o[] = new int[m];
int p[] = new int[m];
for (i = 0; i<m ; i++)
{
n[i] = in.nextInt();
o[i] = in.nextInt();
p[i] = in.nextInt();
}
for( i=0; i<m; i++)
{
Fibo ob = new Fibo(n[i],o[i]);
System.out.println(ob.fibo2(p[i]));
}
}
}
//Whats the error?
question: CodeChef: Practical coding for everyone
code : CodeChef: Practical coding for everyone
can someone pls tell why am i getting runtime error here,been stuck here for a while,thankyou
include
define max 100
int main()
{
int n,i;
scanf("%d",&n);
int a[max];
for(i=0;i<n;i++)
{
scanf("%d",&a[i]);
}
for(i=0;i<n;i++)
{
int num,r,s=0;
num=a[i];
while(num!=0)
{
r=num%10;
num=num/10;
s=s+r;
}
a[i]=s;
}
for(i=0;i<n;i++)
{
printf("\n%d\n",a[i]);
}
return 0;
}
#include<stdio.h>
void main()
{
int a;
float totalmoney;
scanf("%d %f",&a,&totalmoney);
if(a<=2000 && totalmoney<=2000)
{
if(a%5==0 && (a + .50)<=totalmoney)
{
totalmoney=totalmoney-(a+.50);
printf("%.2f",totalmoney);
}
else
printf("%.2f",totalmoney);
}
}
why i am getting run time error in this
Runtime error (NZEC) may occur if you upload a file from package.
Remember when you upload a file from your computer, class needs to be named Main and be in default package.
do anyone know why do we get run time error SIGCONT