Question:4
C program to take input for a string, pass the string to a function and display the string in such a way that all lower case alphabets are displayed as upper case and rest are displayed as it is?
Sol:
#include<stdio.h>
void show(char *p)
{
while(*p!='\0')
{
if(*p>='a' && *p<='z')
printf("%c",*p-32);
else
printf("%c",*p);
p++;
}
}
int main()
{
char n[20];
printf("Enter any string ");
gets(n);
show(n);
/* show(&n[0]); */
return(0);
}
/* Output */ Enter any string hello world HELLO WORLD
Question:5
C program to take input for a string , pass the string to a function and display the string in such a way that all upper case alphabets are displayed as lower case and rest is displayed as it is?
Sol:
#include<stdio.h>
void show(char *p)
{
while(*p!='\0')
{
if(*p>='A' && *p<='Z')
printf("%c",*p+32);
else
printf("%c",*p);
p++;
}
}
int main()
{
char n[20];
printf("Enter any string ");
gets(n);
show(n);
/* show(&n[0]); */
return(0);
}
/* Output */ Enter any string HELLO hello
Question:6
C program to take input for a string, pass the string to a function and display the string in such a way that all upper case alphabets are displayed as lower case and all lower case are displayed as upper case and rest are displayed as it is(toggle case)?
Sol:
#include<stdio.h>
void show(char *p)
{
while(*p!='\0')
{
if(*p>='A' && *p<='Z')
printf("%c",*p+32);
else
if(*p>='a' && *p<='z')
printf("%c",*p-32);
else
printf("%c",*p);
p++;
}
}
int main()
{
char n[20];
printf("Enter any string ");
gets(n);
show(n);
/* show(&n[0]); */
return(0);
}
/* Output */ Enter any string CoMpUtER cOmPuTer




