Why do I get a Runtime exception?

,

#include<stdio.h>

int main()
{
int t;
printf("\n enter the number of test case : “);
scanf(”%d",&t);
while(t>0)
{
int nbNote=0,amount=0;
int nb100=0,nb50=0,nb10=0,nb5=0,nb2=0,nb1=0;
printf("\n enter the amount : “);
scanf(”%d",&amount);
if(amount%100>=0)
{
nb100=amount/100;
nbNote+=nb100;
amount-=(nb100100);
}
if(amount%50>=0)
{
nb50=amount/50;
nbNote+=nb50;
amount-=(nb50
50);
}
if(amount%10>=0)
{
nb10=amount/10;
nbNote+=nb10;
amount-=(nb1010);
}
if(amount%5>=0)
{
nb5=amount/5;
nbNote+=nb5;
amount-=(nb5
5);
}
if(amount%2>=0)
{
nb2=amount/2;
nbNote+=nb2;
amount-=(nb22);
}
if(amount%1>=0)
{
nb1=amount/1;
nbNote+=nb1;
amount-=(nb1
1);
}
printf("\n number of notes = %d",nbNote);
t–;
}
return 0;
}

1 Like

#include<stdio.h>
#include<conio.h>
void main()
{
int i;
scanf("%2d",&i);

while(i=!42)
{
printf("%2d",i);
scanf("%2d",&i);
}
return 0;

}

1 Like

#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);
}
}

1 Like

why do i get run time error(SIGSEV) for thi code
https://www.codechef.com/viewsolution/8927820

1 Like

#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);
			}

}link text

1 Like

Why an i getting run-time error in this program even if its running in my Net Beans ?CodeChef: Practical coding for everyone

1 Like

//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.

1 Like

runtime errors occurs when there is any logic error in that program or in any exceptional cases

1 Like

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:

1 Like

#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;

}

1 Like

#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;

}

1 Like

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;

}

1 Like

#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;

}

1 Like

#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);
}
}

why do i get a run time error(SIGXFSZ)CodeChef: Practical coding for everyone

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.