1 PROGRAM TO FIND THE VOWELS AND CONSONANTS IN THE STRING.
#include<stdio.h>
#include<string.h>
int main()
{
int c=0,v=0,n,j,flag;
char s[100];
printf("enter the character : ");
gets(s);
for(j=0; s[j]!='\0'; j++)
if(s[j]=='a'||s[j]=='A'||s[j]=='e'||s[j]=='E'||s[j]=='i'||s[j]=='I'||s[j]=='o'||s[j]=='O'||s[j]=='u'||s[j]=='U')
{
v++;
}
else
{
c++;
}
n=strlen(s);
printf("total size=%d",n);
printf("\nvowels=%d",v);
printf("\nconsonants=%d",c);
return 0 ;
}
OUTPUT :
enter the character : I love doing coding
total size=19vowels=7
consonants=12enter string 1 :coderash5.blogspot.com
Program to compare two strings without using strcmp(library function)...
#include<stdio.h>
#include<string.h>
int main()
{
int i=0,l,k,j;
char s1[100],s2[100];
printf("enter string 1 :");
fgets(s1,sizeof s1,stdin );
printf("enter string 2 :");
fgets(s2,sizeof s2,stdin );
l=strlen(s1);
k=strlen(s2);
printf("%d\n%d\n",l-1,k-1);
if(l!=k)
printf("not equal string!!");
else
{
while(s1[i]<=l&&s2[i]<=k);
{
if(s1[i]==s2[i])
j=1;
}
i++;
if(j==1)
printf("equal string");
else
printf("not equal string!");
}
return 0 ;
}
OUTPUT :
enter string 1 :coderash5.blogspot.com
enter string 2 :coderash5.blogspot.com
22
22
equal string
Program to count string elements without any library function:
#include <bits\stdc++.h>
using namespace std;
int main()
{
int count = 0; //initialising count with 0
char str[80];
cout << "enter the string: " << endl;
fgets(str, sizeof str, stdin);
while (str[count] != '\0')
{
count++; //counting elements of string
}
cout << "s_length of the string is : " << count - 1;
return 0;
}
Program to count total numbers of words in string:]
Word : coderash 5 blogspot .com
count : 4
LOGIC = If spaces or '\n(new line) or '\t' (tab) comes count it
#include <bits\stdc++.h>
using namespace std;
int main()
{
int word=1, i; // initialising word with 0
char str[100] ;
cout << "enter the string: " << endl;
fgets(str, sizeof str, stdin);
for(str[i]=0;str[i]<sizeof str;str[i++])
{
if (str[i] == ' ' || str[i] == '\n' || str[i] == '\t') //logic given above
{
word++;
}
}
cout << "total num are: " << word - 1;
return 0;
}
Comments
Post a Comment