Sunday, 9 March 2014

Printing of characters and strings.

Printing of characters and strings.

Code for Printing of characters and strings in C Programming

main()                                                      
   {                                                           
       char x = 'A';                                           
       staticchar  name[20] = "ANIL KUMAR GUPTA";             
                                                               
       printf("OUTPUT OF CHARACTERS\n\n");                     
       printf("%c\n%3c\n%5c\n", x,x,x);                        
       printf("%3c\n%c\n", x,x);                               
       printf("\n");                                           
                                                               
       printf("OUTPUT OF STRINGS\n\n");                        
       printf("%s\n", name);                                   
       printf("%20s\n", name);                                 
       printf("%20.10s\n", name);                              
       printf("%.5s\n", name);                                 
       printf("%-20.10s\n", name);                             
       printf("%5s\n", name);                                  
   }                                                           
                                                               
Output                                                      
                                                               
   OUTPUT OF CHARACTERS                                        
                                                               
    A                                                           
      A                                                         
        A                                                       
      A                                                         
    A                                                           
                                                               
   OUTPUT OF STRINGS                                           
                                                               
   ANIL KUMAR GUPTA                                            
       ANIL KUMAR GUPTA                                        
             ANIL KUMAR                                        
   ANIL                                                        
   ANIL KUMAR                                                  
   ANIL KUMAR GUPTA                                            

No comments:

Post a Comment