#include
void main()
{
int num;
do{
cout<<""\n\tENter the number=;
cin>>num;
if(num!=42){
cout<<num<<endl;
}
}while(num!=42);
}
#include
void main()
{
int num;
do{
cout<<""\n\tENter the number=;
cin>>num;
if(num!=42){
cout<<num<<endl;
}
}while(num!=42);
}
Do not write anything other than output.
synatax error- cout<<""\n\tENter the number=;
Do not write “Enter the number” and also instead of void main use int main and return 0 in the last…
Syntax error; it should be, #include<iostream.h> or else it wont accept any input.
and also there should be cout<<"\n Enter the number?";
There are a lot of errors which are as follows :
- not used using namespace std in C++ program
- you dont have to use cout<<“Enter a naumber” and all on codechef
- At the end of program you should return 0 that indicate successful
run.
Optimizing the solution
Use for loop instead of while and do-while as they are faster.
Use printf and scanf even in C++ to get input and output, as they are faster than cin and cout.
Happy coding…!!