The question was :
Write a program to determine whether an input string has unique characters or not using atmost two primitive data structures ?
[ Hint : primitive data structure may be integer,character. ]
It can be done by using recursive approach.
The code is given below :
#include<stdio.h>
#include<string.h>
char str[30];
int i;
void check(char a,int x)
{
if (a=='\0')
{
printf("\n all the charachers are unique\n");
getch();
exit (0);
}
for (i=x-1;i>=0;i--)
{
if (a==str[i])
{
printf("\nall characters are not unique");
printf("\n '%c' is being repeated\n",a);
getch();
exit(0);
}
}
check(str[x+1],x+1);
}
main()
{
clrscr();
printf("\n enter the string :");
scanf ("%[^\n]",str);
check(str[0],0);
return 1;
}
Write a program to determine whether an input string has unique characters or not using atmost two primitive data structures ?
[ Hint : primitive data structure may be integer,character. ]
It can be done by using recursive approach.
The code is given below :
#include<stdio.h>
#include<string.h>
char str[30];
int i;
void check(char a,int x)
{
if (a=='\0')
{
printf("\n all the charachers are unique\n");
getch();
exit (0);
}
for (i=x-1;i>=0;i--)
{
if (a==str[i])
{
printf("\nall characters are not unique");
printf("\n '%c' is being repeated\n",a);
getch();
exit(0);
}
}
check(str[x+1],x+1);
}
main()
{
clrscr();
printf("\n enter the string :");
scanf ("%[^\n]",str);
check(str[0],0);
return 1;
}
No comments:
Post a Comment