Uploaded by Avish Lamsal

c program computer

advertisement
PROJECT WORK
ON
MENU DRIVEN C PROGRAM
For partial fullfillment of
Second Terminal Examination – 2078
Submitted to
Submitted by
Mr Rajkumar sir
Mr Ayush Lamsal
Computer department
class 12 D4
HIMALAYAN WHITEHOUSE INTERNATIONAL COLLEGE
ACKNOWLEDGEMENT :
• I would like to express my special thanks of gratitude to my teacher RK sir ,
who gave me the golden opportunity to do this wonderful project ,which also
helped me in doing a lot of Research and i came to know about so many new
things I am really thankful to them.
Secondly i would also like to thank my classmate Rajat and who helped me a lot
in finalizing this project within the limited time frame.
Table of content :
1.To check whether the given number is odd or even.
2. To find the multiplication table from 1 to 10 number
3. To calculate arithmetic operation (Example: Addition, Subtraction,
Multiplication, (Division-Integer, Decimal, Modular)).
4. Area and perimeter of Rectangle.
5. Area and Perimeter of Circle.
6. Area of Triangle.
7. Curved Surface area of Cylinder.
8. Simple and Compound Interest.
9. Exit.
1.To check whether the given number is odd or even.
#include <stdio.h>
int main() {
int num;
printf("Enter an integer: ");
scanf("%d", &num);
// true if num is perfectly divisible by 2
if(num % 2 == 0)
printf("%d is even.", num);
else
printf("%d is odd.", num);
return 0;
}
OUTPUT :
2. To find the multiplication table from 1 to 10 number
#include <stdio.h>
int main() {
int n, i;
printf("Enter an integer: ");
scanf("%d", &n);
for (i = 1; i <= 10; ++i) {
printf("%d * %d = %d \n", n, i, n * i);
}
return 0;
}
3. To calculate arithmetic operation (Example: Addition, Subtraction
Multiplication, (Division-Integer, Decimal, Modular)).
• #include <stdio.h>
• int main()
{
int first, second, add, subtract, multiply;
float divide;
printf("Enter two integers\n");
scanf("%d%d", &first, &second);
add = first + second;
subtract = first - second;
multiply = first * second;
divide = first / (float)second; //typecasting, you can also write: divide = (float)first/second
printf("Sum = %d\n", add);
printf("Difference = %d\n", subtract);
printf("Multiplication = %d\n", multiply);
printf("Division = %.2f\n", divide); // "%.2lf" to print two decimal digits, by default (%lf) we get six
•
}
return 0;
3. To calculate arithmetic operation (Example:
Addition, Subtraction,
Multiplication, (Division-Integer, Decimal,
Modular)).
Output
4. Area and perimeter of Rectangle.
#include <stdio.h>
int main()
{
/*declare the variables*/
float length;
float breadth;
float area;
float perimeter;
/*length input*/
printf("Enter the length: ");
scanf("%f", &length);
/*breadth input*/
printf("Enter the breadth: ");
scanf("%f", &breadth);
/*Calculating the area and rectangle*/ area = length * breadth;
perimeter = (2 * length) + (2 * breadth);
/*printing the result*/
printf("Area of the rectangle: %.02f\n", area);
printf("Perimeter of rectangle: %.02f\n", perimeter);
return 0;
}
5. Area and Perimeter of Circle
#include<stdio.h>
int main() {
float r, Area, Perimeter;
printf(“Enter the radius of circle”);
scanf(“%f”,&r);
Area = 3.14*r*r;
Perimeter=2*3.14*r;
printf(“the area of the circle is %f\n”,Area);
printf(“the circumference of the circle is %f\n”,Perimeter);
return 0;
}
6. Area of Triangle
#include <stdio.h>
#include <math.h>
int main()
{
double a, b, c, s, area;
printf("Enter sides of a triangle\n");
scanf("%lf%lf%lf", &a, &b, &c);
s = (a+b+c)/2; // Semiperimeter
area = sqrt(s*(s-a)*(s-b)*(s-c));
printf("Area of the triangle = %.2lf\n", area);
return 0;
}
7. Curved Surface area of Cylinder
• #include<stdio.h>
•
• int main()
• {
•
const float PI = 3.14;
•
float r, h, Area;
•
•
printf("Enter Radius and Height of the Cylinder\n");
•
scanf("%f%f", &r, &h);
•
•
Area = (2 * PI * r * h) + (2 * PI * r * r);
•
•
printf("Surface Area of Cylinder is %f\n", Area);
•
•
• }
return 0;
8. Simple and Compound Interest.
#include<stdio.h>
#include<conio.h>
void main()
{
int p,r,t;
float i;
printf("Enter the Principal, Rate and Time\n");
scanf("%d %d %d",&p,&r,&t);
/*Formula for calculating simple interest*/
i=p*r*t/100;
printf("simple interest is : %f",i);
getch();
}
Enter the Principal, Rate and Time
1000
7
8
simple interest is : 560.00000
9. Exit.
#include <stdio.h>
#include <stdlib.h>
int main () {
printf("Start of the program....\n");
printf("Exiting the program....\n");
exit(0);
printf("End of the program....\n");
return(0);
}
Start of the program....
Exiting the program....
Download