2000:
1.b) Name the header file, to which following built in function belong: (i) isupper() (ii) setw() (iii) exp() (iv) strcmp()
2
Ans)
(i) isupper( ) - ctype.h
(ii) setw( ) - iomanip.h
(iii) exp( ) - math.h
(iv) strcmp( ) - string.h
1.c) Will the following program execute successfully?If not, state the eason(s)
#include<stdio.h>
void main( )
{ int s1,s2,num;
s1=s2=0;
for(x=0;x<11;x++)
{ cin<<num;
if(num>0)s1+=num;else s2=/num;
}
cout<<s1<<s2;
}
2
Ans: The program will not execute
successfully.
Because some syntax errors are there in the program. They are
(i) cin and cout, stream objects used but
iostream.h header file is not included in the
program.
(ii) x is not declared, it should be declared as
int.
(iii) With cin, we should use >> instead of <<.
(iv)The shorthand operator /=, is given
wrongly as =/.
So the corrected program is as follows:
#include<iostream.h>
void main( )
{ int s1,s2,num;
s1=s2=0;
for(int x=0;x<11;x++)
{ cin>>num;
if(num>0)s1+=num;else s2/=num;
}
cout<<s1<<s2;
}
d) Give the output of the following program segment(Assuming all required header files are included in the program):
char *NAME=”a ProFiLe”;
for(int x=0;x<strlen(NAME);x++)
if(islower(NAME[x]))
NAME[x]=toupper(NAME[x]);else if(isupper(NAME[x]))
if(x%2!=0)
NAME[x]=tolower(NAME[x-1]);
else
NAME[x]--;
cout<<NAME<<endl;
2
Ans: Output: AOROoIiE
CBSE Computer Science Solved Revision Tour By Mr. Ravi Kiran ( [email protected] )