Showing posts with label string. Show all posts
Showing posts with label string. Show all posts

Friday, 12 October 2012

String032

Write a program which asks the user to enter the name and age of persons in his group. The number of persons is not known to the user in the beginning of the program. The user keeps on entering the data till the user enters the age as zero. The program finally prints the average age.

#include <stdio.h>
#include <conio.h>
void main ( )
{                                    
        int           age, totage = 0, n = 0;
        char        name[40];
        float        avgage = 0;
        clrscr ( );
                        
        do     
        {                                  
                fflush ( stdin );
                printf("\n\n\t\t Enter name.:"); gets(name);
                fflush ( stdin );
                printf("\t\t Enter age..:"); scanf("%d",&age);
                totage = totage + age;
                n++;
        } while ( age != 0 );
        avgage = ( float ) totage / n;
                 
        printf("\n\n\n\n\t\t Average age=%.2f",avgage);
        getch ( );
}
Click here to contact us

Monday, 24 September 2012

String030

Input state and print capital of that state.

#include <stdio.h>
#include <conio.h>
#include <string.h>
void main ( )
{
        char       nm[80];
        char       state[6][20] = { "WEST BENGAL", "BHIHAR", "ORISHA", "ASSAM",
                                               "GUJARAT", "RAJASTHAN" };
        char       cap[6][20] = { "kolkata", "patna", "bhubaneswar", "dispur",
                                             "gandhinagar", "jaipur" };
        int          c, i = 1;
        clrscr ( );
                     
        printf("\n\n\n\t NAME OF STATE \n\t_______________\n\t");
        for ( c = 0; c < 6; c++)
        {                                             
                     printf("\n\n\t  %s", state[c] );
        }
                                     
        printf("\n\n\n\t Enter the name of state....:"); gets(nm);
                              
        for ( c = 0; c <= 5; c++)
        {                                                   
                     if ( strcmp( nm, state[c] ) == 0 )
                     {                                    
                                    printf("\n\n\n\t Capital.....: %s", cap[c] );
                                    i = 0;
                                    break;
                     }
        }                                       
        if ( i == 1 )
        {                      
                 printf("\n\n\n\t\t NOT FOUND!");
        }
        getch ( );
}
Click here to contact us

String029

Password program.

#include <stdio.h>
#include <conio.h>
#include <string.h>
void main ( )
{
         char     masterlist[6][10] = { "akshya", "dipankar", "sanjay", "nilanjan", "sankar", "gopal" };
         char     yourname[10];
         int        i, flag = 0;
         clrscr ( );
                                 
         printf("\n\n\n\t Enter your name....:"); gets(yourname);
                         
         for ( i = 0; i <= 5; i++)
         {                              
                     if ( strcmp( yourname, masterlist[i] ) == 0 )
                     {                                     
                                    printf("\n\n\n\t\t WELCOME, YOU CAN ENTER THE PALACE!");
                                    flag = 1;
                                    break;
                     }
         }          
         if ( flag == 0 )
         {                                                       
                     printf("\n\n\n\t\t SORRY, YOU ARE A TRESPASSER!");
         }
         getch ( );
}
Click here to contact us

Sunday, 23 September 2012

String028

Input a sentence and a word, write a program to  find whether the word is in the sentence or not.

#include <stdio.h>
#include <conio.h>
#include <string.h>
void main ( )
{
          char       nm1[80], nm2[80][80], nm3[80], nm4[80] ;
          int          i = 0, j = 0, n = 0, y = 0, ln, m = 1;
          clrscr ( );
                                                      
          printf("\n\n\n\t Enter a sentence....:"); gets(nm1);
          printf("\n\n\n\t Enter a word....:"); gets(nm3);
          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;
                       }
          }                
          for ( j = 0; j < i; j++)
          {                                                                                 
                       n = strcmp ( nm2[ j], nm3 );
                       if ( n == 0 )   
                       {                      
                                 m = 0;
                                 break;
                       }
          }                 
          if ( m == 0 )
          {                                  
                       printf("\n\n\n\t\t WORD FOUND!");
          }                                                                 
          else                                                          
          {                                                             
                       printf("\n\n\n\t\t WORD NOT FOUND!");
          }
          getch ( );
}
Click here to contact us

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

String020

Input two strings and merge them in third string.

#include <stdio.h>
#include <conio.h>
#include <string.h>
void main ( )
{
        char        nm1[80], nm2[80], nm3[80];
        int           ln1, ln2,  j, i = 0;
        clrscr ( );
                   
        printf("\n\n\n\t\t Enter first string..........:"); gets (nm1);
        printf("\n\n\n\t\t Enter second string.....:"); gets (nm2);
                                 
        ln1 = strlen (nm1);
        ln2 = strlen (nm2);
                                    
        for ( j = 0; j < ln1; j++ )
        {                                     
                    nm3[i++] = nm1[ j];
        }
                                         
        for ( j = 0; j < ln2; j++ )
        {                                       
                    nm3[i++] = nm2[ j];
        }
        nm3[i] = '\0';
                               
        printf("\n\n\n\t\t Merge String....: %s",nm3);
        getch ( );
}
Click here to contact us

String019

 Input a sentence in a string and store first word in another string.

#include <stdio.h>
#include <conio.h>

void main ( )
{
          char        nm[80], nm1[80];
          int           ln, j, c = 0;
          clrscr ( );
                          
          printf("\n\n\n\t\t Enter a sentence....:"); gets (nm);
          for ( ln = 0; nm[ln] != '\0'; ln++ );
                                            
          for ( j = 0; j < ln; j++ )
          {                                
                       if ( nm[ j] != ' ' )
                       {                                    
                                     nm1[c++] = nm[ j];
                       }                                         
                       else                                         
                       {                                        
                                     break;
                       }
          }
          nm1[c++] = '\0';
                                         
          printf("\n\n\n\t\t WORD....: %s",nm1);
          getch ( );
}
Click here to contact us 

Wednesday, 19 September 2012

String018

Input a sentence and print all the words of that sentence.

#include <stdio.h>
#include <conio.h>

void main ( )
{
          char        nm[80];
          int           ln, j;
          clrscr ( );
                                
          printf("\n\n\n\t\t Enter a sentence....:"); gets (nm);
          for ( ln = 0; nm[ln] != '\0'; ln++ );
                                                 
          printf("\n\n\n\t\t WORDS....:     ");
          for ( j = 0; j < ln; j++ )
          {                                     
                      if ( nm[ j] == ' ' )
                      {                            
                                     printf("\n\n\t\t\t\t");
                      }               
                      else                               
                      {                                      
                                     printf("%c", nm[ j] );
                      }
          }
          getch ( );
}
Click here to contact us

Tuesday, 18 September 2012

String017

Write a program to construct  the image shown below.

                      I    I    I    I    I
                        N  N  N  N
                           D   D  D
                               I    I
                                 A

#include <stdio.h>
#include <conio.h>

void main ( )
{
          char        nm[80];
          int           i, ln, j, k, a = 25;
          clrscr ( );
                  
          printf("\n\n\n\t\t Enter a word....:"); gets (nm);
          for ( ln = 0; nm[ln] != '\0'; ln++ );
                                 
          printf("\n\n\n\n");
          for ( j = 0; j < ln; j++ )
          {                                    
                       for ( k = 0; k <= a; k++ )
                       {                                  
                                     printf(" ");
                       }                                   
                       for ( i = ln; i > j; i-- )
                       {                              
                                     printf("%c ", nm[ j] );
                       }
                       a++;
                       printf("\n\n" );
          }
          getch ( );
}
 Click here to contact us

String016

Write a program to construct  the image shown below.
                         I
                         N N
                         D D D
                         I   I   I   I
                         A  A  A  A  A

#include <stdio.h>
#include <conio.h>

void main ( )
{
          char        nm[80];
          int         i, ln, j, k, a = 25;
          clrscr ( );
                             
          printf("\n\n\n\t\t Enter a word....:"); gets (nm);
          for ( ln = 0; nm[ln] != '\0'; ln++ );
                                
          printf("\n\n\n\n");
          for ( j = 0; j < ln; j++ )
          {                                   
                      for ( k = 0; k <= a; k++ )
                      {                                       
                                   printf(" ");
                      }                               
                      for ( i = 0; i <= j; i++ )
                      {                                         
                                   printf("%c ", nm[ j] );
                      }
                      printf("\n\n" );
          }
          getch ( );
}
Click here to contact us

Monday, 17 September 2012

String015

Write a program to construct  the image shown below. 
                         I
                       I  N
                     I  N  D
                   I  N  D  I
                 I  N  D  I  A
 
#include <stdio.h>
#include <conio.h>

void main ( )
{
          char        nm[80];
          int           i, ln, j, k, a = 25;
          clrscr ( );
                             
          printf("\n\n\n\t\t Enter a word....:"); gets (nm);
          for ( ln = 0; nm[ln] != '\0'; ln++ );
                               
          printf("\n\n\n\n");
          for ( j = 0; j < ln; j++ )
          {                                    
                      for ( k = 0; k <= a; k++ )
                      {                         
                                   printf(" ");
                      }                               
                      for ( i = 0; i <= j; i++ )
                      {                                   
                                   printf("%c ", nm[i] );
                      }
                      a--;
                      printf("\n\n" );
          }
          getch ( );
}
 Click here to contact us

String014

Write a program to construct  the image shown below.

                     I
                     I  N
                     I  N  D
                     I  N  D  I
                     I  N  D  I  A

#include <stdio.h>
#include <conio.h>

void main ( )
{
        char        nm[80];
        int           i, ln, j;
        clrscr ( );
             
        printf("\n\n\n\t\t Enter a word....:"); gets (nm);
        for ( ln = 0; nm[ln] != '\0'; ln++ );
              
        printf("\n\n\n\n\n\t\t\t" );
        for ( j = 0; j < ln; j++ )
        {                                      
                    for ( i = 0; i <= j; i++ )
                    {                                   
                                printf("%c ", nm[i] );
                    }
                    printf("\n\n\n\t\t\t" );
        }
        getch ( );
}
Click here to contact us

String013

Input a word and find the word is palindrome or not.

#include <stdio.h>
#include <conio.h>

void main ( )
{
        char      nm[80], nm1[80];
        int         i = 0, ln, j, s = 0;
        clrscr ( );
            
        printf("\n\n\n\t\t Enter a word....:"); gets (nm);
        for ( ln = 0; nm[ln] != '\0'; ln++ );
        
        for ( j = ln - 1; j >= 0; j-- )
        {            
                    nm1[ j] = nm[i++];
        }
        nm1[ln] = '\0';
                 
        for ( i = 0; i < ln; i++ )
        {                                   
                    if ( nm[i] != nm1[i] )
                    {                           
                                   s = 1;
                                   break;
                    }
        }
                      
        if ( s == 0 )
        {                         
                  printf("\n\n\n\t\t It is a Palindrome word...: %s ", nm);
        }                
        else                     
        {                        
                  printf("\n\n\n\t\t It is not a Palindrome word...: %s ", nm);
        }
        getch ( );
}
Click here to contact us
Related Posts Plugin for WordPress, Blogger...