Ask a Teacher
What are the errors in the following?
#include |
In your program the
syntax for 'cout' is wrong. Use '<<' operator instead of
'>>'. You should provide semicolon at the time of variable
declaration, that is, int s=0; . And you should provide header conio.h , clrscr() and getch() in
the program. conio.h is a header file, declares several
useful library functions for performing "console input and output"
from a program. clrscr() and getch() are the member functions of
conio.h . So if you use both these functions in program, you should
include header conio.h . clrscr() - Clears the screen. So this function
helps you to clear the output screen in each execution. getch() - Reads a character directly from the
console without buffer, and without echo. So this function helps you to show
answer in the output screen until you press any key on the keyboard. The correct program as follows: #include<iostream.h> #include<conio.h> void main() { clrscr(); int s=0; for(int i=0;i<100;i+=2) s=s+i; cout<<s; getch(); } Output 2450 |