1answer.
Ask question
Login Signup
Ask question
All categories
  • English
  • Mathematics
  • Social Studies
  • Business
  • History
  • Health
  • Geography
  • Biology
  • Physics
  • Chemistry
  • Computers and Technology
  • Arts
  • World Languages
  • Spanish
  • French
  • German
  • Advanced Placement (AP)
  • SAT
  • Medicine
  • Law
  • Engineering
Soloha48 [4]
4 years ago
14

Write a function that checks whether two words are anagrams. Two words are anagrams if they contain the same letters. For exampl

e, silent and listen are anagrams. The header of the function is: def isAnagram(s1, s2): (Hint: Obtain two lists for the two strings. Sort the lists and check if two lists are identical.)
Computers and Technology
1 answer:
marysya [2.9K]4 years ago
7 0

<u>C++ program for the checking if 2 strings are anagram :- </u>

#include<bits/stdc++.h>

using namespace std;

void isAnagram(string s1,string s2) //defining function

{

int an1[256]={},an2[256]={};//declare two count arrays of size 256 an1 and an2.

bool test=true;//taking a bool variable test = true for displaying the result..

for(int i=0;s1[i]&s2[i];i++) // iterating over both the strings.

{

an1[s1[i]]++;//increasing the count of the characters as per their ascii values in count array an1.

an2[s2[i]]++;//increasing the count of the characters as per their ascii values in count array an2.

}

for(int i=0;i<256;i++)//iterating over the count arrays..

{

if(an1[i]!=an2[i])//condition for not anagram.

{

cout<<"not an anagram"<<endl;

test=false;//making test false..

break;//coming out of the loop.

}

}

if(test)//if test is true only then printing..

cout<<"is an anagram"<<endl;

}

int main()

{

string s1,s2;//declaring two strings.

cout<<"Enter both the strings"<<endl;

cin>>s1>>s2;//prompting the strings..

if(s1.length()==s2.length()) //checking whether the lengths of string is same or not

isAnagram(s1,s2); //calling function

else

cout<<"not an anagram"<<endl;

return 0;

}

<u>Explanation</u>

A string is said to be an anagram string of other string if it has same characters but in different order or exactly the same.

for example:-  

string 1="silent"  

string 2="listen"

string 2 is an anagram of string 1.

void isAnagram(string s1,string s2) - This is the function having name isAnagram of void return type having parameters s1 and s2.

You might be interested in
Write a program to print "I love to program" to the screen 2 times. Edhesive​
Anon25 [30]

Answer:

It matters what programming language you are using. It would be something like this:

print("I love to program");

print("I love to program");

(written in modified javascript)

6 0
3 years ago
2. Name the layer of the Web/Internet Protocol Stack with which each of these functions is associated.
Nadya [2.5K]

Answer:

a. Encrypt a message - Application layer

b. Prevent buffer overruns - Transport Layer

c. Choose the best route for a data packet - Network Layer

d. Compose an email message - Application layer

Explanation:

3 0
3 years ago
Read 2 more answers
_______ is the type of vision useful in sensing motion and objects outside normal vision.
Likurg_2 [28]

The answer is peripheral vision, also known as side vision.

3 0
3 years ago
EDVAC stands for? on which theory it is made on?
almond37 [142]

Answer:EDVAC (Electronic Discrete Variable Automatic Computer)

foi um dos primeiros computadores eletrônicos. Ao contrário do ENIAC que operava com base em codificação decimal, o EDVAC foi projetado para utilizar códigos binários e manter os programas armazenados na memória, respeitando a arquitetura de vo n Neumann.

Explanation:

6 0
3 years ago
Write a class named Add that has the following data members, constructor, and methods:
taurus [48]

Answer:

A class is like a blueprint of object.

Explanation:

A class defines the kinds of data and the functionality their objects will have.

A class enables you to create your own custom types by grouping together variables of other types, methods and events.

In C#, we can create a class  using the class keyword.

Here's a sample program:

using System;

namespace ConsoleApplication

{

   public class Test

   {

       public static void Main()

       {

           Add a1 = new Add(70, 50);

           a1.AddNumbers();                    

           Console.ReadLine();

       }      

   }

     class Add

   {

       private int row;

       private int column;

       public Add(int r, int c)

       {

           row = r;

           column = c;

       }

       public void AddNumbers()

       {

           Console.WriteLine(row+column);

       }

   }

}

output: 120

Explanation of the program:

I have created a class named Add. Within a class, row and column are two fields and AddNumbers() is a method. We also have constructor to initialize row and column.

In main method, If I need to invoke members of the class, I must create  an instance of the class. We can create any number of instances using the single class.IN our program, a1 is the reference variable using which we can invoke members of the class. I invoked function in the class and passed arguments to the constructor while creating an instance.

Those values are assigned to method variables and it operated the addition. Thus the output is 120.

7 0
3 years ago
Other questions:
  • Why is it important for people to express resentments in the workplace?
    9·1 answer
  • The term _____ refers to computers that are among the fastest of any in the world at the time of their introduction.
    6·1 answer
  • If the force of gravity _ then the weight of an object will _
    8·2 answers
  • You are interested in buying a laptop computer. Your list of considerations include the computer's speed in processing data, its
    15·1 answer
  • Which THREE devices can perform both input and output operations?
    8·2 answers
  • How 0x86 processor store 0x12345678 in memory ​
    13·1 answer
  • What will happen when you run this program?
    12·2 answers
  • How are status reports useful
    6·1 answer
  • The /home/gshant/smp directory contains several files. The directory and files need to be removed. The current working directory
    13·1 answer
  • Which 2 tools are useful to remote employees and coworkers.
    10·1 answer
Add answer
Login
Not registered? Fast signup
Signup
Login Signup
Ask question!