write the function. if all the character in string B appear in
string A, return true, otherwise return false.

Answers were Sorted based on User's Feedback



write the function. if all the character in string B appear in string A, return true, otherwise ret..

Answer / patrick

//This works for strings of a fixed length(here 10)..Its
written in assumption that strings are given in same case
completely(ie,india,INdia will be false witout modifican..

#include<stdio.h>
#include<string.h>
main(){
char a1[10],a2[10],cn[10]={0,0,0,0,0,0,0,0,0,0};
int i,j,k,l,c=0;
printf("enter string B\n");
scanf("%s",a1);
printf("enter string A\n");
scanf("%s",a2);
for(i=0;i<strlen(a1);i++){
for(j=0;j<strlen(a2);j++){
if(a1[i]==a2[j]){
c++;
cn[i]=1;
}}}
for(k=0;k<strlen(a1);k++){
if(cn[k]==0){
printf("FALSE\n");exit(0);}}
printf("TRUE\n");}

Is This Answer Correct ?    5 Yes 0 No

write the function. if all the character in string B appear in string A, return true, otherwise ret..

Answer / latter

why u all waisting time... First understand problem then solve.
Problem is like that

suppose B = "iwantto"
A = "Hiwannachatoopsthatiswhy"

Now here all character of B is in A string...

Okay!!!

Is This Answer Correct ?    2 Yes 0 No

write the function. if all the character in string B appear in string A, return true, otherwise ret..

Answer / sravanthi

#include<stdio.h>
#include<stdlib.h>
#include<conio.h>
#include<string.h>
int main()
{
char *a;
a=(char*)malloc(20*sizeof(char));
char *b;
b=(char*)malloc(20*sizeof(char));
int i,j,flag,count,n;
i=j=count=flag=0;
printf("enter the string 1");
gets(a);
printf("enter the string 2");
gets(b);
n=strlen(b);
while(b[j]!='\0')
{
i=0;
flag=0;
while(a[i]!='\0')
{
if(a[i]==b[j])
{
flag=1;
break;
}
else
{
i++;
}
}

if(flag==1)
{
count=count+1;
}
j++;
}
if(count==n)
{
printf("true");

}
else
{
printf("false");
}
getch();
}

Is This Answer Correct ?    2 Yes 0 No

write the function. if all the character in string B appear in string A, return true, otherwise ret..

Answer / raghuram

#include<iostream.h>
#include<stdio.h>
#include<string.h>
int main()
{
char str1[100],str2[100];
int flag1=0,flag=0;
cout<<"\n\nenter 1st string:";
cin>>str1;
cout<<"\n\nenter 2nd string:";
cin>>str2;
int i=0,j=0;
for(i=0;i<strlen(str1);i++)
{ flag=0;
for(j=0;j<strlen(str2);j++)
{
if(str1[i]==str2[j])
{flag=1;
str2[j]=' ';
break;
}
}
if(flag==0)
{
flag1=1;
cout<<"\n\nnot anagrams";
break;
}
}
if(flag1!=1)
cout<<"\nanagrams";


return 0;

}


Is This Answer Correct ?    1 Yes 0 No

write the function. if all the character in string B appear in string A, return true, otherwise ret..

Answer / sam

private bool IsPartOf(string B, string A)
{
if(A==null || B==null) return false;
if(B.Length>A.Length) return false;
A = A.ToLower();
B = B.ToUpper();

for(int i=0; i<A.Length;i++)
{
if((i<B.Length)&&(A[i]==B[i]))
{
bool found = true;
for(int j=i;j<B.Length;j++)
{
if(A[j]!=B[j])
{
found = false;
break;
}
}
if(found) return true;
}
}
return false;
}

Is This Answer Correct ?    1 Yes 0 No

write the function. if all the character in string B appear in string A, return true, otherwise ret..

Answer / satish nerlekar

//assuming both the strings in same case

int main()
{

string A;
string B;

int count = 0;
char repeatChar='$';

cout<<"Enter string A";
cin>>A;
cout<<"Enter the string B";
cin>>B;

if(A.length()<B.length())
{
cout<<"Length of string A is small than B, so all the charaters of the B can't be there in A";
exit(0);
}


int A_length = A.length();
int B_length = B.length();

for(int i=0; i<B_length; i++)
{
for(int j=0; j<A_length; j++)
{
if(A[j] == B[i])
{
if(repeatChar == A[j])
;
else
{
count++;
repeatChar = A[j];
break;
}

}
}
}

if(count==B_length)
cout<<"string A has all the chars of string B";
else
cout<<"string A doesn't have all chars of string B";

return 0;

}

Is This Answer Correct ?    1 Yes 0 No

write the function. if all the character in string B appear in string A, return true, otherwise ret..

Answer / raghuram.a

#include<iostream.h>
#include<string.h>
int h(char letter)
{

return(letter-97);
}

int main()

{

char str1[100],str2[100];

int i=0,count[26];
for(i=0;i<26;i++)

count[i]=0;

clrscr();
cout<<"\n\nenter 1st string:";

cin>>str1;

cout<<"\n\nenter 2nd string:";

cin>>str2;
for(i=0;i<strlen(str1);i++)

{

count[h(str1[i])]++;

}
for(i=0;i<strlen(str2);i++)

{

count[h(str2[i])]--;
} int flag=0;

for(i=0;i<26;i++)

{if(count[i]!=0)
{cout<<"\n\nnot anagrams";

flag=1;

break;

}
}

if(flag==0)

cout<<"\n\nanagrams";

return 0;

}

Is This Answer Correct ?    0 Yes 0 No

write the function. if all the character in string B appear in string A, return true, otherwise ret..

Answer / defcon

#include<iostream.h>
void main()
{
char a,b;
cout<<"Entr the values of a & b";
cin>>a>>b;
if(strcmp(a,b))
cout<<"Both a & b are the same";
else
cout<<"A & b are different";
}

Is This Answer Correct ?    2 Yes 2 No

write the function. if all the character in string B appear in string A, return true, otherwise ret..

Answer / tushar

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

int main()
{
char str1[10],str2[10],temp[10];
char *p,*q;
int flag=1;

cout<<"enter the two strings"<<endl;
cin>>str1;
cout<<"and"<<endl;
cin>>str2;

p=str1;

//strcpy(str2,temp);
//cout<<temp;
if(strlen(str1)!=strlen(str2))
flag=0;

while(*p)
{
char ch=*p;
q=str2;
while(*q)
{
if(ch!=*q)
q++;
else
{
*q='*';
break;
}
}
if((*q)=='\0')
{flag=0;
break;
}
p++;

}

if(flag)
cout<<"anagrams"<<endl;
else
cout<<"not anagrams"<<endl;

getch();
return 0;
}

Is This Answer Correct ?    0 Yes 0 No

write the function. if all the character in string B appear in string A, return true, otherwise ret..

Answer / somisetty

char B_str[] = "aaaaaa";
char A_str[] = "a"
// For the above case, this function should return true

char B_str[] = "aB";
char A_str[] = "aaaaaBaaaaaa"
// For the above case, this function should return true

int B_chars[256]; //for all unique chars in B_str

/* Init B_chars[] */
for( int i = 0; i < 256; i++ )
B_chars[i] = 0;

/* Get characters in B_str */
for( int i = 0; i < strlen(B_str); i++ )
B_chars[(int) B_str[i]]++;

/* check if A_str has which of them */
for( int i = 0; i < strlen(A_str); i++ )
B_chars[(int) A_str[i]] = 0;

/* If any of the B_chars[] has non-zero entry */
for( int i = 0; i < 256; i++ )
{
if( B_chars[i] != 0 )
{
return (false);
}
}

/* Otherwise return true */
return (true);

Is This Answer Correct ?    0 Yes 0 No

Post New Answer

More C Code Interview Questions

hello sir,is there any function in C that can calculate number of digits in an int type variable,suppose:int a=123; 3 digits in a.what ll b answer?

6 Answers  


Write a program using one dimensional array to assign values and then display it on the screen. Use the formula a[i]=i*10 to assign value to an element.

1 Answers   Samar State University,


struct aaa{ struct aaa *prev; int i; struct aaa *next; }; main() { struct aaa abc,def,ghi,jkl; int x=100; abc.i=0;abc.prev=&jkl; abc.next=&def; def.i=1;def.prev=&abc;def.next=&ghi; ghi.i=2;ghi.prev=&def; ghi.next=&jkl; jkl.i=3;jkl.prev=&ghi;jkl.next=&abc; x=abc.next->next->prev->next->i; printf("%d",x); }

1 Answers  


What is the difference between proc means and proc tabulate ? explain with a simple example when you have to use means or tabulate?

1 Answers  


main() { char not; not=!2; printf("%d",not); }

1 Answers  






What are segment and offset addresses?

2 Answers   Infosys,


main() { { unsigned int bit=256; printf("%d", bit); } { unsigned int bit=512; printf("%d", bit); } } a. 256, 256 b. 512, 512 c. 256, 512 d. Compile error

1 Answers   HCL,


what will be the output of this program? void main() { int a[]={5,10,15}; int i=0,num; num=a[++i] + ++i +(++i); printf("%d",num); }

3 Answers   Wipro,


main() { static int var = 5; printf("%d ",var--); if(var) main(); }

1 Answers  


posted by surbhi just now main() { float a = 5.375; char *p; int i; p=(char*)&a; for(i=0;i<=3;i++) printf("%02x",(unsigned char) p[i]); } how is the output of this program is :: 0000ac40 please let me know y this output has come

2 Answers   GATE,


write a simple calculator c program to perform addition, subtraction, mul and div.

0 Answers   United Healthcare, Virtusa,


#define assert(cond) if(!(cond)) \ (fprintf(stderr, "assertion failed: %s, file %s, line %d \n",#cond,\ __FILE__,__LINE__), abort()) void main() { int i = 10; if(i==0) assert(i < 100); else printf("This statement becomes else for if in assert macro"); }

1 Answers  


Categories