0% found this document useful (0 votes)
3 views15 pages

AlgorithmQuestions (1)

The document outlines various algorithms for basic mathematical operations, including swapping numbers, calculating summation and average, finding the biggest number among two or three numbers, and determining if a number is positive, negative, odd, or even. It also includes algorithms for calculating the summation and average of n numbers, finding factorials, and checking for prime numbers. Each algorithm is accompanied by pseudocode for implementation.

Uploaded by

Noor Athirah
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
3 views15 pages

AlgorithmQuestions (1)

The document outlines various algorithms for basic mathematical operations, including swapping numbers, calculating summation and average, finding the biggest number among two or three numbers, and determining if a number is positive, negative, odd, or even. It also includes algorithms for calculating the summation and average of n numbers, finding factorials, and checking for prime numbers. Each algorithm is accompanied by pseudocode for implementation.

Uploaded by

Noor Athirah
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 15

Algorithm

1. Write an algorithm to swap two numbers.

Algorithm

1.Enter two numbers.

2.Diplay two numbers before swap.

3.Assign the number .

4.Swap the two numbers.

Pseudocode

1.Start

2.read num1,num2.

3.tmp=num1

4.num1=num2

5.num2=tmp

6.stop
2. Write an algorithm to find summation and average of two numbers

Algorithm

1.Enter two numbers.

2.Calculate the sum by add the two numbers.

3.Calculate the average by dividing the sum with two.

4.Display the sum and average of the two numbers.

Pseudocode

1.Start

2.read num1,num2

3.sum=num1+num2

4.average=(num1+num2)/2

5.Display sum, average

6.Stop
3. Write an algorithm to find the biggest number of two numbers.

Algorithm

1.Enter two numbers

2.If number1 is bigger than number2,display number1 is biggest.

3.If number2 is bigger than number1,display number2 is biggest.

Pseudocode

1.Start

2.Read num1,num2

3.If num1>num2,

3.1.display num1

4.else if num2>num1

4.1display num2
5.stop

4. Write an algorithm to find whether the number is negative or positive.

Algorithm

1.Enter number.

2.If the number greater than 0,display the number is positive.

3.If the number less than 0,display the number is negative.

Pseudocode

1.Start

2.read number

3.if number>0,

3.1.display the number is positive

4.else if number<0,
4.1.display the number is negative

5.stop

5. Write an algorithm to find whether the number is odd or even.

Algorithm

1.Enter number

2.If the number is divisible by 2 without remainder, display even.

3.If the number is not divisible by 2 ,display odd.

Pseudocode

1.Start

2.read number

3.if number %2==0,

3.1.display even

4.if number %2!=0,


4.1.display odd

5.stop

6. Write an algorithm to find the biggest number of three numbers.

Algorithm

1.Enter three numbers

2. Read number1,number2 and,number2

3. Check if number1 is bigger than number2

4. If true, check if number1 is bigger than number3.

5.If true, display number1 is the biggest number.

6.If false, display number3 is the biggest number.

7.If false, check if number2 is bigger than number3,

8.If true, display number2 is the biggest number.


9.If false, display number3 is the biggest number.

Pseudocode

1.Start

2.read number1,number2,number3

3.If (number1>number2&&number2>number3),

3.1.display number1 is the biggest number.

4.else if (number2>number3)

4.1display number2 is the biggest number.

5.else

5.1.display number3 is the biggest number.

6.stop

7. Write an algorithm to find the biggest number of n numbers.

Algorithm
1.Enter n numbers

2.Initilize the n

3.If n is greater than biggest, set biggest to the value of n

4.display biggest number

Pseudocode

1.Start

2.read n numbers

3.i=0

4.If i<=n

4.1display biggest

5.biggest=num

6.i=i+1

7.stop

8. Write an algorithm to calculate summation of n numbers.

Algorithm
1.Enter n numbers

2.calculate sum n numbers by add al the number

3.calculate the average divide by n

4.Display sum of n numbers.

Pseudocode

1.Start

2.sum=0,average=0,count=0

3.while (count<1)

5.sum=sum+1

4.end while

5.average=sum/n

6.Display average

7.Stop

9. Write an algorithm to find an average of n numbers.

Algorithm
1.enter n number

2.calculate sum of n number with total up all the numbers

3.calculate the average by divide the sum with n number

4.display average

Pseudocode

1.Start

2.sum=0,counter=0

3.read n

4.read num

5.sum=sum+num

6.counter=counter+1

7.read num
8.average=sum/n

9.print average

10.stop

10. Write an algorithm to calculate summation of odd numbers.

Algorithm

1.Enter odd numbers.

2.Calculate the summation by total up all the odd numbers.

3.Display the summation.

Pseudocode

1.Start

2.counter=0,sum=0

3.read odd number

4while odd number %2!=0

5.sum=sum + odd numbers

4.counter=counter+1
5.endwhile

6.print sum

7.Stop

11. Write an algorithm to calculate summation of even numbers.

Algorithm

1.Enter even numbers.

2.Calculate the summation by total up all the even numbers.

3.Dsiplay the summation

Pseudocode

1.Start

2.counter=0,sum=0

3.read even number

4while even number %2==0


5.sum=sum + even numbers

4.counter=counter+1

5.endwhile

6.print sum

7.Stop

12. Write an algorithm to find the factorial of a number entered by user.

Algorithm

1.Enter n number

2.Initialize the number as i=1,factorial=1

3.If i<= n ,calculate the factorial

4.Display factorial.

Pseudocode

1.Start

2.read n

3.i=1,factorial=1
4.If i<=n,

4.1.factorial=factorial*I,

5.i=i+1

6.Display factorial

7.Stop

13. Write an algorithm to check whether a number entered by user is prime or not.

Algorithm

1.Enter n number

2.Initialize n

3.If n can be divided without a remainder, only by itself and by 1,display prime

4. If n cannot be divided without a remainder, only by itself and by 1,display not prime

Pseudocode

1.Start

2.read n, i=2 to n-1

3.counter=0
4.if n==0

4.1.display not prime

5.else if n%i==0

5.1display prime

6.Stop

You might also like