Chapter-10 Standard Library Functions Type A: Very Short Answer Questions
Chapter-10 Standard Library Functions Type A: Very Short Answer Questions
http://cbsecsnip.in
str[i]=toupper(str[i]);
}
i++;
}
puts(str);
getch();
}
2. Write a C++ program that reads three strings and prints the longest and smallest string.
Ans. #include<iostream.h>
#include<conio.h>
#include<string.h>
void main()
{
clrscr();
char str1[50],str2[50],str3[50];
int i=0,a,b,c;
cout<<"Enter string1: ";
gets(str1);
cout<<"Enter string2: ";
gets(str2);
cout<<"Enter string3: ";
gets(str3);
a=strlen(str1);
b=strlen(str2);
c=strlen(str3);
if((a>b) && (a>c))
cout<<"Largest string: "<<str1;
else if((b>a) && (b>c))
cout<<"Largest string: "<<str2;
else
cout<<"Largest string: "<<str3;
if((a<b) && (a<c))
cout<<endl<<"Smallest string: "<<str1;
else if((b<a) && (b<c))
cout<<endl<<"Smallest string: "<<str2;
else
cout<<endl<<"Smallest string: "<<str3;
getch();
}
3. Write a program that reads a string and a character. Each occurrence of the given character (regardless of its case)
is converted to opposite case. For example, if the string entered is:
AabrAcadabrA and the character as A or a then the output string should be aAbracAdAbra. See each a or A is
converted to opposite case i.e., upper to lower or vice-versa.
Ans. #include<stdio.h>
#include<iostream.h>
#include<conio.h>
#include<ctype.h>
void main()
{
clrscr();
char str[50],ch;
int i=0,l;
int result=0,result1=0;
cout<<"Enter strings: ";
gets(str);
http://cbsecsnip.in
cout<<"Enter charcter: ";
cin>>ch;
while(str[i]!='\0')
{
if(toupper(ch)== str[i])
{
str[i]=tolower(str[i]);
}
else if(tolower(ch)== str[i])
{
str[i]=toupper(str[i]);
}
i++;
}
puts(str);
getch();
}
http://cbsecsnip.in