Sunday, 23 September 2012

String027

Input a sentence and find the length of each word of that sentence.

#include <stdio.h>
#include <conio.h>
#include <string.h>
void main ( )
{
           char       nm1[80], nm2[80][80];
           int          i = 0, j = 0, c = 0, y = 0, ln;
           clrscr ( );
                                                  
           printf("\n\n\n\t Enter a sentence....:"); gets(nm1);
           ln = strlen (nm1);
                                              
           for ( y = 0; y <= ln; y++ )
           {                                                 
                        if ( nm1[y] != ' ' && nm1[y] != '\0' )
                        {                                                     
                                        nm2[i][ j] = nm1[y];
                                        j++;
                        }                                          
                        else                                                 
                        {                                                     
                                        nm2[i][ j] = '\0';
                                        i++;
                                         j = 0;
                        }
           }             
           printf("\n\n\n\t\t WORD \t LENGTH OF WORD \n\t\t________________________");
           for ( c = 0; c < i; c++ )
           {                                   
                        printf("\n\n\n\t\t %s \t\t %d", nm2[c], strlen (nm2[c]) );
           }
           getch ( );
}
Click here to contact us

Saturday, 22 September 2012

String026

Concept of strcmp ( ).

#include <stdio.h>
#include <conio.h>
#include <string.h>
void main ( )
{
           char      nm1[80], nm2[80];
           int         c = 0;
           clrscr ( );
                           
           printf("\n\n\n\t\t Enter a name.....( 1 )....:"); gets(nm1);
           printf("\n\n\n\t\t Enter a name.....( 2 )....:"); gets(nm2);
                          
           c = strcmp ( nm1, nm2 );     /* Used for comparing two strings */
                             
           if ( c == 0 )
           {                                          
                     printf("\n\n\n\t\t Same String");
           }                
           else                          
           {                                      
                     if ( c > 0 )
                     {               
                               printf("\n\n\n\t\t String....( 1 )..is big");
                     }                             
                     else                        
                     {                                                   
                               printf("\n\n\n\t\t String....( 2 )..is big");
                     }
           }
           getch ( );
}
Click here to contact us

String025

Concept of strcat ( ).

#include <stdio.h>
#include <conio.h>
#include <string.h>
void main ( )
{
          char        source[6] = "Folks";
          char        target[12] = "Hello" ;
          clrscr ( );
                  
          strcat ( target, source );               /* Used for concatenate two strings */
                    
          printf("\n\n\n\t\t Source String.....: %s", source);
          printf("\n\n\n\t\t Target String.....: %s", target);
                    
          getch ( );
}
Click here to contact us

String024

Concept of strcpy ( ).

#include <stdio.h>
#include <conio.h>
#include <string.h>
void main ( )
{
           char        source[] = "Sayonara";
           char        target[20];
           clrscr ( );
                       
           strcpy ( target, source );     /* Using for copying element from source to target */
                     
           printf("\n\n\n\t\t Source String.....: %s", source);
           printf("\n\n\n\t\t Target String.....: %s", target);
             
           getch ( );
}
Click here to contact us

Friday, 21 September 2012

String023

Input an amount and print it in words. 

#include <stdio.h>
#include <conio.h>
void main ( )
{
         char   tenth[10][40] = {"Ten","Eleven","Twelve","Thirteen","Forteen","Fifteen",
                                              "Sixteen","Seventeen","Eighteen","Nineteen"};
         char   dig[10][20] = {"","One","Two","Three","Four","Five","Six","Seven",
                                              "Eight","Nine"};
         char   tense[10][40] = {"","","Twenty","Thirty","Forty","Fifty","Sixty","Seventy",
                                                    "Eighty","Ninety"};
         int      d1,d2,d3,n,r,d5,d4;
         clrscr ( );
                        
         printf("\n\n\n\t Enter a amount in Rs. (less than 32767)..:"); scanf("%d",&n);
             
         d5 = n % 10;
         n = n / 10;
         d4 = n % 10;
         n = n / 10;
         d3 = n % 10;
         n = n / 10;
         d2 = n % 10;
         n = n / 10;
         d1 = n%10;
                             
         printf("\n\n\n\t Rupees in words...:");
         if ( d1 == 0  && d2 != 0 )
         {                                        
                      printf("%s thousand ",dig[d2] );
         }                                
         else if ( d1 == 1)
         {                                              
                       printf("%s thousand ",tenth[d1] );
         }                                         
         else if ( d1 != 1 && d1 != 0 )
         {                                          
                       printf("%s %s thousand ",tense[d1],dig[d2] );
         }                                    
         if( d3 != 0 )
         {                                                      
                       printf("%s hundred ",dig[d3] );
         }                                                          
         if( d4 == 1 )
         {                                      
                       printf("%s",tenth[d5] );
         }                                               
         else                                       
         {                                                
                       printf("%s %s",tense[d4],dig[d5] );
         }
         getch ( );
}
Click here to contact us

String022

Input a number and write a program to spell all the digit of that number.

#include <stdio.h>
#include <conio.h>
void main ( )
{
         char        dg[ ][7] = { "Zero", "One", "Two", "Three", "Four", "Five",
                                          "Six", "Seven", "Eight", "Nine" };
         int           no, c = 0, md[10], d = 0;
         clrscr ( );
                               
         printf("\n\n\n\t\t Enter a Number (less than 32767)...:"); scanf("%d", &no);
                              
         while ( no > 0 )
         {                              
                         md[c] = no % 10;
                         no = no /10;
                         c++;
         }                    
                        
         printf("\n\n\n\t Digits are [ in word].....:");
         for ( d = c - 1; d >= 0; d-- )
         {                                                
                         printf("%s ", dg[ md[d] ] );
         }
         getch ( );
}
Click here to contact us

Thursday, 20 September 2012

String021

Input a name or a sentence and find the vowel on that name.

#include <stdio.h>
#include <conio.h>
#include <string.h>
void main ( )
{
         char        nm1[80], nm2[80], nm3[80], c;
         int           ln,  j, i = 0, k = 0;
         clrscr ( );
               
         printf("\n\n\n\t Enter a sentence or a name......:"); gets (nm1);
         ln = strlen (nm1);
                     
         for ( j = 0; j < ln; j++ )
         {           
                     c = nm1[j];
                     if ( c != ' ' )
                     {                         
                              if ( c == 'a' || c == 'e' || c == 'i' || c == 'o' || c == 'u'
                                    || c == 'A' || c == 'E' || c == 'I' || c == 'O' || c == 'U' )
                                                        nm2[i++] = nm1[ j];
                              else                            
                                                        nm3[k++] = nm1[ j];
                     }
         }
         nm2[i] = '\0';
         nm3[k] = '\0';
                                    
         printf("\n\n\n\t The vowel in a name or a sentence ....: %s",nm2);
         printf("\n\n\n\t The consonant in a name or a sentence ....: %s",nm3);
         getch ( );
}
Click here to contact us
Related Posts Plugin for WordPress, Blogger...