PSPC LAB-6
PSPC LAB-6
#include<stdio.h>
#include<string.h>
int main(){
int i,j,k;
char s[100],s1[100];
printf("Enter the string : ");
scanf("%[^\n]",s);
for(i=0;i<strlen(s);i++){
j=(int)s[i];
if(j>=65 && j<=90){
k=j+32;
s1[i]=s1[i]+(char)k;
}
else if(j>=97 && j<=122){
k=j-32;
s1[i]=s1[i]+(char)k;
}
else {
k=j+32;
s1[i]=s1[i]+s[i];
}
}
printf("%s \n",s1);
return 0;
}
2. Write a program to the print out the number of vowels, consonants, and digits (0-9) present
in the given input string.
Source Code:-
#include<stdio.h>
#include<string.h>
#include<ctype.h>
int main(){
int i,j,v=0,c=0,d=0;
char s[100],k;
printf("Enter the string : ");
scanf("%[^\n]",s);
for(i=0;i<strlen(s);i++){
k=tolower(s[i]);
j=(int)k;
if(j==97 || j==101 || j==105 || j==111 || j==117){
v=v+1;
}
else if((j>=97 && j<=122) && (j!=97 || j!=101 || j!=105 || j!=111 || j!=117)){
c=c+1;
}
else if(j>=48 && j<=57){
d=d+1;
}
}
printf("Vowels : %d \n",v);
printf("Consonants : %d \n",c);
printf("Digits : %d \n",d);
return 0;
}
3. Write a program to check whether the given input string is palindrome string or not?
Source Code:-
#include<stdio.h>
#include<string.h>
#include<ctype.h>
int main(){
int i,j,l,k;
char ip[100];
printf("Enter the string : ");
scanf("%[^\n]",ip);
char op[100]="";
l=strlen(ip);
for(i=l-1,j=0;i>=0,j<l;i--,j++){
ip[i]=tolower(ip[i]);
op[j]=ip[i];
}
k=strcmp(ip,op);
if(k==0){
printf("%s is a Palindrome\n",ip);
}
else
{
printf("%s is not a palindrome \n",ip);
}
return 0;
}
#include<stdio.h>
#include<string.h>
#include<ctype.h>
int main(){
char s[100],temp;
int i,j;
printf("Enter string :");
scanf("%[^\n]",s);
int n=strlen(s);
printf("String before sorting : %s \n",s);
for(i=0;i<n-1;i++){
for(j=i+1;j<n;j++){
if(s[i]>s[j]){
temp=s[i];
s[i]=s[j];
s[j]=temp;
}
}
}
printf("String after sorting : %s\n",s);
return 0;
}