Monday 1 October 2012

Function013

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

#include <stdio.h>
#include <conio.h>
void right ( 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);
               
        right ( n, c );                                  /* Function calling */
        getch ( );
}                               
                                 
void right ( char    nm[80], int    x )        /* Function Definition */
{                     
        int      ln = 0, i = 0, y;
        for ( ln = 0; nm[ln] != '\0'; ln++ );
                    
        if ( x <= ln )
        {                   
                printf("\n\n\n\t\t OUTPUT....:");
                y = ln - x;
                for ( i = y; i < ln; 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...