fbpx

Enroll Now

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.

#include <stdio.h>

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.

#include <stdio.h>

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.

#include <stdio.h>
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

#include <stdio.h>
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

#include <stdio.h>
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.

#include <stdio.h>
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.

#include <stdio.h>
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.

#include <stdio.h>
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.

#include <stdio.h>
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.

#include <stdio.h>
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;
}

Most Popular

Social Media

Categories

On Key

Related Posts

String Questions in C

C Programing-Questions On Strings : Exercises, Practice, Solution

Ever wondered about strings in C? Here’s a quick challenge: Can you differentiate strings from character arrays, explain safe input using fgets(), find string length with strlen(), or compare strings by iterating characters? These are just a few ways to test your C string knowledge!

C programming questions on arrays

C Programing-Questions On Arrays : Exercises, Practice, Solution

Arrays are crucial in C programming for storing and manipulating data efficiently. Mastering array initialization, accessing elements, and basic operations like insertion and deletion is essential. Learning search and sorting algorithms for arrays enhances problem-solving skills. Exploring multi-dimensional arrays expands data representation possibilities. Advanced techniques like slicing and copying offer powerful manipulation tools. Understanding practical applications, such as implementing data structures like stacks and queues, provides real-world context. Stay tuned for detailed explanations and examples!

C programming Question on Pointers

C Programing-Questions On Pointers : Exercises, Practice, Solution

Write a C program to swap two integers using pointers. Write a C program to find the sum of elements in an array using pointers. Write a C program to reverse a string using pointers. Write a C program to find the maximum element in an array using pointers. Write a C program to count

Python Question Bank

Python Question Bank

Ready to challenge yourself? Dive into our curated list of 100 Python questions covering everything from basics to advanced topics. Whether you’re a beginner or a seasoned pro, these questions will put your Python knowledge to the test. Let’s see how well you know Python!