0 like 0 dislike
22k views

Write a function that tests whether two words or phrases are anagrams (permutations of the same letters):

寫一個判斷兩個單詞或詞組是不是符合易位構詞的函數。

#include <stdio.h>
#include <string.h>
#include <ctype.h>
int is_anagrams(char A[],char B[])
{
   /*INSERT YOUR CODE HERE*/


   /*END OF YOUR CODE*/
   //The function should return 1 if two words or phrases are anagrams, 0 if two words or phrases are not anagrams.
}

int main(void)
{
   char A[100],B[100];
   /*INSERT YOUR CODE HERE*/


   /*END OF YOUR CODE*/
   if (is_anagrams(A,B)) printf("Two words or phrases are anagrams");
   else printf("Two words or phrases are not anagrams");

   return 0;
}

Example input:

smartest
mattress

Example output:

Two words or phrases are anagrams

Example input:

dumbest
stumble

Example output:

Two words or phrases are not anagrams

Remember: You may correct the cases, but your code always be revised! 

[Exercise] Coding (C) - asked in Chapter 9: Functions
ID: 39986 - Available when: Unlimited - Due to: Unlimited
| 22k views
0 0
STRUPES!

79 Answers

0 like 0 dislike
Hidden content!
#include ** ** ** * *
* *** * * ***
* * **** ** **** **
int * * ** A[],char B[])
{
* * ** ** * * YOUR CODE HERE*/
**** ** * **** * * * ** i;
***** ** * * n = * ***

* ****** * ******** = 0; i * n; i++)
** * * * *
** * * * * ** **** * * ** **** ** = * * *
* ** * * * ** * * ** ** * * * ****** * **
* * ** *** ** ******

*** ** * * * ** * * * = 0; i ***** n; i++)
** * ** ****** **
** * * * * ** ** * *** ** * ** ** **** ** * = * ** *
*** *** * ** ** *** ** * ** ** ** ** *
** * ** ** *****

* **** * ** * *** = 0; i < 26; i++)
* * * ****** *** * *
** * *** * ** ** *** **** ** ** * ** != b[i])
* ** *** * ** **** * * ** * *** *** * *** 0;
** ** * ***** ** ** ***
* ****** ** * * ** 1;

* *** * *** * *** * OF YOUR CODE*/
** * * ** * *** * should return 1 if two words or phrases are * * 0 if two words or phrases are not
}

int * ** **
{
* * ** * *** **** * **** ** **
** ****** * * ** * *** * YOUR CODE HERE*/
* ** *** ** * * * ** 100, stdin);
* * * *** * ** ** **** ** * 100, stdin);

* **** * ** OF YOUR CODE*/
** * ***** ** ** ** * ** * ** ** * ** * ** words or phrases are * * *****
* * * * * *** * * **** ** words or phrases are not **** ** *

* * * * ** * ** 0;
}
answered by (-255 points)
0 0
Case 0: Correct output
Case 1: Correct output
Case 2: Correct output
Case 3: Correct output
Case 4: Correct output
0 like 0 dislike
Hidden content!
#include <stdio.h>

int is_anagrams(char A[],char B[])
{
* ** * ** * * ** * Array1[26] = {0}, Array2[26] = {0}, i = 0;
*** * *** **** *
* ******* ******* *** * (A[i] != '\0')
* *** * * * ** ****** ** ***
******* * * * ** *** ** ** **** * *** ** * *** ** * * || A[i]-'A']++;
** * * *** * ** ** * ***** ** ** *
** * * * ** * * ****
* ** *** * ** * * * * ** *
* * *** ** ****** * = 0;
** ** ** **** ** **
**** * * **** *** * (B[i] != '\0')
** * *** *** ** * * **
* ** ****** ******** ** *** *** * * ** * ** ***** * || B[i]-'A']++;
******* ***** *** * **** **** ** ** *** **
**** ** *** ** **
** * * ** * * * *** *** *
* * ** *** * ****** *** (i = 0; i < 26; i++)
* * * * * * * ** *
* ** * * ** * *** *** * ***** * * ******* *** * * (Array1[i] != Array2[i])
* ** ** *** ** ** ** * *** * **** * * * ** **** *** ** *** * **** * 0;
*** ** ***** ** * ******
** ** * * * * *
**** * **** ** * ** ******* 1;
}

int main()
{
** * *** * * ** * * * ** ** A[100],B[100];
* *** **** * * *****
* * * * * *** * * * * * * * * ** * ** *
* * * * * * ***** ** * * * ** *** ****
* *** * * * *** *
* * * ** * ** * **** (is_anagrams(A,B))
*** ************ ***
** *** * * * * ** * * ** * * ** **** * * ** * ** ** words or phrases are anagrams");
*** * * ** *****
** * **** ** * *** printf("Two words or phrases are not anagrams");
* * ***** ** * *** *** *
* * * * * * * ***** 0;
}
answered by (-193 points)
0 0
Case 0: Correct output
Case 1: Wrong output
Case 2: Correct output
Case 3: Wrong output
Case 4: Wrong output
0 like 0 dislike
Hidden content!
#include <stdio.h>

int is_anagrams(char A[],char B[])
{
* * * * * * * * ** * * ** Array1[26] = {0}, Array2[26] = {0}, i = 0;
** ** ****** * ****** *
******* * *** * *** * (A[i] != '\0')
** ******* * * *
* ***** ** ****** * * ** ** ** * **** **** * ** ***** ******
* * **** * ** * * ** ** * * ** * * ** * **** *
** * * *** *** * * ***
* ** ** * * * ***
** * ******* **** * * = 0;
** ** * **** ******* *
** *** ** * * * * (B[i] != '\0')
** * * ** * * **
** * * * *** ***** ** * * ***** * * **** ** **** * ****
**** * *** *** * * * * ** * * ** *
** * ** * *** * * **** * ** *
* * ***** *** * * *
* * * * **** * ***** * (i = 0; i < 26; i++)
* * ** ****** ** * * *
* ** * * *** ***** * ** ** * *** *** * * * (Array1[i] != Array2[i])
** * ***** ** *** *** * * * ** ******* ****** *** ** ** 0;
** * * * ** ** *** *
    
** ** *** **** * ** * 1;
}

int main()
{
* *** * * * ******** A[100],B[100];
*** * ** ** **** * *
** *** ** * * * ** ** **** * * *
* * * ** ****** * *** ** *** *** **** *
****** * *** * * * * **** *
* * ******** ****** * * (is_anagrams(A,B))
** ** * * *****
**** *** * * * * ** * * **** * * * *** * * ** * * words or phrases are anagrams");
* *** * * * ** ** ** **
* *** * * *** * printf("Two words or phrases are not anagrams");
*** ** * * * * * * *
** * ** *** * * * * * ** * *** 0;
}
answered by (-193 points)
0 0
Case 0: Correct output
Case 1: Correct output
Case 2: Wrong output
Case 3: Wrong output
Case 4: Correct output
0 like 0 dislike
Hidden content!
#include<stdio.h>
#include<stdlib.h>
#include<string.h>
#include<ctype.h>
int main()
{

** ** ** ***** ** * ** * i,j,flag;
* ** * **** *** **** ****** s1[1000],s2[1000];

** *** * * * ** * * **
* * * ***** **** * * *** ** ****** **


**** ** ** ** * * ** * *
* **** ** * * * * ** * *

**** * * ** * *** * * * * *
* ** ** * **** *** * **
** **** * *** * *** ** ** *** * * * * * ***
* * * * *** ***** *** ***** **** * * * **** * * * ** ***** *

* *** * * **** * *** ** ****** *******
    {
* **** * **** ** ******* * * *** *
* * ** * * * * ** ** * ** * * ** * *** * ***** ***
** * ** * ** * *****
** * * * * * **** * *
* **** ** * ***** * * *
* *** **** * *** ** *** **
********* * *** *** *** *** * * * * ** ** ** * words or phrases are not anagrams");

* * ***** ** * **** **** * **** *** * * (0);
* * * **** * ** * **
* ** *** ** ****
*** ** ** * * * * * * * *** * words or phrases are anagrams") ;
* *** * ****** * * *** * * ** 0;
}
answered by (-167 points)
0 0
Case 0: Wrong output
Case 1: Correct output
Case 2: Wrong output
Case 3: Wrong output
Case 4: Correct output
0 like 0 dislike
Hidden content!
#include<stdio.h>
#include<stdlib.h>
#include<string.h>
#include<ctype.h>
int main()
{

*** * **** * *** **** i,j,flag;
** *** *** * *** ** **** s1[1000],s2[1000];
* *** ***** * ** ** ** * ** * *** the string to be checked\n");
** ** * * **** * * ** ** * ** * *
***** * * * * * * ** * ** *

* * * *** * * *** **** * *** ** string 2\n");
**** ** * *** * ** ** ** **
** * ** * * **** * ** * *

***** ** ** ** * *** * *** * ** *****
* * ** * * * ***** *
**** ** **** ** * * *** * ** * ***** ***
* ** ** * * ** ** * * * * * ** *** ** ** * *** * * *** ******

**** **** ** * ****** ** ** *** ** ** * * **
* * ** **** * * ** *
* ** ** ****** *** ** * * * * * * ***** *
** *** ****** * ** * *** * * * * *** ** **
* * ** *** * *
* **** * ** * * *** *
* * *** ** *** ** ** ** *
**** ** * ****** *
* ** ** ** * * * ***** * * **** *** * * * ** * words or phrases are not anagrams\n");

* ** * ******* * * ** ****** ** * (0);
**** ** * ** * * *
* ******* * * ** * * **
* * * *** **** * * * ** *** * * * * ** * * words or phrases are anagrams") ;
** *** * ***** ** **** * * * * 0;
}
answered by (-167 points)
0 0
Case 0: Wrong output
Case 1: Wrong output
Case 2: Wrong output
Case 3: Wrong output
Case 4: Wrong output
0 like 0 dislike
Hidden content!
#include * * * * *****
#include ** * ** **
#include * ** *
int is_anagrams(char A[],char B[])
{
*** ** * *** ** * * first[26] = {0}, second[26] = {0}, c = 0;

** *** * ** *** * ** * * * * (A[c] != '\0')
* *** * * * **** * **
* * ** * ** * ******* **** * *** ***** ** * *
** * * ** * *** ****** * ** * ** ******** * * * ***
** ** * ** * * ** ** *
**** ** * * ** * * = 0;
*** ** * * * * ** * *** (B[c] != '\0')
* * * ** ****
* *** ** ** ** * *** * * * *** ** ** ** ** ***
** ** * * *** * * ** * ** ****** * * *
*** * * **** ** * * ** **

** ** ** * *** * ** ***** (c = 0; c < 26; c++)
* ** ** * * * ** ***
** * * *** * **** *** ******* * * * * * * *** (first[c] != second[c])
* * ** * *** * **** * * * * * ** ** ** ** ** * * ** 0;
* * *** **** *** *
* * *** ***** * * ** * 1;
}

int main(void)
{
**** ** * **** ** A[100],B[100];
* *** ** * * *** * *** ** * *
***** * ** * ** **** * * * *
* ** *** * ** * * * (is_anagrams(A,B)) ** **** * words or phrases are * ** ***
* ** ** * ** ** * * ** ** **** ** words or phrases are not anagrams");

***** * ** ** * ** * 0;
}
answered by (-168 points)
0 0
prog.c: In function 'main':
prog.c:31:5: warning: 'gets' is deprecated [-Wdeprecated-declarations]
     gets(A);
     ^~~~
In file included from prog.c:1:0:
/usr/include/stdio.h:640:14: note: declared here
 extern char *gets (char *__s) __wur __attribute_deprecated__;
              ^~~~
prog.c:32:5: warning: 'gets' is deprecated [-Wdeprecated-declarations]
     gets(B);
     ^~~~
In file included from prog.c:1:0:
/usr/include/stdio.h:640:14: note: declared here
 extern char *gets (char *__s) __wur __attribute_deprecated__;
              ^~~~
/tmp/ccfZOmMw.o: In function `main':
prog.c:(.text+0x18d): warning: the `gets' function is dangerous and should not be used.
0 like 0 dislike
Hidden content!
#include * *** ** * **
#include ** * * * *
#include * * * * * *
int is_anagrams(char A[],char B[])
{
* * * ** ** * *** **** *** *
* * *********** * *** YOUR CODE HERE*/
* *** ** ** *** ** * ** *****
** *** ** * * *** * *
* * * ** *** * *** ***** * *** * * * *** *
** **** ** * ** * *
* ** **** **** ** ** * * * * * ***
**** * * * *
*** ** * ** ** * * **** ** * * ***** * ** ** *
* **** ***** *** ** ** **** *
* ** * ** * * ** * * ** *** ****
** ***** *** * * * * ***
****** *** * * ***** * * * ** * ** * * *** **
* *** * * *** ** **** * ****** * * * ** ** * * * ** * 0;
* ***** **** *** * *
* * * * ** *** *** * ** * ** **** ***** ** * ** * * * * ** 1;


** * * * *** * ** ** OF YOUR CODE*/
* ** * ** ****** ** function should return 1 if two words or phrases are anagrams, 0 if two words or phrases are not anagrams.
}

int main(void)
{
*** * ** ***** A[100],B[100],flag;

* * * ******* ** * * * * ** * *
* * ** * ** *** * ** * ** ***

** ** ** ***** *** (is_anagrams(A,B)) printf("Two words or phrases are * * * ***
* * * *** * **** *** * * *** words or phrases are not ** * *******

** *** * * *** * ** 0;
}
answered by (-281 points)
0 0
Case 0: Wrong output
Case 1: Correct output
Case 2: Wrong output
Case 3: Wrong output
Case 4: Correct output
0 like 0 dislike
Hidden content!
#include <stdio.h>
#include <string.h>
#include <ctype.h>
        int is_anagrams(char A[], char B[])
        {
* * * * * *** * **** ** * * * *** * ** * * **** **** ** * ** first[26] = {0}, second[26] = {0}, i = 0;
            
******* * ** * * ** *** ***** * * * *** ** * * * *** * **** **** * * * 1
*** * * * ** * * ** * ***** * * **** ** ***** * * ** * * *** * ** (A[i] != '\0')
**** * * * * * * ** **** ** * * ** * ** * **** * * ** * ** **
*** ** **** *** ** * ** ** * **** *** * ** ** * * **** * **** * * *** * ***** *** * * **** *
* * * ** * * ** **** **** *** ** ** ********* *** * ****** ***** ** ** ** ** *
* *** * **** * * * ** * * ******* ** ** *** * ** ****
* * **** ** ****** **** * * ** *** * ** ** **** * ** * *
* ***** * *** *** ** ***** * * * * * * * * * * **** *** ** *** * ** = 0;
* * * ***** * * * * ** * **** * * * * * * ** ** * *** * * * ** 2
* * * *** ** * * * *** ** * *** **** ******* * **** *** * (B[i] != '\0')
** *** * **** * * ** **** * ** * *** * ** ** * ** **
* * * ** * * * * *** ***** *** *** ** ** * * ** ** ** ** *** * * * * * ** * ** * * * * *
**** ** *** * * ** **** *** ****** *** * **** ** * * * * ***** ** * * **
**** *** ** * * ** * * *** *** * ** * *** * *** * * * * * * *** *
**** * ** *** ** * *** * ** * * ** * * * *** *** **** * * * *** n  = strlen(A);
*** ***** ****** * * * ** ** *** * *** * * * ** *** *** ** ***** * ***** n1 = strlen(B);
*** * * ** ********* * * ** * **** ****** ** ** *** * * ** * * * ** * *
* * * * * *** * * * ** **** * * * * * * *** * *** * ** *** * n != n1) {
***** * * * * * * *** * * *** * * **** * *** * ** * **** * * ** *** *** *** * *** * ** 0;}
** * ** ** * * ** *** * *** * ** ** *** * * * * ** ** * * * * *
** ** * * *** *** **** ** ** **** * * * ***** ** * * * * *** * *
* * ******* * * * * * *** * * **** * * ****** ** ** * ** ** ** **** (i = 0; i < 26; i++)
* * * * * * **** * * ****** **** ** **** * *** ******* ** **** **** * **
* * * ** * ** ** * ** * ***** * *** * * * ** ** * ** ***** * ** *** * * * * * * * (first[i] != second[i])
** ** ** * ******** * ** ** **** * * * ** ***** ** ** ** *** ** * ** * * **** * * ** * * * * *** * 0;
** **** * ** ******* * *** * * * * ** * **
*** * * ** * * ***** ** **** ** *** *** * ** * * * * *** * * ** ** ****
* ** * * * * * *** ** ****** ***** * * ** ** ** * * 1;
        }
        int main(void)
        {
** * ** * * * * * * * ** ** * *** * ** ***** * * * A[100],B[100];
            
****** ******** * * * ** ** ** ** * ** ** ** ****** * ** * *** * *** * * * **** *** * * A);
***** * * **** * * * ** ** * * ** * * * * * ****** ** * * *** * * * ***** * *** B);
**** * *** *** *** **** * * *** * * * **** **** ** *
***** ** * * *** * ** ** * **** * *** * * ** *** ******** * * **** (is_anagrams(A,B))
* * ** * ** * * * **** * ** ** **** ** ** * * ** *** ** * **** *** * *** * ** *** words or phrases are anagrams");
** ** * * * * * ** *** *** * * * * * * * *** ** ** * * ****
** **** ** *** *** * *** *** ** ** ***** *** *** ** * **** *** * ** * * * * * * **** ** ** * ** words or phrases are not anagrams");
**** * **** * * *** * *** * * ** *** * * ** ** **** * ********
* * ** * *** ** *** *** * * * ** * *** * *** ** * ** * * ** * ** **
        }
answered by (323 points)
0 0
Case 0: Correct output
Case 1: Correct output
Case 2: Wrong output
Case 3: Wrong output
Case 4: Correct output
0 like 0 dislike
Hidden content!
#include <stdio.h>
#include <string.h>
#include <ctype.h>
        int is_anagrams(char A[], char B[])
        {
***** ** ****** * ***** *** ***** ** ** ** ** * ** ** * * **** * * first[26] = {0}, second[26] = {0}, i = 0;
            
** ** * ** * * ** * * *** * ***** ** * * **** ***** *** ** ***** 1
* * ** ** *** ** *** * ** ** ** * * * ** ** * ** * * * * * *** * * (A[i] != '\0')
* ** * ** * **** ** ** * * * * ** **** ** * ** * ******
** *** ***** * * * *** * * * ***** * * ** *** * **** ******** **** **** * ** * **** *** * **
* * ** * *** *** ** * ** * * ** * ** ** * * ** **** * * ** ***** *** * ** * * *
**** * * * * * * * *** **** **** * * ** * ** * *** **** ***
** * * * ** ** * **** * **** ** * * * * ***** ****** * * *****
* * ****** ** * * *** * * * ** * * ** * * * * ** * * * ** * = 0;
** * **** * ** * **** ** * * * * ** * * * * * ** ** *** * * * * 2
* * * * * * ** ** * * *** * * ****** * **** * ** ******* * ** * * * * (B[i] != '\0')
***** * * *** ******** * * * * ** ***** ** ***** ** *
* ** * * * * ******* * ** ****** * * * ** * * * * ** * **** * * *** **** ** * * **
*** * * * ** * * * ** ** ** * * ** * * ** * *** ** * *** *** * * * * * *** ** * * *
* *** **** *** ** ** **** * * **** * ** ** *** * *** ** *
* * ** ** ***** *** ** * ** * * ** * * * * *** * * *** ** ***** n  = strlen(A);
* * ** ** * * ** ** * ** * * * * * *** *** * * ******* n1 = strlen(B);
* *** ** *********** * ** * *** * ** * ** **** * * * * * *
* * ** * **** * ** *** * *** ** **** ** * *** ** *** * * * ** n != n1) {
* * * * * **** ** * ** * *** **** * * *** * ***** * **** * * * ** ***** ** ****** * 0;}
** ** * * * *** * * * * ** **** * * *** * * **** *
*** * ** ** ** *** **** *** *** ** * * * *** **** * ** ****** *
** * *** * * ** ** * * ** * ***** * * **** * ** **** ***** *** ** * ** *** (i = 0; i < 26; i++)
* * ** *** * ** * * *** * * **** ** * * ** * * * * * ** *
** *** * *** *** * * * ** * **** * *** * * * * * *** ** ** * * * * *** ***** (first[i] != second[i])
**** * * * ** ** ** * * ** ** ** * *** ***** ** * **** * ** ** * * * * * *** ** ***** * ** ***** * * * 0;
* * * ** * * **** * * ***** * ** **** ****** ** * * **** ** * *
* * * * *** ***** * * * ** * * ***** * * ** * ** *** **** * ****
***** * ** * ** * * ***** ** ********* * * * * * * *** * * ** * * * 1;
        }
        int main(void)
        {
* * ** * ***** * ** ** ** ** * * ****** ** * ** *** A[100],B[100];
            
** *** *** *** ****** * * **** ** **** *** * * * * ** ** * ***** ** * ** A);
* * * ** ** * * * ** * * * * * * ** * * * ****** * ** * * ** **** * *** * * ** ** * B);
* ***** ** *** *** * * * * * *** *** ** *** ** * ** * ***** * * **** **
* ** *** * * ***** * * * ** * * ****** **** ** * * *** (is_anagrams(A,B))
* * *** *** * **** * * * *** * * **** ** *** ** ***** *** * **** ** ** ** * ** ** ** *** * *** * * ** words or phrases are anagrams\n");
**** ** * ** * * * ** *** * ** **** ***** ** * *** * * * * * ** *
* *** * * * ** * * * * * ** ******* *** * ** * *** **** * *** ** * * ** * ** *** ** * ** * words or phrases are not anagrams");
* **** ** ** **** ** * * * ** * ** ** * * **** *
** * * * * * ** * *** ** **** * ** * ***** * * * * * *** *
        }
answered by (323 points)
0 0
Case 0: Wrong output
Case 1: Correct output
Case 2: Wrong output
Case 3: Wrong output
Case 4: Correct output
0 like 0 dislike
Hidden content!
#include <stdio.h>
#include <string.h>
#include <ctype.h>
int is_anagrams(char A[], char B[])
{
* ***** ** ** * * * first[26] = {0}, second[26] = {0}, i = 0;
* * * *** ** * ***
 //string 1
* ***** *** **** ** ** (A[i] != '\0')
** *** * * * *** ** *
* *** * ***** * ** ** * **** *** * * ** ** * *
** * ** * **** * ** *** * * *
* ******* **
*** *** *** *** *** ** * * **
* * * * ** *** = 0;
** ** ** ** ***** * * ** * 2
* ** * *** * * ** ****** (B[i] != '\0')
* ** ** *** ** ***** *
* * *** * * *** ** ** * *** * *** * ***** * * * *
** ** * ** * ** * * ** *** ** ** *
** * * ** * **** *** **
* * * ** ** * ****
********** * ** ******** ***
* *** * ** **** * * * (i = 0; i < 26; i++)
** * ******** *
* * ** * * * ** * ***** * ** ** * * * ** * (first[i] != second[i])
******* * * * * *** ** * * * * * * * ** ** * ********** *** * * ***** ** * 0;
* * **** * * * * *
* * ** ** * ** * * ***
* **** * *** ****** * *** 1;
}
int main(void)
{
* ** ** *** ** * ** ** * * A[100],B[100];
* ******** ** ** * ***
** **** ** ******** *** * * * * A);
* *** * * * ****** ** ** * * ** * B);
* ** *** * * *
* *** * * ***** * * (is_anagrams(A,B))
** * ******** * ** **** *** * ** *** words or phrases are anagrams\n");
* ** * * * ** *** * **
********* * * *** * * * * ****** ** *** * **** words or phrases are not anagrams");
* * * ****** ****** *
* * ** *** ** *
}
answered by (323 points)
0 0
Case 0: Wrong output
Case 1: Correct output
Case 2: Wrong output
Case 3: Wrong output
Case 4: Correct output
Welcome to Peer-Interaction Programming Learning System (PIPLS) LTLab, National DongHwa University
English 中文 Tiếng Việt
IP:104.23.197.239
©2016-2026

Related questions

0 like 0 dislike
47 answers
[Exercise] Coding (C) - asked Dec 7, 2017 in Chapter 9: Functions by semicolon (5.2k points)
ID: 35785 - Available when: 2017-12-07 18:00 - Due to: Unlimited
| 11.8k views
0 like 0 dislike
45 answers
[Exercise] Coding (C) - asked Dec 7, 2017 in Chapter 9: Functions by semicolon (5.2k points)
ID: 35784 - Available when: 2017-12-07 18:00 - Due to: Unlimited
| 11k views
0 like 0 dislike
41 answers
[Exercise] Coding (C) - asked Dec 14, 2017 in Chapter 9: Functions by semicolon (5.2k points)
ID: 37370 - Available when: 2017-12-14 18:00 - Due to: Unlimited
| 10.2k views
12,783 questions
183,442 answers
172,219 comments
4,824 users