C Programing-Questions Basic Questions: Exercises, Practice, Solution.

In this Post we will see some basic questions in C programming. All beginners can go through with these excercise and test there basic skills.

C programming serves as a foundational milestone for many individuals navigating the programming landscape. It is an optimal choice for gaining insights into the intricacies of programming and comprehending the internal workings of computer programs.

Given its proximity to low-level programming, venturing into C can be a daunting prospect for beginners unless approached with deliberate practice. However, fear not! At Codeforwin, we offer a systematic, step-by-step approach to learning and practicing C programming.

Within this programming exercise, our primary focus lies on the fundamentals of C programming. Upon completion, you will have acquired a solid understanding of the basic structure and semantics inherent in C programs. Moreover, you’ll be adept at crafting mathematical programs using the C language.

Basic Questions

1 ) WAP in C to find addition of two numbers by taking input from user.

int main() {
    // Declare variables to store the input numbers
    int num1, num2, sum;

    // Prompt the user to enter the first number
    printf("Enter the first number: ");
    scanf("%d", &num1);

    // Prompt the user to enter the second number
    printf("Enter the second number: ");
    scanf("%d", &num2);

    // Calculate the sum
    sum = num1 + num2;

    // Display the result
    printf("The sum of %d and %d is: %d\n", num1, num2, sum);

    return 0;
}

2 ) WAP in C to find area of rectangle by taking input from user.

int main() {
// Declare variables
float length, width, area; // Prompt user for input
printf("Enter the length of the rectangle: ");
scanf("%f", &length);
printf("Enter the width of the rectangle: ");
scanf("%f", &width); // Calculate the area
area = length * width; // Display the result
printf("The area of the rectangle is: %.2f\n", area);
return 0;
}

3) WAP in C to find area of Square by taking input from user.

int main() {
    // Declare a variable to store the side length of the square
    int sideLength,area;
    // Prompt the user to enter the side length of the square
    printf("Enter the side length of the square: ");
    scanf("%d", &sideLength);
    // Calculate the area of the square
       area = sideLength * sideLength;
    // Display the result
    printf("The area of the square with side length %d is: %dn", sideLength, area);
    return 0;
}

4) WAP in C to calculte simple interest by taking principle, rate and time from user

int main() {
    // Declare variables to store user input
    int principle, rate, time;
    // Prompt the user to enter the principal amount
    printf("Enter the principal amount: ");
    scanf("%d", &principle);
    // Prompt the user to enter the interest rate
    printf("Enter the interest rate (in percentage): ");
    scanf("%d", &rate);
    // Prompt the user to enter the time (in years)
    printf("Enter the time (in years): ");
    scanf("%d", &time);
    // Calculate the simple interest
    float simpleInterest = (principle * rate * time) / 100;
    // Display the result
    printf("Simple Interest: %fn", simpleInterest);
    return 0;
}

5) WAP in C to input cost price and selling price for a product and find profit and loss value

int main() {
    // Declare variables to store user input
    int costPrice, sellingPrice;
    // Prompt the user to enter the cost price
    printf("Enter the cost price: ");
    scanf("%d", &costPrice);
    // Prompt the user to enter the selling price
    printf("Enter the selling price: ");
    scanf("%d", &sellingPrice);
    // Calculate profit or loss
    int profitLoss = sellingPrice - costPrice;
    // Display the result
    if (profitLoss > 0) {
        printf("Profit: %dn", profitLoss);
    } else if (profitLoss < 0) {
        printf("Loss: %dn", -profitLoss);  // Display loss as positive value
    } else {
        printf("No Profit, No Lossn");
    }
    return 0;
}

6) WAP in C to calculate area of circle taking input from user.

int main() {
    // Declare variables to store user input and the area
    int radius;
    float area;
    // Prompt the user to enter the radius of the circle
    printf("Enter the radius of the circle: ");
    scanf("%d", &radius);
    // Calculate the area of the circle
    area = 3.14159 * radius * radius;
    // Display the result
    printf("The area of the circle with radius %d is: %.2fn", radius, area);
    return 0;
}

7) WAP in C to input marks of a student having 5 subjects from user and then calculate total marks and percentage of the student and print them.

int main() {
    // Declare variables to store marks and calculations
    int marksSubject1, marksSubject2, marksSubject3, marksSubject4, marksSubject5;
    int totalMarks;
    float percentage;
    // Prompt the user to enter marks for each subject
    printf("Enter marks for Subject 1: ");
    scanf("%d", &marksSubject1);
    printf("Enter marks for Subject 2: ");
    scanf("%d", &marksSubject2);
    printf("Enter marks for Subject 3: ");
    scanf("%d", &marksSubject3);
    printf("Enter marks for Subject 4: ");
    scanf("%d", &marksSubject4);
    printf("Enter marks for Subject 5: ");
    scanf("%d", &marksSubject5);
    // Calculate total marks
    totalMarks = marksSubject1 + marksSubject2 + marksSubject3 + marksSubject4 + marksSubject5;
    // Calculate percentage
    percentage = (float)totalMarks / 5.0;
    // Display the results
    printf("nTotal Marks: %dn", totalMarks);
    printf("Percentage: %.2f%%n", percentage);
    return 0;
}

8) WAP in C to convert temperature from Celsius to Fahrenheit.

int main() {
    // Declare variables to store temperature in Celsius and Fahrenheit
    float celsius, fahrenheit;
    // Prompt the user to enter temperature in Celsius
    printf("Enter temperature in Celsius: ");
    scanf("%f", &celsius);
    // Convert Celsius to Fahrenheit
    fahrenheit = (celsius * 9 / 5) + 32;
    // Display the result
    printf("Temperature in Fahrenheit: %fn", fahrenheit);
    return 0;
}

9) WAP in C to input price of 5 products from user and calculate the total price and apply a discount of 10 % to provide a final total for payment.

int main() {
    // Declare variables to store prices and calculations
    float price1, price2, price3, price4, price5;
    float totalPrice, discountedTotal;
    // Prompt the user to enter prices for each product
    printf("Enter price for Product 1: ");
    scanf("%f", &price1);
    printf("Enter price for Product 2: ");
    scanf("%f", &price2);
    printf("Enter price for Product 3: ");
    scanf("%f", &price3);
    printf("Enter price for Product 4: ");
    scanf("%f", &price4);
    printf("Enter price for Product 5: ");
    scanf("%f", &price5);
    // Calculate total price
    totalPrice = price1 + price2 + price3 + price4 + price5;
    // Apply a discount of 10%
    discountedTotal = totalPrice - (0.10 * totalPrice);
    // Display the results
    printf("nTotal Price: %fn", totalPrice);
    printf("Discounted Total: %fn", discountedTotal);
    return 0;
}

10) WAP in C to input radius of circle from user and find its diameter, circumference and area.

int main() {
    // Declare variables to store user input and calculations
    float radius, diameter, circumference, area;
    // Prompt the user to enter the radius of the circle
    printf("Enter the radius of the circle: ");
    scanf("%f", &radius);
    // Calculate diameter, circumference, and area
    diameter = 2 * radius;
    circumference = 2 * 3.14159 * radius;
    area = 3.14159 * radius * radius;
    // Display the results
    printf("nDiameter of the circle: %fn", diameter);
    printf("Circumference of the circle: %fn", circumference);
    printf("Area of the circle: %fn", area);
    return 0;
}
On Key

Related Posts

Tableau Formulas

Most Commonly Used Formulas in Tableau (With Sample Sheet and Examples)

Unlock the Power of Tableau with Ready-to-Use Formulas!
Explore a comprehensive collection of Tableau formulas categorized for quick reference – including Numeric, String, Date, Logical, Aggregate, and Type Conversion functions. Whether you’re just starting out or already working on dashboards, this guide will help you master Tableau calculations faster with real examples and syntax-ready code.

Practice Question on Java Constructor

Java Constructor Practice Questions with Solutions | Pivot Edu Unit

Java is one of the most popular programming languages, and understanding constructors in Java is essential for mastering Object-Oriented Programming (OOP). If you are preparing for Java interviews, college exams, or simply want to improve your Java skills, this set of Java constructor practice questions will help you. At Pivot Edu Unit, Dehradun, we provide

How to Analyze Data Like a Pro – A Beginner’s Guide to Excel

Introduction In today’s data-driven world, Excel is one of the most powerful tools for analyzing and interpreting data. Whether you’re a student, a professional, or an aspiring data analyst, learning Excel can help you make informed decisions and stand out in your career. In this beginner-friendly guide, we’ll walk you through the key Excel functions

Digital Marketing Interview Question

Top Digital Marketing Interview Questions & Answers for 2025

🚀 Digital Marketing is one of the fastest-growing fields, and companies are actively looking for skilled professionals. Whether you’re a beginner or an experienced marketer, acing a Digital Marketing interview requires a strong understanding of key concepts, tools, and trends. At Pivot Edu Unit, Dehradun, we prepare our students with real-world projects and interview-ready skills.