Sunday 4 March 2018

C program to count the number of vowels, consonants and so on

#include <stdio.h>

int main()
{
    char line[150];
    int i, vowels, consonants, digits, spaces;

    vowels =  consonants = digits = spaces = 0;

    printf("Enter a line of string: ");
    scanf("%[^\n]", line);

    for(i=0; line[i]!='\0'; ++i)
    {
        if(line[i]=='a' || line[i]=='e' || line[i]=='i' ||
           line[i]=='o' || line[i]=='u' || line[i]=='A' ||
           line[i]=='E' || line[i]=='I' || line[i]=='O' ||
           line[i]=='U')
        {
            ++vowels;
        }
        else if((line[i]>='a'&& line[i]<='z') || (line[i]>='A'&& line[i]<='Z'))
        {
            ++consonants;
        }
        else if(line[i]>='0' && line[i]<='9')
        {
            ++digits;
        }
        else if (line[i]==' ')
        {
            ++spaces;
        }
    }

    printf("Vowels: %d",vowels);
    printf("\nConsonants: %d",consonants);
    printf("\nDigits: %d",digits);
    printf("\nWhite spaces: %d", spaces);

    return 0;
}



Output:

Enter a line of string: adfslkj34 34lkj343 34lk
Vowels: 1
Consonants: 11
Digits: 9
White spaces: 2

Finding the Number of 500,100,50,20,10,5,2 and 1 Rupee Notes in a Given Amount.

# include <stdio.h> 
# include <conio.h> 
void main() 
{ 
 int rs, a, b, c, d, e, f, g, h ; 
 clrscr() ; 
 printf("Enter the amount in Rupees : ") ; 
 scanf("%d", &rs) ; 
 while(rs >= 500) 
 { 
  a = rs / 500 ; 
  rs = rs % 500;
  printf("\nThe no. of five hundreds are : %d", a) ; 
  break ; 
 } 
 while(rs >= 100) 
 { 
  b = rs / 100 ; 
  rs = rs % 100;
  printf("\n\nThe no. of hundreds are : %d", b) ; 
  break ; 
 } 
 while(rs >= 50) 
 { 
  c = rs / 50 ;
  rs = rs % 50; 
  printf("\n\nThe no. of fifties are : %d", c) ; 
  break ; 
 } 
 while(rs >= 20) 
 { 
  d = rs / 20 ; 
  rs = rs % 20;
  printf("\n\nThe no. of twenties are : %d", d) ; 
  break ; 
 } 
 while(rs >= 10) 
 { 
  e = rs / 10 ; 
  rs = rs % 10;
  printf("\n\nThe no. of tens are : %d", e) ; 
  break ; 
 } 
 while(rs >= 5) 
 { 
  f = rs / 5 ; 
  rs = rs % 5;
  printf("\n\nThe no. of fives are : %d", f) ; 
  break ; 
 } 
 while(rs >= 2) 
 { 
  g = rs / 2 ; 
  rs = rs % 2;
  printf("\n\nThe no. of Twos are : %d", g) ; 
  break ; 
 } 
 while(rs >= 1) 
 { 
  h = rs / 1 ; 
  rs = rs % 1;
  printf("\n\nThe no. of ones are : %d", h) ; 
  break ; 
 } 
 getch() ; 
}

Output of above program is

Enter the amount in Rupees : 698

The no. of five hundreds are : 1

The no. of hundreds are : 1 

The no. of fifties are : 1              
                                        
The no. of twenties are : 2 
                                        
The no. of fives are : 1 
                                        
The no. of Twos are : 1 

The no. of ones are : 1

Tech UOG