Search This Blog

Showing posts with label Computer Practicals X. Show all posts
Showing posts with label Computer Practicals X. Show all posts

Monday, 7 March 2022

Practical No.13: Write a program to read an integer n and print the factorial of n.

ACTIVITY 13

Practical No.13:
Write a program to read an integer n and print the factorial of n.





OR

By Sir Sajjad Akber Chandio


ALGORITHM

  • step 1: start
  • step 2: Declare variables for number, factorial and loop
  • step 3: Input positive integer number
  • step 4: Use factorial formula i.e. factorial = factorial * integer number
  • step 5: Repeat step # 4 until integer number
  • step 6: Print factorial value
  • step 7: End


VIVA VOCE
ACTIVITY 13

Q.1: What do you understand by factorial?
Ans: Factorial is the product of all positive integers less than or equal to a given positive integer and denoted by that integer and an exclamation point.

Q.2: Write down the example of factorial of a number.
Ans: Factorial seven is written 7!, calculate as:
1 x 2 x 3 x 4 x 5 x 6 x 7.
Factorial zero is defined as equal to 1.

Q.3: What is loop?
Ans: Iteration or loop in computer programming, is a process wherein a set of instructions or structures are repeated in a sequence a specified number of times until a condition is true.

Q.4: How many types of loop are there?
Ans: C++ provides following types of loop to handle looping requirement.
1. for loop
2. while loop
3. do-while loop

Q.5: What are the escape sequence in C++?
Ans: Escape sequence is a set of characters that convey a special meaning to the program.

Q.6: What is the use of "namespace" in C++?
Ans: Namespace are used to organize code into logical groups and to prevent name collisions that can occur especially when our code base includes multiple libraries.



Practical No.12: Write a program to read 10 numbers and sort them into ascending order

ACTIVITY 12

Practical No.12:
Write a program to read 10 numbers and sort them into ascending order.







OR

By Sir Sajjad Akber Chandio



ALGORITHM

  • step 1: start
  • step 2: Declare variables for loop
  • step 3: Define an array of 10 value
  • step 4: Input ten value stored in defined array
  • step 5: Using sort function to sort array value (Note: Values are stored in array in ascending order)
  • step 6: Print array contents from 0 to 9 sorted value in ascending order
  • step 7: End







Practical No.11: Write a program to read 10 numbers and sort term into descending order

ACTIVITY 11

Practical No.11:
Write a program to read 10 numbers and sort term into descending order.







OR

By Sir Sajjad Akber Chandio
For SOURCE CODE See above codes





Practical No.10 Write a program that takes a number and prints its multiples up to 10.

ACTIVITY 10

Practical No.10:
Write a program that takes a number and prints its multiples up to 10.





OR

By Sir Sajjad Akber Chandio


ALGORITHM

  • step 1: start
  • step 2: Declare variables for loop and number
  • step 3: Input any number
  • step 4: Print multiples of number up to 10
  • step 5: Repeat step 4 10times (using for loop)
  • step 6: End


VIVA VOCE
ACTIVITY 10

Q.1: What is loop?
Ans: Iteration or loop in computer programming, is a process wherein a set of instructions or structures are repeated in a sequence a specified number of times until a condition is true.

Q.2: How many types of loops are there?
Ans: C++ provides the following types of loops to handle looping requirements.
1. for loop
2. while loop
3. do-while loop

Q.3: Define for loop.
Ans: A for loop is a repetition or iteration control structure that repeats a statement or block of statements for a specified number of times. The for loop is commonly used when the number of iterations is known.

Q.4: Which function is used for printing output?
Ans: tout is the most common input function in C++ used as output function.

Q.5: What are the Escape sequences in C++?
Ans: Escape sequence is a set of characters that convey a special meaning to the program.


Practical No.9: Write a program to convert temperature from Fahrenheit into Celsius

ACTIVITY 9

Practical No.9:
Write a program to convert temperature from Fahrenheit into Celsius






OR

By Sir Sajjad Akber Chandio

ALGORITHM

  • step 1: start
  • step 2: Declare variables or Fahrenheit and Celsius
  • step 3: Take input for temperature in Fahrenheit
  • step 4: Convert Fahrenheit into Celsius by using formula i.e. (F – 32) * (5.0 / 9.0)
  • step 5: Print temperature value in Celsius
  • step 6: End


VIVA VOCE
ACTIVITY 9

Q.1: Define the range of Fahrenheit scale.
Ans: Fahrenheit scale is marked from 32° to 212°.

Q.2: Write down the formula of Fahrenheit into centigrade.
Ans: Fahrenheit into Celsius conversion is done by this formula:
Celsius = (Fahrenheit -32) * (5.0 / 9.0)

Q.3: Write down the formula of Celsius into Fahrenheit.
Ans: Fahrenheit into Celsius conversion is done by this formula:
Fahrenheit = {Celsius * (5.0 / 9.0)} + 32

Q.4: Define the range of Celsius scale.
Ans: Celsius scale is marked from 0° to 100°.

Q.5: What is the purpose of return keyword used in C++?
Ans: This statement is used to return the value to the operating system. By default, main function returns integer value 0.



Sunday, 6 March 2022

Practical No.8: Write a program to input length in centimeter and convert it into meter

ACTIVITY 8

Practical No.8:
Write a program to input length in centimeter and convert it into meter





OR

By Sir Sajjad Akber Chandio


ALGORITHM

  • step 1: start
  • step 2: Declare variables for length and meter
  • step 3: Take input for length in centimeter
  • step 4: Convert it into meter by dividing centimeter value with 100
  • step 5: Print value in meter
  • step 6: End




Practical No.7: Write a program to find the area of a rectangle

ACTIVITY 7

Practical No.7:
Write a program to find the area of a rectangle.





OR

By Sir Sajjad Akber Chandio


ALGORITHM

  • step 1: start
  • step 2: Declare variables
  • step 3: Take input for length
  • step 4: Take input for width
  • step 5: calculate area by multiplying length by width
  • step 6: Print Area
  • step 7: End


VIVA VOCE
ACTIVITY 7

Q.1: What do you understand by an area of rectangle?
Ans: Area of rectangle is the region occupied by a rectangle within its four sides or boundaries.

Q.2: Write down the formula to calculate area of rectangle.
Ans: The area of a rectangle is the product of its length and width. So, area of rectangle = (length x width).

Q.3: Which type of operator is used in this program?
Ans: Arithmetic multiplication operator is used in this program.

Q.4: What is the purpose of return keyword used in C++?
Ans: This statement is used to return the value to the operating system. By default, main function returns integer value 0.

Q.5: Function cout belongs to which header file?
Ans: cout function belongs to header file iostream.


Practical No.6: Write a program to check whether a number is positive, negative or zero.

ACTIVITY 6

Practical No.6:
Write a program to check whether a number is positive, negative or zero






OR

By Sir Sajjad Akber Chandio



VIVA VOCE
ACTIVITY 6

Q.1: What is an integer?
Ans: A number which is a whole number and cannot contain decimal point is called an integer.

Q.2: What is a positive number?
Ans: A number which is greater than zero is called a positive number.

Q.3 What is a negative number?
Ans: A number which is less than zero is called a negative number.

Q.4 What is if condition?
Ans: An if condition is a selection control structure that compares two values and evaluates the answer as true or false.