Pps Practical7 Solution Without Watermark-2
Pps Practical7 Solution Without Watermark-2
if(k[i]=='a'||k[i]=='e'||k[i]=='i'||k[i]=='o'||k[i]=='u'||k[i]=='A'||k[i]=='E'||k[i]=='I'||k[i]=='O'||k[i]=='U'){
c++;
}
}
printf("Number of vowels in this string is %d",c);
return 0;
}
7.8 Write a program to check whether given String is Palindrome or not.
#include<stdio.h>
#include<string.h>
int main(){
char str1[99];
printf("enter the string \n");
gets(str1);
int l=strlen(str1)-1;
int count=0;
for(int i=0;i<=(strlen(str1)/2);i++){
if(str1[i]!=str1[l]){
count++;
}
l--;
}
if(count==0){
printf("the string is palidrome");
}else if(count!=0){
printf("the number is not palidrome");
}
return 0;
}
7.9 Make a program to sort the characters for the given string.
#include<stdio.h>
#include<string.h>
int main(){
char k[99];
printf("enter the string \n");
gets(k);
int l;
l=strlen(k);
for(int i=0;i<l-1;i++){
for(int j=0;j<l-i-1;j++){
if(k[j]>k[j+1]){
int temp;
temp=k[j];
k[j]=k[j+1];
k[j+1]=temp;
}
}
}
puts(k);
return 0;
}
7.10 Take a sentence in a string using scanf without for loop. Now find out total no of
characters and words in that sentence excluding spaces.
#include <stdio.h>
int main() {
char k[100];
int c = 0, w = 1,i;
printf("Enter a String: \n");
scanf("%[^\n]%*c", k);
for (i=0 ; k[i] != '\0' ; i++){
if (k[i] == ' '){
w++;
}else{
c++;
}
}
printf("Total characters: %d\n", c);
printf("Total words: %d\n", w);
return 0; }