You are not logged in. Please login at www.codechef.com to post your questions!

×

Why this code gives runtime error

#include < stdio.h >
void main()
{
    int i = 0;
    int T;
    int N;
    printf("Enter the 'T' value : ");
    scanf("%d",&T);
    for(i = 0;i<T;i++)
    {
        printf("Enter the 'N' value");
        scanf("%d",&N);
        int number = 1;
        int temp;
        int j = 0;
        for(j=0;j<N;j++)
        {
            printf("Enter values :");
            scanf("%d",&temp);
            number = temp *number;
        }
        j = 1;
        int count = 0;
        for(j = 2;j < number;j++)
        {
            if(number%j == 0)
            {
                count++;
            }
        }
        if(number > 1)
        {
            printf("count = %d\n",(count+2));
        }
        else if(number == 1)
        {
            printf("count = 1\n");
        }
        else
        {
            printf("count = 0\n");
        }
    }
}

asked 08 Jul '13, 19:11

hemanth465's gravatar image

2★hemanth465
113
accept rate: 0%

edited 08 Jul '13, 22:38

tijoforyou's gravatar image

2★tijoforyou
4.2k52364

1

not able to indent. Please use code tag and upload again with proper indentation :)

(08 Jul '13, 19:23) sunny_patel2★

Please give the ideone link!!That would be easier to read!!Or while posting code indent it!!

link

answered 08 Jul '13, 20:25

jaythegenius's gravatar image

3★jaythegenius
4253717
accept rate: 4%

U are using void main it causes issues. Use int main with return 0 in the end. Also dont prompt user for input, U will get a wrong ans error if u do so.

link

answered 08 Jul '13, 22:33

abbas's gravatar image

4★abbas
4118
accept rate: 28%

-1

You are getting a runtime error because, the very first line of your code is wrong. When you are using #include, you are expected to give the name (or path) of a header file within the angle brackets -- no space, no extra characters. Change it to #include <stdio.h> or #include<stdio.h> (see, no spaces between < and >).

Now, you might again get a runtime error (probably and more specifically, an NZEC - Non-Zero-Exit-Code - error) because, you main does not return 0. A successfully completed C/C++ program is expected to return 0 (EXIT_SUCCESS) from the main (or from wherever the program terminates).

Try changing your void main() to int main().

Also, a few words of caution: you might still not get an accepted solution, if the output your code produces is not STRICTLY as per what the problem asks you to print. So, if the program does not ask you to output "Enter the 'N' value", then you shall not output the same. The program will be judged wrong answer for that.

link

answered 08 Jul '13, 22:51

tijoforyou's gravatar image

2★tijoforyou
4.2k52364
accept rate: 15%

toggle preview
Preview

Follow this question

By Email:

Once you sign in you will be able to subscribe for any updates here

By RSS:

Answers

Answers and Comments

Markdown Basics

  • *italic* or _italic_
  • **bold** or __bold__
  • link:[text](http://url.com/ "title")
  • image?![alt text](/path/img.jpg "title")
  • numbered list: 1. Foo 2. Bar
  • to add a line break simply add two spaces to where you would like the new line to be.
  • basic HTML tags are also supported
  • mathemetical formulas in Latex between $ symbol

Question tags:

×21

question asked: 08 Jul '13, 19:11

question was seen: 751 times

last updated: 08 Jul '13, 22:51