Grade 6 Programs

1. Program to find the area of a rectangle

#include <stdio.h>  // Header file for input and output functions

int main() {
    float length, breadth, area;  // Variables to store length, breadth, and area

    // Asking the user to enter length and breadth
    printf("Enter the length of the rectangle: ");
    scanf("%f", &length);

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

    // Formula for area of rectangle = length * breadth
    area = length * breadth;

    // Displaying the result
    printf("Area of the rectangle = %.2f\n", area);

    return 0;  // End of program
}

2. Program to find the area of a triangle

#include <stdio.h>

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

    // Asking the user for base and height
    printf("Enter the base of the triangle: ");
    scanf("%f", &base);

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

    // Formula for area of triangle = 1/2 * base * height
    area = 0.5 * base * height;

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

    return 0;
}

3. Program to calculate total and average of 3 subjects

#include <stdio.h>

int main() {
    float subject1, subject2, subject3, total, average;

    // Asking the user to enter marks for 3 subjects
    printf("Enter marks for subject 1: ");
    scanf("%f", &subject1);

    printf("Enter marks for subject 2: ");
    scanf("%f", &subject2);

    printf("Enter marks for subject 3: ");
    scanf("%f", &subject3);

    // Total = sum of all 3 subjects
    total = subject1 + subject2 + subject3;

    // Average = total / number of subjects (3)
    average = total / 3;

    // Displaying results
    printf("Total marks = %.2f\n", total);
    printf("Average marks = %.2f\n", average);

    return 0;
}

4. Program to convert temperature from Celsius to Fahrenheit

#include <stdio.h>

int main() {
    float celsius, fahrenheit;

    // Asking the user to enter temperature in Celsius
    printf("Enter temperature in Celsius: ");
    scanf("%f", &celsius);

    // Formula: Fahrenheit = (Celsius * 9/5) + 32
    fahrenheit = (celsius * 9 / 5) + 32;

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

    return 0;
}

Here are the next two C programs — simple, clear, and with helpful comments for grade 6 students.


5. Program to calculate Gross Salary

#include <stdio.h>

int main() {
    float basic, da, ta, gross;

    // Asking the user to enter the basic salary
    printf("Enter basic salary of the employee: ");
    scanf("%f", &basic);

    // DA = 12% of basic salary
    da = basic * 12 / 100;

    // TA = 10% of basic salary
    ta = basic * 10 / 100;

    // Gross salary = Basic + DA + TA
    gross = basic + da + ta;

    // Displaying all calculated values
    printf("Dearness Allowance (DA) = %.2f\n", da);
    printf("Travel Allowance (TA) = %.2f\n", ta);
    printf("Gross Salary = %.2f\n", gross);

    return 0;
}

Explanation for students:

  • DA means Dearness Allowance (12% of basic).

  • TA means Travel Allowance (10% of basic).

  • Gross Salary = Basic Salary + DA + TA.


6. Program to find Area and Circumference of a Circle

#include <stdio.h>

int main() {
    float radius, area, circumference;
    float pi = 3.14;  // Value of pi (you can use 3.1416 for more accuracy)

    // Asking the user to enter radius of the circle
    printf("Enter the radius of the circle: ");
    scanf("%f", &radius);

    // Formula for area = pi * r * r
    area = pi * radius * radius;

    // Formula for circumference = 2 * pi * r
    circumference = 2 * pi * radius;

    // Displaying results
    printf("Area of the circle = %.2f\n", area);
    printf("Circumference of the circle = %.2f\n", circumference);

    return 0;
}

Explanation for students:

  • Area = π × radius × radius

  • Circumference = 2 × π × radius

  • π (pi) is a constant, approximately 3.14.


Comments

Popular posts from this blog

NCERT GRADE 10

NCERT GRADE 9

Class 9 Part B Term 2