Location via proxy:   [ UP ]  
[Report a bug]   [Manage cookies]                
0% found this document useful (0 votes)
9 views

Subjective Assignment 02 Basic Programs 02 Ans

The document provides solutions to 7 subjective questions in C programming. Each question asks the user to write a C program to perform a specific task like calculating the area of a triangle, compound interest etc. For each question, it gives the expected input/output and provides the C code as the solution.

Uploaded by

Yash rai
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
9 views

Subjective Assignment 02 Basic Programs 02 Ans

The document provides solutions to 7 subjective questions in C programming. Each question asks the user to write a C program to perform a specific task like calculating the area of a triangle, compound interest etc. For each question, it gives the expected input/output and provides the C code as the solution.

Uploaded by

Yash rai
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 7

Assignment of Subjective questions

1. Write a C program to input a number and find square root of the given number.

Example
Input
Enter any number: 9
Output

Square root of 9 = 3

Solution -

#include <stdio.h>
#include <math.h>

int main()
{
double num, root;

/* Input a number from user */


printf("Enter any number to find square root: ");
scanf("%lf", &num);

/* Calculate square root of num */


root = sqrt(num);

/* Print the resultant value */


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

return 0;
}
2. Write a C Program to input two angles from user and find third angle of the
triangle.

Example
Input
Enter first angle: 60
Enter second angle: 80
Output

Third angle = 40

Solution -

#include <stdio.h>

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

/* Input two angles of the triangle */


printf("Enter two angles of triangle: ");
scanf("%d%d", &a, &b);

/* Compute third angle */


c = 180 - (a + b);

/* Print value of the third angle */


printf("Third angle of the triangle = %d", c);

return 0;
}
3. Write a C program to input base and height of a triangle and find area of the
given triangle.

Example
Input
Enter base of the triangle: 10
Enter height of the triangle: 15
Output

Area of the triangle = 75 sq. units

Solution -

#include <stdio.h>

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

/* Input base and height of triangle */


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

/* Calculate area of triangle */


area = (base * height) / 2;

/* Print the resultant area */


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

return 0;
}
4. Write a C program to input side of an equilateral triangle from user and find
area of the given triangle.

Example
Input

Enter side of the equilateral triangle: 10


Output

Area of equilateral triangle = 43.3 sq. units

Solution -

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

int main()
{
float side, area;

/* Input side of equilateral triangle */


printf("Enter side of an equilateral triangle: ");
scanf("%f", &side);

/* Calculate area of equilateral triangle */


area = (sqrt(3) / 4) * (side * side);

/* Print resultant area */


printf("Area of equilateral triangle = %.2f sq. units", area);

return 0;
}
5. Write a C program to input marks of five subjects of a student and calculate
total, average and percentage of all subjects.

Example
Input
Enter marks of five subjects: 95 76 85 90 89
Output

Total = 435
Average = 87
Percentage = 87.00

Solution -

#include <stdio.h>

int main()
{
float eng, phy, chem, math, comp;
float total, average, percentage;

/* Input marks of all five subjects */


printf("Enter marks of five subjects: \n");
scanf("%f%f%f%f%f", &eng, &phy, &chem, &math, &comp);

/* Calculate total, average and percentage */


total = eng + phy + chem + math + comp;
average = total / 5.0;
percentage = (total / 500.0) * 100;

/* Print all results */


printf("Total marks = %.2f\n", total);
printf("Average marks = %.2f\n", average);
printf("Percentage = %.2f", percentage);

return 0;
}
6. Write a C program to input principle, time and rate (P, T, R) from user and find
Simple Interest.

Example
Input
Enter principle: 1200
Enter time: 2
Enter rate: 5.4
Output

Simple Interest = 129.600006

Solution -

#include <stdio.h>

int main()
{
float principle, time, rate, SI;

/* Input principle, rate and time */


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

printf("Enter time: ");


scanf("%f", &time);

printf("Enter rate: ");


scanf("%f", &rate);

/* Calculate simple interest */


SI = (principle * time * rate) / 100;

/* Print the resultant value of SI */


printf("Simple Interest = %f", SI);

return 0;
}
7. Write a C program to input principle (amount), time and rate (P, T, R) and find
Compound Interest.

Example
Input
Enter principle (amount): 1200
Enter time: 2
Enter rate: 5.4
Output

Compound Interest = 1333.099243

Solution -

#include <stdio.h>
#include <math.h>

int main()
{
float principle, rate, time, CI;

/* Input principle, time and rate */


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

printf("Enter time: ");


scanf("%f", &time);

printf("Enter rate: ");


scanf("%f", &rate);

/* Calculate compound interest */


CI = principle* (pow((1 + rate / 100), time));

/* Print the resultant CI */


printf("Compound Interest = %f", CI);

return 0;
}

You might also like