C programming error? :s

#include <stdio.h>

main ()
{
int n;

printf("enter a number ");
scanf("%d",&n);
printf("\nthe square of the number is ");
printf("%d\n",n*n);
}

program is right (according to me)..
it works fine for small numbers..
but when we give a big input viz. 100000, the program breaks down.. why?? [12]

9 Answers

30
Ashish Kothari ·

its better if you define a variable "sq" of type long int. Int variables have a range (you can google it).

49
Subhomoy Bakshi ·

I tried to joke with the compiler
I typed

#include <stdio.h>

main ()
{
int n;

scanf("%d",&n);
printf("%d\n",1.0/n);
}

and gave input 0!
it said filename.exe has stopped working! lol! :P

It hanged my lappy by the neck till shut down! [6]

C compilers have no sense of humour! :-/ LOL!

30
Ashish Kothari ·

Usually it shows divide error. God knows what happened to your compiler. :P It might not have had breakfast! [3]

30
Ashish Kothari ·

Btw you using old compilers of C?

49
Subhomoy Bakshi ·

May be!!

I have my own set of stories with C compiler!

The best one was when I used it for first time..

I did not know head/tail of C..

I typed "ADD TWO NUMBERS"
it said: "SYNTAX ERROR"

I said "JUST ADD THEM."
it said: "SYNTAX ERROR"

I said "Come on it is just addition!" [3] (I was enjoying it.. dont brand a MAD tag on me)
it said: "SYNTAX ERROR"

I SAID: "WTH ARE YOU TRYING TO IGNORE ME??" (rofl)
it said: "SYNTAX ERROR" [3]

I SAID: "I WONT USE U EVER AGAIN!!!!"
it said: "SYNTAX ERROR"

lol!
I officially brand this compiler humourless!

49
Subhomoy Bakshi ·

I am using new-est! [3]

Old is GOLD!
anyway, new is diamond! ;)

30
Ashish Kothari ·

It is very loving though. Carefully finds out your errors in the program, no matter how many times you make it. :) Though I agree its emotionless. [3] You work in Turbo C++ IDE or some other IDE?

49
Subhomoy Bakshi ·

idk .. whatever u r talking about is frence/latin/hebrew to me! :P

30
Ashish Kothari ·

Lol. Okay! I meant the software you write your codes in!

Your Answer

Close [X]