Saturday 11 November 2017

C Program to Display the Characters in Prime Position a given String


Code:

#include
#include

void main()
{
    int i, j, k, count = 0;
    char str[50];

    printf("enter string\n");
    scanf("%[^\n]s", str);
    k = strlen(str);
    printf("prime characters in a string are\n");
    for (i = 2;i <= k;i++)
    {    
        count = 0;
        for (j = 2;j <= k;j++)
        {
            if (i % j == 0)
            {
                count++;
            }
        }
        if (count == 1)
        {
            printf("%c\n", str[i - 1]);
        }
    }
}



Output:

enter string
welcome to executesss c-programming class!
prime characters in a string are
e
l
o
e

a
u
d
c
r
m
c
s


More C Programs:












100+ Best Home Decoration Ideas For Christmas Day 2019 To Make Home Beautiful

Best gifts for Christmas Day | Greeting cards for Christmas Day | Gift your children a new gift on Christmas day This Christmas d...