This is a C Program to display the characters in prime position of a given string.
This program prints the characters in prime position of a given string.
1. Take a string as input.
2. Find the number which gets divided only once and consecutively print the character of the obtained position.
Here is source code of the C Program to display the characters in prime position a given string. The C program is successfully compiled and run on a Linux system. The program output is also shown below.
* C Program to Display the Characters in Prime Position a given String
int i, j, k, count = 0;
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)
if (count == 1)
printf("%c\n", str[i - 1]);
1. Take a string as input and store it in the array str.
2. Store the length of the input string in the variable k.
3. Use two loops to divide the numbers upto the value of k.
4. Increment the variable count when the remainder is zero.
5. If the variable count is equal to 1, then print the corresponding character.
enter string welcome to sanfoundry c-programming class! prime characters in a string are e l o e a u d c r m c s
Sanfoundry Global Education & Learning Series – 1000 C Programs.
Here’s the list of Best Books in C Programming, Data-Structures and Algorithms
- Get Free Certificate of Merit in C Programming
- Participate in C Programming Certification Contest
- Become a Top Ranker in C Programming
- Take C Programming Tests
- Chapterwise Practice Tests: Chapter 1, 2, 3, 4, 5, 6, 7, 8, 9, 10
- Chapterwise Mock Tests: Chapter 1, 2, 3, 4, 5, 6, 7, 8, 9, 10
- Apply for Computer Science Internship
- Practice Computer Science MCQs
- Watch Advanced C Programming Videos
- Apply for C Internship
- Practice BCA MCQs