TheFestFever.com

Our aim is to connect students from campuses all over Delhi by making them aware of all Technical, Cultural, Management fests, workshops, Seminars organized by every college in Delhi.

Join Us Now

Program 29: Write a C++ program to print a string which repeats again and again.

#include<iostream>
#include<string.h>
using namespace std;

int main()
{
	string str;
	int flag=0;
	cout<<"\nenter a string : ";
	cin>>str;
	int size=str.length();

	for(int i=0;i<size;i++)
	{
		for(int j=i+1;j<size;j++)
		{
			if((str[i]==str[j])&&(str[i+1]==str[j+1])&&(i+1<size)&&(j+1<size))
			{
				cout<<str[i];
				while((str[i+1]==str[j+1])&&(i+1<size)&&(j+1<size))
				{
					cout<<str[i+1];
					i++;
					j++;
				}
				flag=1;
				exit(0);
			}
		}
	}

	if(flag==0)
	cout<<"\nNO string is repeated!!!";
	return 0;
}



If you have any suggestion or found any error in the above program, then do let us know at [email protected] or just comment below.