Answers: c language basic interview questions and answers for freshers.

 In this Question and answer serious I considered almost all important topics for c language from basic to advance.

In this Question and answer serious I considered almost all important topics for c language from basic to advance.


Recommended For You: 

1. Day 11: Decision-making statements: If, If.Else.., if.Else if ...else if, else.

2.  Day 10: Math.h header file detailed review and important functions in Math. h.

3. Read All important posts for these equations: Click Here


1 . WAP to input the roll number, name, marks, and phone of a student and display the values.

Answer :

#include <stdio.h>

int main() {
    int roll_number;
    char name[50];
    float marks;
    long phone;

    printf("Enter roll number: ");
    scanf("%d", &roll_number);

    printf("Enter name: ");
    scanf("%s", name);

    printf("Enter marks: ");
    scanf("%f", &marks);

    printf("Enter phone number: ");
    scanf("%ld", &phone);

    printf("\nStudent Details:\n");
    printf("Roll Number: %d\n", roll_number);
    printf("Name: %s\n", name);
    printf("Marks: %.2f\n", marks);
    printf("Phone Number: %ld\n", phone);

    return 0;
}



2 . WAP to input roll number, name, and marks of a student in 5 subjects and calculate

the total and average marks. Display all the values.


Answer: 
#include <stdio.h>

int main() {
    int roll_number;
    char name[50];
    float marks[5];
    float total_marks = 0;
    float average_marks;

    printf("Enter roll number: ");
    scanf("%d", &roll_number);

    printf("Enter name: ");
    scanf("%s", name);

    for (int i = 0; i < 5; i++) {
        printf("Enter marks for subject %d: ", i + 1);
        scanf("%f", &marks[i]);
        total_marks += marks[i];
    }

    average_marks = total_marks / 5;

    printf("\nStudent Details:\n");
    printf("Roll Number: %d\n", roll_number);
    printf("Name: %s\n", name);
    printf("Marks:\n");
    for (int i = 0; i < 5; i++) {
        printf("Subject %d: %.2f\n", i + 1, marks[i]);
    }
    printf("Total Marks: %.2f\n", total_marks);
    printf("Average Marks: %.2f\n", average_marks);

    return 0;
}



3. WAP to find out the square of a given number.

Ans:  #include <stdio.h>

int main() {
    int number, square;

    printf("Enter a number: ");
    scanf("%d", &number);

    square = number * number;

    printf("The square of %d is: %d\n", number, square);

    return 0;
}


4. WAP to input a number and print its cube.


#include <stdio.h>

int main() {
    int number, cube;

    printf("Enter a number: ");
    scanf("%d", &number);

    cube = number * number * number;

    printf("The cube of %d is: %d\n", number, cube);

    return 0;
}


5 . WAP to input radius and calculate the area and circumference of a circle.


Ans: 
#include <stdio.h>

#define PI 3.14159

int main() {
    float radius, area, circumference;

    printf("Enter the radius of the circle: ");
    scanf("%f", &radius);

    area = PI * radius * radius;
    circumference = 2 * PI * radius;

    printf("Area of the circle: %.2f\n", area);
    printf("Circumference of the circle: %.2f\n", circumference);

    return 0;
}


6 . WAP to input the width and height of a rectangle and calculate the area and perimeter. [Area of
rectangle :width*height, Perimeter of rectangle : 2*width+2*height]


Ans: 
#include <stdio.h>

int main() {
    float width, height, area, perimeter;

    printf("Enter the width of the rectangle: ");
    scanf("%f", &width);

    printf("Enter the height of the rectangle: ");
    scanf("%f", &height);

    area = width * height;
    perimeter = 2 * (width + height);

    printf("Area of the rectangle: %.2f\n", area);
    printf("Perimeter of the rectangle: %.2f\n", perimeter);

    return 0;
}


7. WAP to input 4 integers a, b, c, d and check that the equation 3*a+ 3*b +3*c= 3*d is
satisfied or not.

Ans: 
#include <stdio.h>

int main() {
    int a, b, c, d;

    printf("Enter the value of a: ");
    scanf("%d", &a);

    printf("Enter the value of b: ");
    scanf("%d", &b);

    printf("Enter the value of c: ");
    scanf("%d", &c);

    printf("Enter the value of d: ");
    scanf("%d", &d);

    if ((3 * a + 3 * b + 3 * c) == (3 * d)) {
        printf("The equation 3*a + 3*b + 3*c = 3*d is satisfied.\n");
    } else {
        printf("The equation 3*a + 3*b + 3*c = 3*d is not satisfied.\n");
    }

    return 0;
}


8 .WAP to input side of a square and calculate the area. [Area of squre :side*side]

Ans: 

#include <stdio.h>

int main() {
    float side, area;

    printf("Enter the side length of the square: ");
    scanf("%f", &side);

    area = side * side;

    printf("Area of the square: %.2f\n", area);

    return 0;
}


9. WAP to input principle, rate and time from the user and calculate the simple interest and total amount.
Display all the values.

Ans: 
#include <stdio.h>

int main() {
    float principle, rate, time, simple_interest, total_amount;

    printf("Enter the principle amount: ");
    scanf("%f", &principle);

    printf("Enter the rate of interest: ");
    scanf("%f", &rate);

    printf("Enter the time period (in years): ");
    scanf("%f", &time);

    simple_interest = (principle * rate * time) / 100;
    total_amount = principle + simple_interest;

    printf("\nPrinciple amount: %.2f\n", principle);
    printf("Rate of interest: %.2f\n", rate);
    printf("Time period (in years): %.2f\n", time);
    printf("Simple interest: %.2f\n", simple_interest);
    printf("Total amount: %.2f\n", total_amount);

    return 0;
}


10 . WAP to input the number the days from the user and convert it into years, weeks and days. [year=days/365,
week=days/7]


Ans: 
#include <stdio.h>

int main() {
    int days, years, weeks, remaining_days;

    printf("Enter the number of days: ");
    scanf("%d", &days);

    years = days / 365;
    weeks = (days % 365) / 7;
    remaining_days = (days % 365) % 7;

    printf("Years: %d\n", years);
    printf("Weeks: %d\n", weeks);
    printf("Days: %d\n", remaining_days);

    return 0;
}

11 . WAP to input a character and print its ASCII value.

Ans: 
#include <stdio.h>

int main() {
    char ch;

    printf("Enter a character: ");
    scanf("%c", &ch);

    printf("ASCII value of '%c': %d\n", ch, ch);

    return 0;
}


12 . WAP to input a number and print its equivalent character code.

Ans: 

#include <stdio.h>

int main() {
    int number;

    printf("Enter a number: ");
    scanf("%d", &number);

    printf("Character code of '%d': %c\n", number, number);

    return 0;
}


13 . WAP to find out the quotient and remainder of two numbers. ( Without using
the modulus ( % ) operator) [ use the formula: a - (a/b)*b]

Ans: 
#include <stdio.h>

int main() {
    int dividend, divisor, quotient, remainder;

    printf("Enter the dividend: ");
    scanf("%d", &dividend);

    printf("Enter the divisor: ");
    scanf("%d", &divisor);

    quotient = dividend/divisor;
    remainder = dividend - (quotient * divisor);

    printf("Quotient: %d\n", quotient);
    printf("Remainder: %d\n", remainder);

    return 0;
}


14 . WAP to input two numbers and print their quotient and remainder.

Ans: 
#include <stdio.h>

int main() {
    int dividend, divisor, quotient, remainder;

    printf("Enter the dividend: ");
    scanf("%d", &dividend);

    printf("Enter the divisor: ");
    scanf("%d", &divisor);

    quotient = dividend/divisor;
    remainder = dividend % divisor;

    printf("Quotient: %d\n", quotient);
    printf("Remainder: %d\n", remainder);

    return 0;
}


15 . WAP to input two numbers and print the greatest using a conditional operator.


Ans: 
#include <stdio.h>

int main() {
    int num1, num2, greatest;

    printf("Enter the first number: ");
    scanf("%d", &num1);

    printf("Enter the second number: ");
    scanf("%d", &num2);

    greatest = (num1 > num2) ? num1 : num2;

    printf("The greatest number is: %d\n", greatest);

    return 0;
}


16 . WAP to input the marks of a student and print the result (pass/fail) using a conditional
operator.


Ans: 
#include <stdio.h>

int main() {
    int marks;

    printf("Enter the marks: ");
    scanf("%d", &marks);

    char* result = (marks >= 40) ? "Pass" : "Fail";

    printf("Result: %s\n", result);

    return 0;
}



17 . WAP to input inches from the user and convert it into yards, feet .
[Inch=inch*0.027 yards, inch=0.083 feet]

Ans: 
#include <stdio.h>

int main() {
    float inches, yards, feet;

    printf("Enter the length in inches: ");
    scanf("%f", &inches);

    yards = inches * 0.027;
    feet = inches * 0.083;

    printf("Length in yards: %.2f\n", yards);
    printf("Length in feet: %.2f\n", feet);

    return 0;
}


18.  WAP to find out the area of a triangle.

Ans: 
#include <stdio.h>

int main() {
    float base, height, area;

    printf("Enter the base of the triangle: ");
    scanf("%f", &base);

    printf("Enter the height of the triangle: ");
    scanf("%f", &height);

    area = 0.5 * base * height;

    printf("Area of the triangle: %.2f\n", area);

    return 0;
}


19 . WAP to find whether a given number is even or odd using a conditional operator.

Ans: 
#include <stdio.h>

int main() {
    int number;

    printf("Enter a number: ");
    scanf("%d", &number);

    char* result = (number % 2 == 0) ? "Even" : "Odd";

    printf("%d is %s\n", number, result);

    return 0;
}


20 .  WAP to find out the greatest of three numbers using a conditional operator.

Ans: 
#include <stdio.h>

int main() {
    int num1, num2, num3, greatest;

    printf("Enter the first number: ");
    scanf("%d", &num1);

    printf("Enter the second number: ");
    scanf("%d", &num2);

    printf("Enter the third number: ");
    scanf("%d", &num3);

    greatest = (num1 > num2) ? ((num1 > num3) ? num1 : num3) : ((num2 > num3) ? num2 : num3);

    printf("The greatest number is: %d\n", greatest);

    return 0;
}


21 . WAP to input choice (1 or 2). If the choice is 1 print the area of a circle otherwise print the circumference of a circle. Input the radius from the user.

Ans: 

#include <stdio.h>

#define PI 3.14159

int main() {
    int choice;
    float radius;

    printf("Enter your choice (1 for area, 2 for circumference): ");
    scanf("%d", &choice);

    printf("Enter the radius of the circle: ");
    scanf("%f", &radius);

    if (choice == 1) {
        float area = PI * radius * radius;
        printf("Area of the circle: %.2f\n", area);
    } else if (choice == 2) {
        float circumference = 2 * PI * radius;
        printf("Circumference of the circle: %.2f\n", circumference);
    } else {
        printf("Invalid choice!\n");
    }

    return 0;
}


22 . WAP to input a number. If the number is even, print its square otherwise print its cube.

Ans: 
#include <stdio.h>

int main() {
    int number;

    printf("Enter a number: ");
    scanf("%d", &number);

    if (number % 2 == 0) {
        int square = number * number;
        printf("Square of %d is: %d\n", number, square);
    } else {
        int cube = number * number * number;
        printf("Cube of %d is: %d\n", number, cube);
    }

    return 0;
}


23 . WAP to input employee code, name, and basic salary of an employee and calculate the following values:
HRA 40 % of basic salary DA 10 % of basic salary
CCA 5 % of basic salary GS Basic + HRA + DA + CCA
PF 10 % of GS IT 10 % of GS
NS GS – (PF + IT)


Ans: 
#include <stdio.h>

int main() {
    int employeeCode;
    char employeeName[50];
    float basicSalary, hra, da, cca, gs, pf, it, ns;

    printf("Enter employee code: ");
    scanf("%d", &employeeCode);

    printf("Enter employee name: ");
    scanf("%s", employeeName);

    printf("Enter basic salary: ");
    scanf("%f", &basicSalary);

    hra = 0.4 * basicSalary;
    da = 0.1 * basicSalary;
    cca = 0.05 * basicSalary;
    gs = basicSalary + hra + da + cca;
    pf = 0.1 * gs;
    it = 0.1 * gs;
    ns = gs - (pf + it);

    printf("\nEmployee Details:\n");
    printf("Employee Code: %d\n", employeeCode);
    printf("Employee Name: %s\n", employeeName);
    printf("Basic Salary: %.2f\n", basicSalary);
    printf("HRA: %.2f\n", hra);
    printf("DA: %.2f\n", da);
    printf("CCA: %.2f\n", cca);
    printf("Gross Salary: %.2f\n", gs);
    printf("PF: %.2f\n", pf);
    printf("IT: %.2f\n", it);
    printf("Net Salary: %.2f\n", ns);

    return 0;
}


24 . WAP to input the temperature in Fahrenheit and convert it into Celsius and vice
versa.[centigrade=5*(fahrenheit-32)/9 : fahrenheit=(Centigrade*0.2) + 32 ]

Ans: 
#include <stdio.h>

int main() {
    float fahrenheit, celsius;

    printf("Enter the temperature in Fahrenheit: ");
    scanf("%f", &fahrenheit);

    celsius = 5 * (fahrenheit - 32) / 9;

    printf("Temperature in Celsius: %.2f\n", celsius);

    printf("\nEnter the temperature in Celsius: ");
    scanf("%f", &celsius);

    fahrenheit = (celsius * 9 / 5) + 32;

    printf("Temperature in Fahrenheit: %.2f\n", fahrenheit);

    return 0;
}


25 . WAP to swap the values of two integer variables

Ans: 

#include <stdio.h>

int main() {
    int a, b, temp;

    printf("Enter the value of a: ");
    scanf("%d", &a);

    printf("Enter the value of b: ");
    scanf("%d", &b);

    printf("\nBefore swapping:\n");
    printf("a = %d\n", a);
    printf("b = %d\n", b);

    temp = a;
    a = b;
    b = temp;

    printf("\nAfter swapping:\n");
    printf("a = %d\n", a);
    printf("b = %d\n", b);

    return 0;
}





All the blow equations are based on these key points in c.

Here are some fundamental concepts of the C programming language:


1.  C has a specific syntax that includes the use of semicolons (;) to terminate statements, curly braces ({}) to define blocks of code, and parentheses to group expressions.


2. Variables and Data Types: In C, you declare variables to store data. C supports various data types such as int (integer), float (floating-point), char (character), and more. Variables must be declared before they can be used.


3. Operators: C provides a wide range of operators, including arithmetic operators (+, -, *, /), assignment operators (=), comparison operators (>, <, ==), logical operators (&&, ||), and more.


4. Control Flow: C supports control flow statements such as if-else statements, switch statements, while loops, for loops, and do-while loops. These statements allow you to control the flow of execution based on conditions or loops.


5. Functions: C programs are typically structured using functions. Functions are blocks of code that perform specific tasks and can be called from other parts of the program. C programs usually have a main() function as the entry point.


6. Arrays: Arrays in C allow you to store multiple values of the same data type. Arrays are declared with a specific size and can be accessed using indices.


7. Pointers: Pointers are variables that store memory addresses. They allow you to work with memory directly and are often used for dynamic memory allocation, passing values by reference, and working with arrays.


8. Input and Output: C provides input/output functions like printf() and scanf() for printing output to the console and reading input from the user.


9. Preprocessor Directives: Preprocessor directives in C start with a hash symbol (#) and provide instructions to the preprocessor. These directives are processed before the compilation and can include actions like including header files or defining constants.


These are just some of the fundamental concepts in C programming. Mastering these concepts will provide a strong foundation for writing C programs.

















 

Post a Comment

Previous Post Next Post