C practical 7 to 13

 

7.     Write a c program to convert temperature form Fahrenheit to Centigrade using this formula like (c=(f-32)/1.8). 




#include <stdio.h>


void main() {

    float fahrenheit, celsius;


    // Asking the user to input the temperature in Fahrenheit

    printf("Enter temperature in Fahrenheit: ");

    scanf("%f", &fahrenheit);


    // Converting Fahrenheit to Celsius using the formula

    celsius = (fahrenheit - 32) / 1.8;


    // Displaying the result

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

}




8.     Write a c program to find square root of given number. 


#include <stdio.h>

#include <math.h>  // for sqrt() function


void main() {

    double num, result;


    // Asking the user to input a number

    printf("Enter a number: ");

    scanf("%lf", &num);


    // Calculating the square root

    result = sqrt(num);


    // Displaying the result

    printf("Square root of %.2lf = %.2lf\n", num, result);

}



9. C Program to Check if a Given Year is a Leap Year or Not.


#include <stdio.h>


void main() {

    int year;


    // Asking the user to input the year

    printf("Enter a year: ");

    scanf("%d", &year);


    // Leap year condition

    if (year % 4 == 0 ) {

        printf("%d is a leap year.\n", year);

    } else {

        printf("%d is not a leap year.\n", year);

    }

}


10. C Program to Check if a Given Number is Odd or Even


#include <stdio.h>


void main() {

    int num;


    // Asking the user to input a number

    printf("Enter a number: ");

    scanf("%d", &num);


    // Checking if the number is even or odd

    if (num % 2 == 0) {

        printf("%d is even.\n", num);

    } else {

        printf("%d is odd.\n", num);

    }

}



11. C Program to Check if a Given Number is Positive, Negative, or Zero.



#include <stdio.h>


void main() {

    int num;


    // Asking the user to input a number

    printf("Enter a number: ");

    scanf("%d", &num);


    // Checking if the number is positive, negative, or zero

    if (num > 0) {

        printf("%d is positive.\n", num);

    } else if (num < 0) {

        printf("%d is negative.\n", num);

    } else {

        printf("The number is zero.\n");

    }

}




12. C Program to Print the Largest Value Among Three Values.


#include <stdio.h>


void main() {

    int num1, num2, num3;


    // Asking the user to input three values

    printf("Enter three numbers: ");

    scanf("%d %d %d", &num1, &num2, &num3);


    // Finding the largest number

    if (num1 >= num2 && num1 >= num3) {

        printf("%d is the largest number.\n", num1);

    } else if (num2 >= num1 && num2 >= num3) {

        printf("%d is the largest number.\n", num2);

    } else {

        printf("%d is the largest number.\n", num3);

    }

}




13. C Program to Print Percentage and Class of Student by Inputting Three Subject Marks (Using if..else if).



#include <stdio.h>


void main() {

    int subject1, subject2, subject3, totalMarks;

    float percentage;


    // Asking the user to input marks for three subjects

    printf("Enter marks for three subjects: ");

    scanf("%d %d %d", &subject1, &subject2, &subject3);


    // Calculating total marks and percentage

    totalMarks = subject1 + subject2 + subject3;

    percentage = (float)totalMarks / 3;


    // Printing the percentage

    printf("Percentage: %.2f%%\n", percentage);


    // Determining the class based on percentage

    if (percentage >= 75) {

        printf("Distinction\n");

    } else if (percentage >= 60) {

        printf("First Class\n");

    } else if (percentage >= 50) {

        printf("Second Class\n");

    } else if (percentage >= 40) {

        printf("Pass\n");

    } else {

        printf("Fail\n");

    }

}














Post a Comment

0 Comments