0% found this document useful (0 votes)
3 views

Algorithms

Algorithms

Uploaded by

magiccian67
Copyright
© © All Rights Reserved
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
3 views

Algorithms

Algorithms

Uploaded by

magiccian67
Copyright
© © All Rights Reserved
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 6

Algorithm for 1st program.

1. Start.

2. Read the user's name as a string and store it in the variable 'a'.

3. Print "Hello World".

4. Print "Hello, " followed by the value stored in variable 'a'.

5. Stop.

Algorithm for 2nd program.

1. Start.

2. Read an integer and store it in variable a.

3. Read a floating-point number and store it in variable b.

4. Read a character and store it in variable c.

5. Read a double and store it in variable d.

6. Print "You entered:".

7. Print "Integer: " followed by the value of a.

8. Print "Floating-point number: " followed by the value of b.

9. Print "Character: " followed by the value of c.

10. Print "Double: " followed by the value of d.

11. Stop.

Algorithm for 3rd program.

1. Start

2. Read num1 from the user

3. Read num2 from the user

4. Calculate sum = num1 + num2

5. Calculate difference = num1 - num2

6. Calculate product = num1 * num2

7. Check if num2 is equal to 0:

(a) If yes,

(i) Print "Infinity"

(ii) Print "Modulo by zero is not allowed"

(b) If no,

(i) Calculate division = num1 / num2


(ii) Calculate modulus = num1 % num2

(iii) Print division

(iv) Print modulus

8. Print sum

9. Print difference

10. Print product

11. Stop

Algorithm for 4th program.

1. Start.

2. Display "Temperature Conversion Menu:".

3. Display "1. Celsius to Fahrenheit".

4. Display "2. Fahrenheit to Celsius".

5. Read user input for choice and store it in 'num'.

6. If 'num' is equal to 1, then:

a. Read user input for temperature in Celsius and store it in 'cel'.

b. Calculate Fahrenheit temperature: fah = cel * 9 / 5 + 32.

c. Display "Fahrenheit Temperature: <fah>".

7. Else, if 'num' is equal to 2, then:

a. Read user input for temperature in Fahrenheit and store it in 'fah'.

b. Calculate Celsius temperature: cel = (fah - 32) * 5 / 9.

c. Display "Celsius Temperature: <cel>".

8. Else, display "Invalid choice".

9. Stop.

Algorithm for 5th program.

1. Start.

2. Read a number from the user and store it in 'number'.

3. Print "After post increment: " followed by the value of 'number'.

4. Post-increment 'number'.

5. Print "After pre increment: " followed by the value of 'number' after pre-increment.
6. Stop.

Algorithm for 6th program.

1. Start

2. Input num1 and num2.

3. Perform bitwise AND, OR, XOR operations on `a` and `b`.

4. Perform bitwise NOT operations on `a` and `b`.

5. Perform left shift by 1 and right shift by 1 operations on `a` and `b`.

6. Display the results of each operation using `printf`.

7. End

Algorithm for 7th program.

1. Start.

2. Input an integer (`a`).

3. b=a%100.

4. If `a<100`:

a. Print "The number should be greater than 100."

- else:

a. Print `b`.

5. End.

Algorithm for 8th program.

1. Start.

2. Input three integers (`a`, `b`, and `c`).

3. If `a>b` and `a>c`, print "Greatest number: `a`".

- Else, if `b>c`, print "Greatest number: `b`".

- Else, print "Greatest number: `c`".

4. End.

Algorithm for 9th program.

1. Start.
2. Input two integers (`a` and `b`).

3. Print the values of `a` and `b` before swapping.

4.`a` = `a + b`.

`b` = `a - b`.

`a` = `a - b`.

5. Print the values of `a` and `b` after swapping.

6. End.

Algorithm for 10th program.

1.Start.

2. Input lower bound `b`.

3. Input upper bound `a`.

4. Input number to check `c`.

5. Check if `c` is greater than `a` and less than `b`:

- If true, print "`c` is in between `a` and `b`".

- If false, print "`c` is not in between `a` and `b`".

6. End.

Algorithm for 11th program.

1. Start.

2. Input a character (`l`).

3. Check if `l` is a letter using ranges of their ASCII values:

- If true, check if it's a vowel (`'a'`, `'e'`, `'i'`, `'o'`, `'u'`):

- If true, print "vowel".

- If false, print "consonant".

- If false, check if it's a digit (`'0'` to `'9'`):

- If true, print "digit".

- If false, print "special symbol".

4.End.

Algorithm for 12th program.


1.Start.

2. Input coefficients `a`, `b`, and `c`.

3. Calculate discriminant using `discriminant = b^2 - 4ac`.

4. If discriminant < 0 :

- `realPart = -b / (2 * a)` and `imaginaryPart = sqrt(-discriminant) / (2 * a)`.

- Print `root1 = realPart + imaginaryPart*i` and `root2 = realPart - imaginaryPart*i`.

5. If discriminant is non-negative:

- `root1 = (-b + sqrt(discriminant)) / (2 * a)`

- `root2 = (-b - sqrt(discriminant)) / (2 * a)`.

- Print `root1` and `root2`.

6. End.

Algorithm for 13th program.

1. Start.

2. Input two numbers (`a` and `b`).

3. Input an operator (`o`).

4. switch(o):

- If `o` is `+`, print `a+b`.

- If `o` is `-`, print `a-b`.

- If `o` is `*`, print `a*b`.

- If `o` is `/`, print `a/b`.

- If `o` is none of the above, print "Invalid operator".

5. End.

Algorithm for 14th program.

1.Start.

2. Input a string (`a`).

3. Iterate through each character in the string:

- If the character is an uppercase letter (ASCII values between 65 and 90):

- Convert it to lowercase by adding 32 to its ASCII value.

- If the character is a lowercase letter (ASCII values between 97 and 122):


- Convert it to uppercase by subtracting 32 from its ASCII value.

4. Print the modified string.

5.End.

Algorithm for 15th program.

1. Start.

2. Input `x` and `y`.

3. If `x < y`, enter loop from `i = x` to `y`:

- If `i % 2 != 0`, print `i`.

4. End loop.

5. End.

Algorithm for 16th program.

1. Start.

2. Input an integer `a`.

3. Initialize `sum` to 0.

4. Loop from `i = 1` to `a`:

- If `a` is divisible by `i` with remainder 0 (`a % i == 0`), print `i` as a factor and update `sum` using
sum=sum + i.

5. Check if `sum` is equal to `a + 1`:

- If true, print "Not a prime number".

- If false, print "Prime number".

6. End.

You might also like