Tuesday, July 28, 2009

I typed this C code into Dev and how do i get it to run?

#include %26lt;stdio.h%26gt;





main()


{


int integer1, integer2, sum;





printf("Enter first interger\n");


scanf("%d", %26amp;integer1);


printf("Enter secong interger\n");


scanf("%d",%26amp;integer2);





sum = integer1 + integer2;





printf("Sum is %d\n", sum);





return 0;





}





thats the code ^





did i do something wrong





i saved it and went to compile and run and nothing pops up

I typed this C code into Dev and how do i get it to run?
Your code is right but since it runs so quick that you won't see it produces something helpful.. Right before you notice it prints something, it has already ended its task. Meaning, after it runs the program, it closes immediately. So to prevent it from closing immediately, use getch() function before the statement "return 0;" And don't forget to include the library "conio.h". This is where the function getch() is.. (^^,) If you need to ask for more, then visit my blog and just leave a comment at http://ronaldborla.blogsome.com/ or http://ronaldborla.wordpress.com/


Also http://ronaldborla.blogsome.com/2008/02/... for my biggest announcement in my blog... (^^,) Thanks!
Reply:Hi,


By reading the code nothing seems incorrect but one deficiency which is the solution of ur problem.


write getch(); before return 0; statement.





The programme runs but it does not give u time to see the output.


After writing getch(); it will wait for a key press then exit. then u can see output of ur programm.
Reply:Well, how did you run your program? Did you use command prompt or Run windows, the later may run so fast that you did not have chance to see it.


No comments:

Post a Comment