Wednesday, July 20, 2011

Program to accept a string and print the rightmost 'n' characters using function {Version 2}

/*Serial No.98     [swami73.cpp]*/ 

#include<stdio.h>
#include<conio.h>
#include<string.h>
#include<alloc.h>
char s1[20];
int n,l,i;

void pri();
void main()
{
clrscr();
printf("enter the string s1:");
gets(s1);
printf("enter the no of characters to extract=");
scanf("%d",&n);
printf("\n\noutput:\n");
pri();
getch();
}
void pri()
    {
    l=strlen(s1);
    i=l-n-1;
    while(s1[i]!='\0')
        {
        i++;
        printf("%c",s1[i]);
        }
    }

No comments:

Post a Comment

If you have any doubt, feel free to ask...