Wednesday, 10 July 2019

write a programe to find the number of vowels and consonants in a text string

#include<stdio.h>
#include<string.h>
int main()
{
    char str[30];
    int vowl=0,cons=0,i=0;
    clrscr();
    printf("Enter a string: ");
    gets(str);
    while(str[i]!='\0')
    {
        if(str[i]=='a'|| str[i]=='A'|| str[i]=='e'|| str[i]=='E'|| str[i]=='i'|| str[i]=='I'|| str[i]=='o'|| str[i]=='O'|| str[i]=='u'|| str[i]=='U')
            vowl++;
        else
            cons++;
        i++;
    }
    printf("\nNumber of Vowels=%d",vowl);
    printf("\nNumber of Consonants=%d",cons);
}

write a programe to copy one string into another and count the number of characters copied

#include<stdio.h>
main()
{
    char string1[80],string2[80];
    int i;
    printf("Enter a string:");
    scanf("%s",string2);
    for(i=0;string2[i];i++)
        string1[i]=string2[i];
    string1[i]='\0';
    printf("%s\n",string1);
    printf("The number of character=%d\n",i);
}

write a programe to read a line of text containing a series of words from the terminal

#include<stdio.h>
main()
{
char line[81],character;
int c;
c=0;
printf("Enter text:");
do
{
character=getchar();
line[c]=character;
c++;
}
while(character!= '\n');
c=c-1;
line[c]='\n';
printf("\n%s\n",line);
}

Tuesday, 9 July 2019

write a program to read a series of words from a terminal using scanf function

#include<stdio.h>
main()
{
char word1[40],word2[40],word3[40],word4[40];
printf("Enter text:\n");
scanf("%s %s %s %s",word1,word2,word3,word4);
printf("\n");
printf("word1=%s\n word2=%s\n word3=%s\n word4=%s",word1,word2,word3,word4);
}