0% found this document useful (0 votes)
0 views

PSPC LAB-6

The document contains four C programs that demonstrate various string manipulations. The first program converts lowercase letters to uppercase and vice versa, the second counts vowels, consonants, and digits in a string, the third checks if a string is a palindrome, and the fourth sorts the characters in a string. Each program includes source code and prompts for user input.

Uploaded by

jaganbure
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
0 views

PSPC LAB-6

The document contains four C programs that demonstrate various string manipulations. The first program converts lowercase letters to uppercase and vice versa, the second counts vowels, consonants, and digits in a string, the third checks if a string is a palindrome, and the fourth sorts the characters in a string. Each program includes source code and prompts for user input.

Uploaded by

jaganbure
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 3

LAB-6

Strings – Dealing with non-numerical data


1. Write a program to convert the Lower Case letters to Upper Case Letters and Upper Case
Letters to Lower Case Letters in a given input string.
Source Code:-

#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;
}

4. Write a program to sort the given string of characters.


Source Code:-

#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;
}

You might also like