1.

Find the syntax error(s), if any, in the following program:(i) #include<iostream.h>main() {int x[5],*y,z[5]for(i=0;i<=5;i++){x[i]=i;z[i]=i+3;y=z;x=y;}}(ii) #include<iostream.h>void main(){int x,y;cin>>x;for(x=0;x<5;++x)cout y else cout<<x<<y;}(iii) #include<iostream.h>void main(){int R;W=90;while W>60{ R=W-50;switch(W){20:cout<<"Lower Range"<<endl;30:cout<<"Middel Range"<<endl;20:cout<<"Higher Range"<<endl;}}}(iv) Rewrite the following program after removing all the syntax error(s), if any#include <iostream.h>void main() {int X[]={60, 50, 30, 40},Y;Count=4;cin>>Y;for(I=Count-1;I>=0,I--)switch(I){ case 0:case 2:cout<<Y*X[I]<<endl;breakcase1:case 3:cout>>Y+X[I];}}(v) Rewrite the following program after removing all the syntax error(s), if any.#include<iostream.h>void main(){int P[]={90, 10, 24, 15},Q;Number=4;Q=9;for(int I=Number-1;I>=0,I--)switch(I){ case 0:case 2:cout>>P[I]*Q<<endl;break;case1:case 3:cout<<P[I]+Q;}}

Answer»

(i) Will encounter a following syntax error(s): 

  • The variable ‘i’ is not declared. 
  • There should be semicolon after the declaration statement if int x[5].

(ii) There is a syntax error in cout statement.

(iii) Will encounter a following syntax error(s): 

  • There should be a ‘,’ between R and W instead of ‘;’ in declaration statement.  
  • There should be a parenthesis in ‘while’ statement.
  • There is missing a use of ‘case’ keyword in switch statement.

(iv) #include<iostream.h>

void main(){

int X[]={60, 50, 30, 40},Y,Count=4;

cin>>Y;

for(int I=Count-1;I>=0;I--)

switch(I)

{ case 0:

case 1:

case 2:cout<<Y*X[I]<<endl;break;

case 3:cout<<Y+X[I];break;

}

}

(v) #include<iostream.h>

void main() {

int P[]={90, 10, 24, 15},Q,Number=4;

Q=9;

for(int I=Number-1;I>=0;I--)

switch(I)

{ case 0:

case 1:

case 2:cout<<P[I]*Q<<endl;

break;

case 3:cout<<P[I]+Q;

break;

}

}



Discussion

No Comment Found

Related InterviewSolutions