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
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.
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
algorithmdivs

algorithmdivs

  • 1.
    Q1 Write a programto 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..Calculatethe 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 ofa 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