Skip to content

C program basis assignment #6

Open
@Pankaj-Str

Description

@Pankaj-Str

Basic C Programming Assignment

Objective

Develop a set of programs to demonstrate understanding of basic C programming concepts including variables, data types, operators, control structures, and functions.

Assignment Tasks

Task 1: Simple Calculator (15 points)

Create a program that:

  • Accepts two numbers and an arithmetic operation (+, -, *, /) from the user
  • Performs the selected operation
  • Displays the result
  • Handles division by zero error
  • Uses a switch-case statement for operation selection

Example Interaction:

Enter first number: 10
Enter second number: 5
Select operation (+, -, *, /): *
Result: 50

Task 2: Number Pattern Printer (20 points)

Write a program that:

  • Accepts a number from the user (1-10)
  • Prints different number patterns using nested loops
  • Implement at least 3 different patterns:
    1. Right-angled triangle of numbers
    2. Pyramid pattern
    3. Inverted pyramid pattern

Example Output for input 5:

Pattern 1:
1 
1 2 
1 2 3 
1 2 3 4 
1 2 3 4 5

Pattern 2:
    1
   2 2
  3 3 3
 4 4 4 4
5 5 5 5 5

Task 3: Array Operations (25 points)

Develop a program that:

  • Creates an array of 10 integers
  • Implements functions to:
    1. Input array elements
    2. Calculate and return the average
    3. Find the highest and lowest numbers
    4. Sort the array in ascending order
    5. Display the array before and after sorting

Task 4: String Manipulation (20 points)

Create a program to:

  • Accept a string from the user
  • Implement functions to:
    1. Count the number of characters
    2. Convert the string to uppercase
    3. Check if the string is a palindrome
    4. Remove all spaces from the string

Task 5: Simple Electricity Bill Calculator (20 points)

Design a program that:

  • Accepts unit consumption
  • Calculates electricity bill based on the following slab rates:
    • 0-100 units: ₹0 per unit
    • 101-200 units: ₹5 per unit
    • 201-300 units: ₹7 per unit
    • 301+ units: ₹10 per unit
  • Apply additional surcharges:
    • 10% additional charge for units above 300
  • Display a detailed bill with:
    • Total units consumed
    • Rate per unit
    • Total bill amount
    • Surcharge (if applicable)

Evaluation Criteria

  • Correct implementation of requirements
  • Code readability
  • Proper use of functions
  • Error handling
  • Code efficiency
  • Commenting and documentation

Submission Guidelines

  1. Submit individual .c files for each task
  2. Include comments explaining your code
  3. Ensure code compiles without errors
  4. Handle potential user input errors

Bonus Challenges

  • Implement input validation
  • Add more complex operations to existing programs
  • Optimize your code for performance
  • Add additional features not specified in the original requirements

Learning Objectives

  • Understand basic C programming syntax
  • Practice control structures
  • Learn array and string manipulation
  • Develop problem-solving skills
  • Implement modular programming using functions

Recommended Tools

  • Use any C compiler (GCC, Turbo C, Dev-C++)
  • Recommended IDEs: Code::Blocks, Visual Studio Code
  • Use online compilers for initial testing

Metadata

Metadata

Assignees

No one assigned

    Labels

    questionFurther information is requested

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions