46) Sample C Program to count the number of words, characters, alphabets, vowels, consonants and digit in a line of text.
# include <stdio.h>
# include <conio.h>
main( )
{
int noa = 0, nob = 0, noc = 0, nov =0 , now = 0, noch = 0, l, I;
char ch, s[100];
clrscr( );
printf("Enter 2 lines of text:");
gets(s);
l = strlen(s);
for(i = 0; i < 1; i++)
{
switch(s[i])
{
case 'a':
case 'e':
case 'i':
case 'o':
case 'u':
case 'A':
case 'E':
case 'I':
case 'O':
case 'U':
nov++;
break;
}
if(isalpha(s[i]))
noa++;
if(isdigit(s[i]))
nod++;
if(noa[i] == ' ') && (noa[i + 1] != ' ')
now++;
}
noch = l - nob;
noc = noa - nov;
printf("Total no of words %d", now);
printf("Total no of characters(without blanks)%d", noch);
printf("Total no of characters(including blanks)%d", l);
printf("Total no of alphabets %d", noa);
printf("Total no of vowels %d", nov);
printf("Total no of characters %d", noc);
printf("Total no of digits %d", nod);
getch( );
}
47) Sample C Program to accept two string and compare the strings are equal or not.
# include <stdio.h>
# include <conio.h>
int getline (char line[ ], int lim );
int strc(char str1[ ], char str2[] );
main( )
{
char str1[80],
str2[80]; int comp;
clrscr( );
printf("Enter first string:");
getline(str1, 80);
printf("Enter second string:");
getline(str2, 80);
comp = strc(str1, str2);
if(comp > 0)
printf("First string is bigger.");
else if(comp == 0)
printf("Both the strings are equal.");
getch( );
}
int getline(char str[], int lin)
{
int i;
for(i = 0; i < lin && ( (str[i] = getchar()) != '\n'); i++);
if(str[i] = '\0')
return i;
}
int strc(char str1[], char str2[])
{
int i;
for(i = 0; str1[i]; i++)
if(str1[i] != str2[i])
return str1[i] - str2[i];
return str1[i] - str2[i];
}
48) Sample C Program to sort the entered numbers using bubble sort.
# include <stdio.h>
# include <conio.h>
main( )
{
int a[100], i, j, n, t;
clrscr( );
printf("Enter the array size:");
scanf("%d",&n);
for(i = 1; i < n; i++)
scanf("%d", &a[i]);
for(i = 1; i <= n; i++)
for(j = i + 1; j < n; j++)
if(a[i] > a[j])
{
t = a[i]
a[i] = a[j];
a[j] = t;
}
printf("The sorted elements are:");
for(i = 1; i <= n; i++)
print("%d", a[i]);
getch( );
}
ALSO CHECK THESE C PROGRAMS:
- C Program To Implement Minimum Spanning Tree Using Functions, Pointers & Structures.
- C Program To Implement 8 Queens Problem Using Arrays, Pointers & Functions.
- C Program To Implement Quick Sort Using Pointers, Functions & Arrays.
- C Program To Implement Binary Search Without Using Recursive Function.
- C Program To Implement Binary Search Using Recursive Function.
...Back To C Program Index.
Comments
Post a Comment
Please share your opinions and suggestions or your experience in the comments section. This way we can all help each other...
Experienced guys can share their resumes at admin@interview-made-easy.com