Coding Practice

Responsive Blogger, WordPress and Static Demo Templates

Write a C Code to find total marks from given input...

Write a C Code to find total marks from given input: Attendance, Class test, Quiz test, Assignment, Midterm and Final Exam and find the grade using the following method:

  1. If Total mark >=80 then A+
  2. If Total mark >=70 then A
  3. If Total mark >=60 then A
  4. If Total mark >=50 then B
  5. Else Grade = F

Sample Input

Enter Attendance, Class test, Quiz test, Assignment, Midterm and Final Exam: 2.5 7.5 3.5 7 21.5 33

Sample Output

Total Mark: 75 & Grade: A

Sample Output
Enter Attendance, Class test, Quiz test, Assignment, Midterm and Final Exam: 2.5 7.5 3.5 7 21.5 33
Total Mark: 75.000000 & Grade: A
Source Code
#include<stdio.h>

int main()
{
    float attendance, ct, qt, assignment, mid_mark, final_mark, total_mark;

    printf("Enter Attendance, Class test, Quiz test, Assignment, Midterm and Final Exam: ");
    scanf("%f %f %f %f %f %f", &attendance, &ct, &qt, &assignment, &mid_mark, &final_mark);
    //Input: 2.5 7.5 3.5 7 21.5 33

    total_mark = (attendance + ct + qt + assignment + mid_mark + final_mark);

    if(total_mark >= 80 && total_mark <= 100)
    {
        printf("Total Mark: %f & Grade: A+\n\n", total_mark);
    }
    else if(total_mark >= 70 && total_mark <= 79)
    {
        printf("Total Mark: %f & Grade: A\n\n", total_mark);
    }
    else if(total_mark >= 60 && total_mark <= 69)
    {
        printf("Total Mark: %f & Grade: A-\n\n", total_mark);
    }
    else if(total_mark >= 50 && total_mark <= 59)
    {
        printf("Total Mark: %f & Grade: B\n\n", total_mark);
    }
    else
    {
        printf("Total Mark: %f & Grade: F\n\n", total_mark);
    }

    return 0;
}
Sample Output
Enter Attendance, Class test, Quiz test, Assignment, Midterm and Final Exam: 2.5 7.5 3.5 7 21.5 33
Total Mark: 75.000000 & Grade: A

Write a C Code to calculate D = 𝒃^𝟐 − 𝟒𝐚𝐜 and...

Write a C Code to calculate D = 𝒃^𝟐 − 𝟒𝐚𝐜 and show the result according to following conditions:

a. D>0 then Calculate X1, X2. Where 𝒙𝟏 = (−𝒃+√𝒃^𝟐−𝟒𝒂𝒄)/𝟐𝒂 and 𝒙𝟐 = (−𝒃−√𝒃^𝟐−𝟒𝒂𝒄)/𝟐𝒂

        b. D =0 then calculate X. Where 𝐱 = 𝒃^𝟐/𝟐𝒂

        c. D<0 then print “No Solution”.

Sample Input

        Enter a, b & c: 5 6 1

Sample Output

    X1: -0.2

    X2: -1
Sample Output
Enter a, b, & c: 5 6 1
X1: -0.200
x2: -1.000
Source Code
#include<stdio.h>
#include<math.h>

int main()
{
    float D, b, a, c, x, x1, x2;

    printf("Enter a, b, & c: ");
    scanf("%f %f %f", &a, &b, &c);

    D = ((b*b) - 4*a*c);

    if(D > 0)
    {
        x1 = (-b + sqrt(D))/(2*a);
        x2 = (-b - sqrt(D))/(2*a);

        printf("X1: %.3f\nx2: %.3f\n\n", x1, x2);
    }
    else if(D == 0)
    {
        x = (b*b)/(2*a);

        printf("X: %f\n\n");
    }
    else if(D < 0)
    {
        printf("No Solution\n\n");
    }
    return 0;
}
Sample Output
Enter a, b, & c: 5 6 1
X1: -0.200
x2: -1.000

Write a C program to solve the Drake equation...

Write a C program to solve the Drake equation N = R*fp*ne*fl*fi*fc*L. Where R, ne and L must be discrete value.

Sample Input

    Enter R, F(p), n(e), f(l), f(i), f(c), L: 5 0.25 20 0.2 0.15 0.11 150

Sample Output

    The number of communicative civilizations within the Milky Way today: 12.375

Sample Output
Enter R, F(p), n(e), f(l), f(i), f(c): 5 0.25 20 0.2 0.15 0.11 150
The number of communicative civilizations within the Milky Way today: 12.375
Source Code
#include<stdio.h>
#include<math.h>

int main()
{
    float N, fp, fl, fi, fc;
    int R, ne, L;

    printf("Enter R, F(p), n(e), f(l), f(i), f(c): ");
    scanf("%d %f %d %f %f %f %d", &R, &fp, &ne, &fl, &fi, &fc, &L); //Input: 5 0.25 20 0.2 0.15 0.11 150

    float n = (float)R*ne*L;
    N = n*fp*fl*fi*fc;

    printf("The number of communicative civilizations within the Milky Way today: %.3f\n\n", N);

    return 0;
}
Sample Output
Enter R, F(p), n(e), f(l), f(i), f(c): 5 0.25 20 0.2 0.15 0.11 150
The number of communicative civilizations within the Milky Way today: 12.375

Lab Task: MID TERM [20 Marks] | Assignment - June 2021

1. [5] Write a C program to solve the Drake equation N = R*fp*ne*fl*fi*fc*L. Where R, ne and L must be discrete value

Sample Input

    Enter R, F(p), n(e), f(l), f(i), f(c), L: 5 0.25 20 0.2 0.15 0.11 150

Sample Output

    The number of communicative civilizations within the Milky Way today: 12.375

2. [7] Write a C Code to calculate D = 𝒃^𝟐 − 𝟒𝐚𝐜 and show the result according to following conditions:

a. D>0 then Calculate X1, X2. Where 𝒙𝟏 = (−𝒃+√𝒃^𝟐−𝟒𝒂𝒄)/𝟐𝒂 and 𝒙𝟐 = (−𝒃−√𝒃^𝟐−𝟒𝒂𝒄)/𝟐𝒂

        b. D =0 then calculate X. Where 𝐱 = 𝒃^𝟐/𝟐𝒂

        c. D<0 then print “No Solution”.

Sample Input

        Enter a, b & c: 5 6 1

Sample Output

    X1: -0.2

    X2: -1

3. [8] Write a C Code to find total marks from given input: Attendance, Class test, Quiz test, Assignment, Midterm and Final Exam and find the grade using the following method:

  1. If Total mark >=80 then A+
  2. If Total mark >=70 then A
  3. If Total mark >=60 then A
  4. If Total mark >=50 then B
  5. Else Grade = F

Sample Input

Enter Attendance, Class test, Quiz test, Assignment, Midterm and Final Exam: 2.5 7.5 3.5 7 21.5 33

Sample Output

Total Mark: 75 & Grade: A

Change Theme
X