The document contains algorithms for various problems:
1. Finding the greatest number in a sequence without using additional data structures.
2. Calculating the difference between the sum of squares and the square of sums of two numbers.
3. Calculating ticket sales, costs, and profits for a theater given the number of attendees.
4. Calculating the surface area and volume of a cylinder given its radius and height.
5. Counting the number of words in a string.
6. Converting a decimal number to its binary equivalent.
7. Calculating the factorial of a number recursively.
8. Reversing an integer array without using an additional array.
9. Concatenating two
Control flow statements!
This is probably one of my favorite topics. All computer languages have instructions and the order and pathways by which these instructions are executed are called control flow.
The following bullet points are methods that can be used to control flow in a programming language:
• If Statement
• Else Statement
• Else If Statement
• Switch
• Loops
• Repeat Loops
• While Loop
• For Loop
• Loop-control Statements
• Break Statement
• Next Statement
I’ve created a very basic while loop that you can try out for yourself by copying the text into your R script. A while loop can be thought of as a repeating if-statement. It repeats a code based on a Boolean condition. So while(x <50) { print(X)} can be interpreted in plain English as “ print X until X exceeds 50” While loops may run ad infinitum if you don’t control them properly with break statements
Control flow statements!
This is probably one of my favorite topics. All computer languages have instructions and the order and pathways by which these instructions are executed are called control flow.
The following bullet points are methods that can be used to control flow in a programming language:
• If Statement
• Else Statement
• Else If Statement
• Switch
• Loops
• Repeat Loops
• While Loop
• For Loop
• Loop-control Statements
• Break Statement
• Next Statement
I’ve created a very basic while loop that you can try out for yourself by copying the text into your R script. A while loop can be thought of as a repeating if-statement. It repeats a code based on a Boolean condition. So while(x <50) { print(X)} can be interpreted in plain English as “ print X until X exceeds 50” While loops may run ad infinitum if you don’t control them properly with break statements
Fibonacci series c++ - This code is very simple and easy simply add two previous terms and get next term. Example of Fibonacci series is; 0 1 1 2 3 5 8 13.....
https://www.sitesbay.com/cpp-program/cpp-fibonacci-series-program
Traversal means visiting all the nodes of a graph. Breadth first traversal or Breadth first Search is a recursive algorithm for searching all the vertices of a graph or tree data structure. In this article, you will learn with the help of examples the BFS algorithm, BFS pseudocode and the code of the breadth first search algorithm with implementation in C, programs.
Digital systems:
Design of a Burglar Alarm using Simple Combinational Logic.
FPGA design verified on BASYS experimenter board utilizing Verilog programming language in Xilinx design suite.
The objective of the Level 5 Diploma in Information Technology is to provide learners with an excellent foundation for a career in a range of organisations. It designed to ensure that each learner is ‘business ready’: a confident, independent thinker with a detailed knowledge of Information Technology, and equipped with the skills to adapt rapidly to change.
Fibonacci series c++ - This code is very simple and easy simply add two previous terms and get next term. Example of Fibonacci series is; 0 1 1 2 3 5 8 13.....
https://www.sitesbay.com/cpp-program/cpp-fibonacci-series-program
Traversal means visiting all the nodes of a graph. Breadth first traversal or Breadth first Search is a recursive algorithm for searching all the vertices of a graph or tree data structure. In this article, you will learn with the help of examples the BFS algorithm, BFS pseudocode and the code of the breadth first search algorithm with implementation in C, programs.
Digital systems:
Design of a Burglar Alarm using Simple Combinational Logic.
FPGA design verified on BASYS experimenter board utilizing Verilog programming language in Xilinx design suite.
The objective of the Level 5 Diploma in Information Technology is to provide learners with an excellent foundation for a career in a range of organisations. It designed to ensure that each learner is ‘business ready’: a confident, independent thinker with a detailed knowledge of Information Technology, and equipped with the skills to adapt rapidly to change.
The Ring programming language version 1.3 book - Part 85 of 88
algorithmdivs
1. Q1
Write a program to find GreatNum from a series of numbers
1.Contract: GreatNum number,numbers ........>number
2.Header: GreatNum(nOfvalues(sequenceOf numbers))...
3.Example GreatNum(3,(23 45 56))-------> 56
4. ALGORITHM
STEP1.Start
STEP2.Declare 'nOfvalues' to get the no of sequence of numbers.Declare Maxval=0
STEP3.Read the sequence of numbers and store the numbers.
STEP4.Check sequence, If a number > Maxval ,then save Maxval as that number
STEP5.Check next number in sequence ,if number >Maxval,then save Maxval as that number
STEP6.Repeat steps 4 to 5 until last of sequence.
STEP7.Display Maxval.
STEP8.Stop.
Sl.NoInputOutput13, 23 45 565624, 10 45 67 3267
Q2.
Sum of squares and square of sums of 2 nos and find diff
1.Contract:calcDiffnce number,number------>number
2.Header: calcDiffnce(nuM1,nuM2)....
3.Example calcDiffnce (4,5)----->40
4.ALGORITHM
STEP1.Start.
STEP2.Declare variables nuM1 and nuM2 and read and store the values.
STEP3.Declare SumoFsqr ,SqroFsum and Diff and initialise to 0.
STEP4. SumoFsqr = (nuM1*nuM1)+(nuM2*nuM2)
STEP5.SqroFsum =(nuM1+nuM2)* (nuM1+nuM2)
STEP6.Diff= SqroFsum - SumoFsqr
STEP7.Display Diff
Sl.NoInputOutput14,540210,12240
Q3
Write a program TheaterProfit(noFattendees) to calculate the calcSales,calcCost and NetProfit
1.Contract: TheaterProfit numbers----->numbers
2.Header:TheaterProfit(noFattendees))...
3.Example TheaterProfit(200)------->880
4.ALGORITHM
STEP1:Start
STEP2. Declare variable 'nOfattendees' and initialise to 0 to save no of attending people show.
STEP3.Input the value for nOfattendees and save.Declare and initialise Ticktprice= 50,SetCost=20,AtndCost=0.5.
STEP4.Declare variables 'calcSales' for calculating cost of ticket sales and 'calcCost' for calculating cost of show.
STEP5.calcSales=nOfattendees * Ticktprice
2. STEP6.calcCost=SetCost+ nOfattendees* AtndCost
STEP7..Calculate the NetProfit= calcSales- calcCost and display NetProfit.
STEP8 Stop.
Sl.NoInputOutput1104752251217.5
Q4.area and volume of cylinder,given base radius and height
1.Contract: calcAreaVolcyl number,number----->number,number
2.Header: calcAreaVolcyl (baseradius,height)
3.Example calcAreaVolcyl(12,13.5)------>( 1921.68,6104.16)
4.ALGORITHM
STEP1:Start
STEP2:DEFINE PI as 3.14
STEP3:Declare variables baseradius and height of the cylinder and read the values.
STEP3:Declare cylSArea and cylVolume and initialise 0.
STEP4:cylSArea=(2*PI* baseradius* height)+(2*PI* baseradius*baseradius)
STEP5: cylSArea=( PI*baseradius*baseradius*height)
STEP6:Display cylSArea and cylVolume
STEP7:Stop
Sl.NoInputsOutputs16,5414.48,565.224,10351.68,502.4
Q5.To count no of words in a string
1. Contract countWords string.-------->number
2.Header :countWords(strng,countVal)....
3.Example countWords( 滴 ave a nice day----->12
4.ALGORITHM
STEP1:Start
STEP2:Declare a string variable as array of characters strng[] and read from user and store string .
STEP3:Declare and Initialise countVal=0.
STEP4:Read string.Check each character strng[i], IF character equals ' ' and next character is not ' ' ,THEN increment
countVal.
STEP5:If character equals 'null' then increment countVal .
STEP6:Repeat step3 to 4 ,until encounter 'null' character.
STEP7:Display countVal
STEP8:Stop
Sl.NoInputOutput1Have a nice Day42I like chocolates and cream5
Q6.Convert decimal to binary value
1.Contract DecToBin number ----->number8)
2.Header DecToBin(decno)....
3.Example DecToBin(25)----->11001
4.ALGORITHM
STEP1:Start
STEP2:Declare variable decno and read decno from user.
STEP3:Declare variables quotnt and rem and initialise as 0.Declare and initialise a variable count as 0.
STEP4:quotnt equals to decno/2 and rem equals to decno%2
STEP5:rem is 0 or 1.Store rem as first element of an array arrno[].increment count .save new decno =quotnt.
STEP6:Repeat steps 4 and 5 until decno reduces to 0.Store rem as next element of array.
STEP7:Print the arrno[] backwards from arrno[count-1] ,as the Binary value.
3. STEP8:Stop
SL.NoInputsOutputs125110012121100
Q7 Factorial of a number using recursive function.
1.Contract FACT number---->number
2.Header FACT(number)
3.Example FACT(8)-------->40320
4.ALGORITHM
STEP1:Start
STEP2:Declare variables num ,fact and i.Initialise fact=1 and i=1
STEP3:Read the required number from user and store as num.
STEP4:Update fact as fact*i.
STEP4:Increment i
STEP5:Repeat steps 4 and 5 until i less than or equals num
STEP6:Display fact
STEP7:Stop
Sl.No InputOutput184032025120
Q8 Print Reverse an integer array without using another array
1.Contract RevArray(number,numbers)-------->numbers
2.Header RevArray(number,numbers)
3.Example RevArray( 7,2 34 67 8 98 31 56)-------->(56 31 98 8 67 34 2)
4.ALGORITHM
STEP1:Declare array arr[]and no of elements LEN.
STEP2:Input no of elements from user and read and store arr[LEN]
STEP3:Initialise i=0.Initialise temp as 0
STEP4:Put temp=arr[i].Then put arr[i] =arr[LEN-i]
STEP5:Put arr[LEN-i]=temp.Increment i
STEP6:Repeat steps 4 and 5 until i is less than or equals LEN/2
STEP7:Display arr[i]
STEP8:Stop
Sl.NoInputOutput15, 12 56 7 0 4545 0 7 56 1228,1 43 88 76 44 3 32 99 32 3 44 76 88 43 1
Q9.To concatinate two strings string1 and string2.
1. Contract : ConcatStr(string, string)--------->string
2.Header ConcatStr(string,string)
3.Example ConcatStr(Housing,Plot)---------->HousingPlot
4.ALGORITHM
STEP1:Declare str1 and str2 as two string arrays
STEP2:Read str1 and str2 from the user and store.
STEP3:Print str1[i] increment I
STEP4:Repeat 3 while str[i] is not equal to 'null '.
STEP5:When str1[i] is 'null' do step 5
STEP5:Print str2[i] .Increment i
STEP6:Repeat 5 until str2[i] equals 'null'.
STEP7:Stop