You cannot select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

49 lines
922 B
C

/*
* C Program to Display the Characters in Prime Position a given String
*/
#include <stdio.h>
#include <string.h>
void main()
{
int i, j, k, count = 0;
char str[50];
printf("enter string
");
scanf("%[^
]s", str);
k = strlen(str);
printf("prime characters in a string are
");
for (i = 2; i <= k; i++)
{
count = 0;
for (j = 2; j <= k; j++)
{
if (i % j == 0)
{
count++;
}
}
if (count == 1)
{
printf("%c
", str[i - 1]);
}
}
}
enter string
get ready to get illuminted!
prime characters in a string are
e
t
r
a
t
u
i
d