Assignment 2
Problem 1: Write a program in C that accepts the marks of 5 subjects and finds the sum and percentage marks obtained by the student.
sol.
#include<stdio.h>
#include<math.h>
float main()
{
float Maths,Programming,Ecology,Physics,Graphics,Percentage,Sum;
printf("Maths=");
scanf("%f",&Maths);
printf("Programming=");
scanf("%f",&Programming);
printf("Ecology=");
scanf("%f",&Ecology);
printf("Physics=");
scanf("%f",&Physics);
printf("Graphics=");
scanf("%f",&Graphics);
Sum=Maths+Programming+Ecology+Physics+Graphics;
Percentage= (Sum/500)*100;
printf("Sum=%f\nPercentage=%f",Sum ,Percentage);
return 0;
}
Problem 2: Write a program in C that calculates the Simple Interest and Compound Interest. The Principal Amount, Rate of Interest and Time are entered through the keyboard.
sol.
#include<stdio.h>
#include<math.h>
float main()
{
float principal,rate,time,compound,simple;
printf("The Principal = ");
scanf("%f",&principal);
printf("Rate of Interest = ");
scanf("%f",&rate);
printf("Time = ");
scanf("%f",&time);
//simple interest formula code
simple=(principal*rate*time)/100;
printf("Simple Interst is %f \n",simple);
//compound interest formula code
compound=((pow((rate/100+1),time))-1)*principal;
printf("Compound Interst is %f",compound);
return 0;
}
Problem 3: Write a program in C to calculate the area and circumference of a circle..
sol.
#include<stdio.h>
#include<math.h>
float main( )
{
float radius, area, circumference;
printf("enter the radius of the circle: ");
scanf("%f", &radius);
//code for area of circle.
area=3.14*pow(radius,2);
printf("The area of the circle is: %f sqaure units\n", area);
//code for circumference of the circle.
circumference=2*3.14*radius;
printf("The circumference of the circle is: %f \n", circumference);
return 0;
}
Problem 4: Write a program in C that accepts the temperature in Centigrade and converts into Fahrenheit using the formula, C/5=(F-32)/9.
sol.
#include<stdio.h>
int main( ) {
float celsius, fahrenheit;
printf("Enter temperature in Celsius: ");
scanf("%f", &celsius);
// Convert Celsius to Fahrenheit using the formula C/5=(F-32)/9
fahrenheit = (celsius * 9/5) + 32;
printf("Temperature in Fahrenheit: %.2f\n", fahrenheit);
return 0;
}
Problem 5: Write a program in C that swaps values of two variables using a third variable.
sol.
#include <stdio.h>
int main()
{
int first, second, temp;
printf("Enter the first variable: ");
scanf("%d", &first);
printf("Enter the second variable: ");
scanf("%d", &second);
// Swap the values using a third variable
temp = first;
first = second;
second = temp;
printf("After swapping:\n");
printf("First variable: %d\n", first);
printf("Second variable: %d\n", second);
return 0;
}
0 comments:
Post a Comment