Quantcast
Channel: CodeChef Discuss - latest questions
Viewing all articles
Browse latest Browse all 39796

runtime error

$
0
0

how to remove runtime error from the following code:

#include<stdio.h>
#include<stdlib.h>
void main()
{
    int a[2000],i;
    float n,m,p;
    a[0]=0;
    a[1]=1;
    for(i=2;i<2000;i++)
        a[i]=a[i-1]+a[i-2];
    printf("enter the no. to be rounded");
    scanf("%f",&n);
    for(i=0;i<2000;i++)
    {
        if(n==a[i])
        {
            printf("rounded number is %f",n);
            exit(0);
        }
    }
    i=0;
    while(a[i]-n<0)
        i++;
    m=a[i]-n;
    p=n-a[i-1];
    if(m<p)
        printf("rounded number is %d",a[i-1]);
    else
        printf("rounded number is %d",a[i]);
}

Viewing all articles
Browse latest Browse all 39796

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>