We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 12
Experiment 2
1. Algorithm: Arithmetic operations
step1 num1=input a number by the user Step2 num2= input a number by the user 1=add 2=subtract 3=multiply 4=divide Step3 If choice==1: Step4Printf(num1+num2) Step5 Elseif==2: Step6 Print(num1-num2) Step7 Elseif==3: Step8 Print(num1*num2) Step4 else==4: Print(num1/num2) Input: enter a number by the user num1,num2 Output: add, subtract multiply divide by the user 2. Find the given number is even or not Algorithm: start num1=input a number If(num1%==0): Print (“number is even”) Else: Print (“number is odd”) stop Input: input a number by user Output: even or odd 3. check the greatest number among 3 Algorithm: greatest number Step1 enter 3 numbers as the user num1 num 2 num 3 Step2 if num1>num2 Step3 check if num1> num3 Step3 if true Step4 print (“num1 is the greatest”) Step5 if false Print (“num2 is the greatest”) Step6 if num2>num1 Step7 check num2>num3 Step8 if true Step8 print(“num2 is the greatest”) Step9 if false Step10 print(“num3 is the greatest”) Input: num1 and num2 by the user Output: greatest among the 3 4. 5. algorithm: factorial of a number Step1 enter number by user num1 Step2 initialise i=1 and fact=1 Step3 if 1<=num1 Step4 fact=fact*i Step5 I=i+1 Step6 repeat step until 1<=fact Step7 else Step8 print fact Input: enter number by user Output: factorial will be calculated 6.Algorithm: compute a^b where a and b are supplied by the user Step1 let a be the variable and b the power Step2 consider variable pow and i Step3 read a as base and b as power Step4 repeat step until i<=b Step5 pow= pow*x and increase value of I by 1 Step6 print pow Input: number a and power b Output:power of a number 7.Algorithm to find the nth term of the arithmetic progression
Step1: Take first term a, common difference d, and n the
number of series. Step2: ap=a + (n-1)*d Step3: print ap Input: a n and d Output: value of nth term