Monday 1 October 2012

Function012

A name or a word and a number entered through the keyboard. Write a function to print that name or word from left up to entered number.

#include <stdio.h>
#include <conio.h>
void left ( char[], int );
void main ( )
{                                
        char    n[80];
        int       c;
        clrscr ( );
                 
        printf("\n\n\n\n\t\t Enter a name...:"); gets ( n );
        printf("\n\n\t\t Enter a number...:"); scanf("%d", &c);
                              
        left ( n, c );                                    /* Function calling */
                  
        getch ( );
}                                
                                            
void left ( char    nm[80], int    x )        /* Function Definition */
{               
        int      ln = 0, i;
        for ( ln = 0; nm[ln] != '\0'; ln++ );
                                                    
        if ( x <= ln )
        {                                
                  printf("\n\n\n\t\t OUTPUT....:");
                  for ( i = 0; i < x; i++ )
                  {                    
                              printf("%c", nm[i] );
                  }
        }                               
        else                                                   
        {                                   
                  printf("\n\n\n\t\t Invalid Input....");
        }
}
Click here to contact us

No comments:

Post a Comment

Related Posts Plugin for WordPress, Blogger...