#include #include int findRepeat(char* s) { int p , i , j; p = -1; for (i = 0 ; i < strlen(s) ; i++) { for (j = i + 1; j < strlen(s); j++) { if (s[i] == s[j]) { p = i; break; } } if (p != -1) break; } return p; } int main() { char str[] = "Hello World"; int pos = findRepeat(str); if (pos == -1) printf("Not found"); else printf("%c", str[pos]); return 0; } can you please explain this code for me
#include <stdio.h>
#include <string.h>
int findRepeat(char* s)
{
int p , i , j;
p = -1;
for (i = 0 ; i < strlen(s) ; i++)
{
for (j = i + 1; j < strlen(s); j++)
{
if (s[i] == s[j])
{
p = i;
break;
}
}
if (p != -1)
break;
}
return p;
}
int main()
{
char str[] = "Hello World";
int pos = findRepeat(str);
if (pos == -1)
printf("Not found");
else
printf("%c", str[pos]);
return 0;
}
can you please explain this code for me
![](/static/compass_v2/shared-icons/check-mark.png)
#include <stdio.h>
#include <string.h>
int findRepeat(char* s)
{
int p , i , j;
p = -1;
for (i = 0 ; i < strlen(s) ; i++) // Counts each character present in the string
{
for (j = i + 1; j < strlen(s); j++) // Counts each character present in the string
{
if (s[i] == s[j]) // If find chracter in j that is same as i
{
p = i; // Store i in p and break the loop
break;
}
}
if (p != -1) // If Repeated character is not found
break;
}
return p; // Return p
}
// Driver Code
int main()
{
char str[] = "Hello World"; // Set a string
int pos = findRepeat(str); // Calling function
if (pos == -1) //If Repeated character not found and print not found
printf("Not found");
else
printf("%c", str[pos]); // Repeated character found and print value of this character, it will print l because it repeated
return 0;
}
Step by step
Solved in 2 steps with 3 images
![Blurred answer](/static/compass_v2/solution-images/blurred-answer.jpg)
![Computer Networking: A Top-Down Approach (7th Edi…](https://www.bartleby.com/isbn_cover_images/9780133594140/9780133594140_smallCoverImage.gif)
![Computer Organization and Design MIPS Edition, Fi…](https://www.bartleby.com/isbn_cover_images/9780124077263/9780124077263_smallCoverImage.gif)
![Network+ Guide to Networks (MindTap Course List)](https://www.bartleby.com/isbn_cover_images/9781337569330/9781337569330_smallCoverImage.gif)
![Computer Networking: A Top-Down Approach (7th Edi…](https://www.bartleby.com/isbn_cover_images/9780133594140/9780133594140_smallCoverImage.gif)
![Computer Organization and Design MIPS Edition, Fi…](https://www.bartleby.com/isbn_cover_images/9780124077263/9780124077263_smallCoverImage.gif)
![Network+ Guide to Networks (MindTap Course List)](https://www.bartleby.com/isbn_cover_images/9781337569330/9781337569330_smallCoverImage.gif)
![Concepts of Database Management](https://www.bartleby.com/isbn_cover_images/9781337093422/9781337093422_smallCoverImage.gif)
![Prelude to Programming](https://www.bartleby.com/isbn_cover_images/9780133750423/9780133750423_smallCoverImage.jpg)
![Sc Business Data Communications and Networking, T…](https://www.bartleby.com/isbn_cover_images/9781119368830/9781119368830_smallCoverImage.gif)