Q&A for How to Write an Algorithm in Programming Language

Return to Full Article

Search
Add New Question
  • Question
    How do I plan or map out an algorithm process?
    Tyrone Showers
    Technologist
    Tyrone Showers is a Technologist and the Co-owner of Taliferro Group, an IT consulting company based in Seattle, Washington. With over 35 years of professional experience, he specializes in API Design, e-Commerce, Operational Efficiency, and website development. He has a B.S. in Computer Science from DeVry Institute of Technology.
    Technologist
    Expert Answer
    Lay the groundwork first, learn some of the common algorithms, and understand what they do and what they're attempting to do. Bayes is one of my favorite algorithms. I build on this in my code to develop software agents that pick up new skills depending on previous behavior.
  • Question
    How do I write an algorithm that 7 is greater than 5?
    nicholasz2510 Gaming, Travel, and Music
    Community Answer
    The syntax can vary over different languages, but to write the conditional 7 is greater than 5 would most likely by simply be this: 7 > 5.
  • Question
    How do I make an algorithm of the sum of two numbers?
    Adam Blalock
    Community Answer
    To add two numbers in a programming language, you just use a "+" between them. In Python (a programming language), it would look like: x = 10, y = 13; print x + y.
  • Question
    Is there any way to understand this easier? I'm 15 and still trying to understand the concepts.
    Community Answer
    I just started programming and my college professors are very vague and make understanding the concepts pretty hard. Your best bet is to keep looking up the terms on Google, that's what I've been doing, and it works to a degree.
  • Question
    What's the difference between algorithm and pseudocode?
    Chukwu Chinaza Esther
    Community Answer
    An algorithm is a step-by-step procedure to solve a given problem, while a pseudocode is a method of writing an algorithm.
  • Question
    How do I write an algorithm of a switch-case program?
    Gilang Aulia Muhamad
    Community Answer
    switch (expression) { case x: /* do something if expression equals x */ break; case y: /* do something if expression equals y */ break; default /* set default action when nothing equals the case */ }
  • Question
    Write an algorithm to accept the cost price of one product and quantity. Calculate the total and charge 2% discount on total cost.
    Community Answer
    You did not specify the language, but this is how you would generally do it: 1. Cost Price * Quantity * (2/100).
  • Question
    How can algorithms help in life?
    Freddy Chavez
    Community Answer
    An algorithm can do specific tasks for you and in that way save time. For example, if you have a task to count some repetitive numbers each day, you can write an algorithm that will do that for you. Or perhaps you need to create a GPS system that can route you to a destination. No one wishes to do this manually, thus an algorithm will use all the data and automatically create a route for you to use.
  • Question
    How to write an algorithm to determine grades of students with their score?
    Community Answer
    You can write these types of algorithms in many programming languages. The easiest one is JavaScript. In order to make this algorithm, you must add all the numbers (student's score) and next divided by the number of all the subjects. For example if there are 3 subjects, P.E. English and I.T. and the student scored 19 20 20 (these are random numbers) you must add them (19 +20 +20) and next divide them by the total number of the subjects (59 ÷ 3). Copy paste the algorithm: Console.log(insert here student's scores. Add then using the + symbol and next divide them with the / symbol) for example it may look something like this Console.log(20 + 20 + 20 / 3) Run the program.
  • Question
    How do I write an algorithm for an irrigation system software?
    Daniel
    Community Answer
    To write code for your algorithm's ordered steps, you will need to know the necessary coding. "I don't know how to write an algorithm for[...]." indicates you don't know the coding necessary to write the algorithm. For example, suppose I wanted to write an algorithm that adds two numbers together. I would make a function that uses the addition operator for two numbers. Because I know the necessary coding, I could write an algorithm for adding numbers together. If you'd like to write an algorithm you don't know how to code, you need to educate yourself on the necessary coding. You may do so by specifying your algorithm and seeking guidance from experts, reading, learning by doing, etc.
  • Question
    I made an algorithm based on numbers. I'm thinking about converting it into a program. How?
    Daniel
    Community Answer
    You need to know how to make a program that perform the ordered steps of your algorithm. Try to find someone to guide you or learn programming on your own and make the algorithm into a program with the knowledge.
  • Question
    How do I write an algorithm for calculating the sum and product of two numbers?
    Daniel
    Community Answer
    You can use both respective arithmetic operations (addition and multipication) in a function. For example, let's say we wanted to find the sum and product of 5 and 10. For demonstration purposes, I'll use Python due to its syntax-friendliness. Algorithms are a collection of ordered steps; our two steps are to add and multiply two numbers. We would do that like so: x = 5 y = 10 print(x + y) print(x * y). This code returns: 15 50. Now we make "sumprodalgo" (shortened version of sum product algorithm) x = 5 y = 10 def sumprodalgo(): return x + y, x * y x, y = sumprodalgo() print(x) print(y). We also get the output of 15 and 50 using this.
  • Question
    How to write an algorithm to find out the smallest among three different numbers entered by user?
    Simeon Watson
    Community Answer
    In pseudocode: number1 = input number2 = input number3 = input if number1 < number 2: if number1 < number3: write "number 1 is the smallest" if number2 < number3: if number2 < number1: write "number 2 is the smallest" else: write "number 3 is the smallest"
  • Question
    What is creating algorithms and turning into codes is called?
    Simeon Watson
    Community Answer
    It is called programming, but the convertion from program you can read to machine code (0s and 1s) is called compiling.
  • Question
    What is the purpose of writing an algorithm?
    Stockriderj
    Community Answer
    The purpose of writing an algorithm is to tell a computer to do something. Not just that; it makes the code work. If there were no algorithms, coding would not exist, because algorithms are everywhere in programs. You just don't realize it.
  • Question
    How do I write an algorithm to find the difference of two numbers?
    Community Answer
    Depends on the programming language you are using. I would simply type "4-3" into a python interpreter and look at the result.
  • Question
    How do I write an algorithm to find the largest number of 2?
    Spenny Smith
    Community Answer
    This can be achieved very simply with a ternary operator in C, C++, and many other languages that support the feature, as such: int max(int a, int b) { return a > b ? a : b; }.
  • Question
    Is it possible for an algorithm to predict the probability of someone's choice?
    Community Answer
    Yes! Google does this all the time. The more you search from the same IP address, the more familiar your browser becomes with your personality. It does this by using many if statements. In other words, your browser gets a better picture of your online habits every time you use it.
  • Question
    What is a compiler? And the function of a compiler?
    Community Answer
    A compiler takes all the code you've written and "compiles" it (I know, not helpful) into a language that the hardware of your computer can understand. Then the computer runs that program. A compiler can be used to create an .exe file, which can be run on Windows without the language the program was originally written in being installed.
  • Question
    Which types of things should I do to create an algorithm that finds lost loved ones in refugee camps?
    Community Answer
    A database and function would suffice much easier. I wrote some basic example code in Python as an example it is as follows: print("Enter your name") str(input()) = name print("Enter your camp location") str(input()) = camp_location #the previous section creates variables that I can now store in a list name_and_camp_location = [name, camp_location] #this line stores the name and camp location in a list this is the end of my data base example def reunite(name) if name == 'example name' return 'example camp_location' #this is my basic example of a function that would be allowed to bring camp_location of loved ones in a large facility or other area if name and location is stored.
  • Question
    How do I develop an algorithm to input any number and print the first five multiples of it?
    Community Answer
    This isn't exactly an algorithm requiring question but, I will write you some example code that could achieve your goal. (example code is in python): print("Please enter a number!") int(input()) = num print(num*1 + " " + num*2 + " " + num*3 + " " + num*4 + " " + num*5)
  • Question
    What is an algorithm to find the average age of a group of 10 people?
    Community Answer
    Example code, hand written algorithm in Python print("please enter the age of ten people one by one, enter okay to continue") p1 = int(input(() print("next") p2 = int(input(() print("next") p3 = int(input(() print("next") p4 = int(input(() print("next") p5 = int(input(() print("next") p6 = int(input(() print("next") p7 = int(input(() print("next") p8 = int(input(() print("next") p9 = int(input(() print("next") p10 = int(input(() print("Ten people entered, group age is as follows " + (p1 + p2 + p3 + p4 + p5 + p6 + p7 + p8 + p9 + p10)/10) #you should probably manually enter this into idle, idle doesn't like copy pasting code.
  • Question
    What do I do to make a code that creates the phrase, "Hi, how are you?" on it's own?
    Community Answer
    Python is an easy code to use to make text. An example is: print: Hi,how are you? And then save the file and when opened, it will display that text.
  • Question
    What would I do to make a computer program give me the sum of two numbers automatically?
    Community Answer
    It depends if it the numbers are determined or the user inputs them. You create two variables, numberOne and numberTwo and simply just add them together numberOne+numberTwo.
  • Question
    How do I create an algorithm to add two fractions?
    Incognito sam
    Community Answer
    Consider two fractions, a/b and c/d. To add them, their denominators must be the same. To ensure a common denominator, we can multiply the denominators together to create a new denominator, in this case b*d. But, whatever we multiply the bottom of a fraction by, we must also multiply the top by. So, after completing these two operations, the fractions we are adding are now: (a*d)/(b*d) and (c*b)/(d*b). The result of adding these fractions is (a*d + c*b)/(d*b).
Ask a Question

      Return to Full Article