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

C Practical 2

Uploaded by

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

C Practical 2

Uploaded by

Alieu Keita
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 3

1: Calculate Discount and Amount to be Paid**

- Problem Statement:Develop a program that accepts a sales amount; if the sales amount is
more than 5000, then the discount is 12% of the sales amount; otherwise, it is 7%. Display the
total discount and the amount to be paid after the discount.
- Objective: Calculate and display the discount and the final amount to be paid based on the
sales amount.
- Algorithm:
1. Input the sales amount.
2. If the sales amount is more than 5000, calculate a 12% discount, otherwise calculate a 7%
discount.
3. Calculate the amount to be paid after applying the discount.
4. Display the total discount and the amount to be paid.

2: Calculate Percentage and Grade**


- Problem Statement:Write a program to enter the marks in three subjects for a student and find
the percentage and grade. Also, print whether the student has passed or failed.
- Objective: Calculate the percentage, determine the grade, and check if the student has passed
or failed.
- Algorithm:
1. Input the marks in three subjects.
2. Calculate the percentage as the average of the three subjects.
3. Determine the grade based on percentage.
4. If the grade is 'F,' mark the student as failed; otherwise, mark them as passed.
5. Display the percentage, grade, and pass/fail status.

Task 3: Print a Pattern


- Problem Statement: Write a program to print a specific pattern.
- Objective:Print a pattern as specified.
- Algorithm:
1. Input the number of rows (N).
2. Use nested loops to print the pattern:
- Outer loop iterates through rows (i).
- Inner loops print spaces and characters ('A' to 'Z') in each row.
- The number of characters and spaces in each row depends on the row number.
3. Display the pattern.

Task 4: Print a Pattern


- Problem Statement:Write a program to print a specific pattern of asterisks.
- Objective:Print a pattern of asterisks as specified.
- Algorithm:
1. Input the number of rows (N).
2. Use nested loops to print the pattern:
- Outer loop iterates through rows (i).
- Inner loop prints asterisks in each row based on certain conditions.
3. Display the pattern.

Task 5: Convert Decimal to Binary, Octal, and Hexadecimal


- Problem Statement: Write a program to convert a decimal number into binary, octal, and
hexadecimal.
- Objective: Convert a decimal number into binary, octal, and hexadecimal representations.
- Algorithm:
1. Input a decimal number.
2. Use printf statements to display the binary, octal, and hexadecimal representations of the
number.

**Task 6: Check if a Year is a Leap Year


- **Problem Statement:** Implement a program to accept a year as input and print whether it is
a leap year. A year is a leap year if divisible by 4, and centennial years (years divisible by 100)
are leap years only when divisible by 400.
- **Objective:** Determine whether a given year is a leap year or not.
- **Algorithm:**
1. Input a year.
2. Check if the year is divisible by 4.
3. If it is divisible by 4, check if it is not divisible by 100 or if it is divisible by 400.
4. If the conditions are met, the year is a leap year; otherwise, it is not.

**Task 7: Print Natural Palindrome Numbers up to N**


- **Problem Statement:** Write a C program to print all the natural palindrome numbers up to N.
- **Objective:** Print natural palindrome numbers up to a given limit (N).
- **Algorithm:**
1. Input the value of N.
2. For each number from 0 to N, check if it is a palindrome using a helper function.
3. If a number is a palindrome, print it.

**Task 8: Print First N Prime Numbers**


- **Problem Statement:** Write a C program to print the first N prime numbers.
- **Objective:** Generate and print the first N prime numbers.
- **Algorithm:**
1. Input the value of N.
2. Initialize a count of prime numbers and a variable for testing prime.
3. Start a loop to generate prime numbers:
- Check if the testing variable is prime using a helper function.
- If it is prime, print it and increment the count.
- Repeat until the count reaches N.
**Task 9: Convert Digits of a Number into Words**
- **Problem Statement:** Write a C program to print the digits of a number in words.
- **Objective:** Convert and print the digits of a number into words.
- **Algorithm:**
1. Input a number.
2. Use a recursive function to print the digits of the number in words.
3. Inside the function, for each digit, convert it into its word form using an array of words.
4. Print the word representation of each digit.

**Task 10: Compute the Sum of Series**


- **Problem Statement:** Write a C program to compute the sum of the first N terms for a given
series.
- **Objective:** Calculate and print the sum of the series.
- **Algorithm:**
1. Input the value of N.
2. Initialize variables for sum.
3. Use a loop to calculate the sum based on the specific series formula for each case (i, ii, iii).
4. Print the calculated sum.

You might also like