31) Sample C Program to accept a string and print each word in new line.
# include <stdio.h>
# include <conio.h>
main( )
{
char ch;
clrscr( );
printf("Enter a string :");
while( ( ch = getchar( ) ) != '\n')
{
putchar(ch);
if(ch == ' ')
printf("\n");
}
getch( );
}
32) Sample C Program to accept a string and count no of capital letters, no. of small letters and no. of special characters.
# include <stdio.h>
# include <conio.h>
main( )
{
char ch;
int c = 0,s = 0,s1 = 0;
clrscr( );
printf("Enter a string :");
while( ( ch = getchar( ) ) != '\n')
{
if(ch >= 'A' && ch >= 'Z')
c = c + 1;
else if(ch >= 'a' && ch >= 'z')
s = s + 1;
else
s1 = s1 + 1;
}
printf("No. of capital letters are %d", c);
printf("No. of small letters are %d", s);
printf("No. of special characters are %d", s1);
getch( );
}
33) Sample C Program to accept any single digit number and print it in words.
# include <stdio.h>
# include <conio.h>
main( )
{
int n;
clrscr( );
printf("Enter a number :");
scanf("%d", &n);
switch(n)
{
case 0: printf("ZERO");
break;
case 1: printf("ONE");
break;
case 2: printf("TWO");
break;
case 3: printf("THREE");
break;
case 4: printf("FOUR");
break;
case 5: printf("FIVE");
break;
case 6: printf("SIX");
break;
case 7: printf("SEVEN");
break;
case 8: printf("EIGHT");
break;
case 9: printf("NINE");
break;
default:
printf("Please enter any number between 0 and 9.");
}
getch( );
}
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