Computer Scientists are Pretty Pessimistic

Saturday 5 September 2015

WAP to extract specified number of characters from a given position from a string.

#include <stdio.h>
int main ()
{
    int i,n;
    char a[100];
    printf("Enter string: ");
    gets(a);
    printf("Enter character position: ");
    scanf("%d",&n);
    for(i=0;i<a[i];i++)
    {
        if((i+1)==n)
        {
            printf("The value of this character %d",a[i]);
            break;
        }
    }
    return 0;
}

No comments:

Post a Comment