#include<stdio.h>
#include<conio.h>
float trapezoidarea(void)
{
float side1,side2,high,area;
printf("Enter side1 : ");
scanf("%f",&side1);
printf("Enter side2 : ");
scanf("%f",&side2);
printf("Enter high : ");
scanf("%f",&high);
area = ((side1+side2)*high)/2;
return(area);
}
main()
{
float area;
area = trapezoidarea();
printf("Trapezoid Area is %.2f\n",area);
getch();
}
การบ้าน หน้า23
#include<stdio.h>
#include<conio.h>
#include<math.h>
float power(float n);
float sqroot(float n);
main()
{
float n;
int c;
printf("Enter number : ");
scanf("%f",&n);
printf("Please select choice( 1=power, 2=square root) : ");
scanf("%d",&c);
if(c==1)
{
power(n);
}
else if(c==2)
{
sqroot(n);
}
else
{
printf("Menu Error!!");
}
getch();
}
float power(float n)
{
float mypow;
mypow=pow(n,2);
printf("Result = %.2f ",mypow);
return(mypow);
}
float sqroot(float n)
{
float mysqrt;
mysqrt=sqrt(n);
printf("Result = %.2f ",mysqrt);
return(mysqrt);
}
การบ้าน หน้า 27
#include<stdio.h>
#include<conio.h>
char cal_grade(float score);
main()
{
float score;
char grade;
printf("Enter score : ");
scanf("%f",&score);
grade = cal_grade(score);
printf("You get %c !!!",grade);
getch();
}
char cal_grade(float score)
{
char grade;
if (score>=80)
{
grade = 'A';
}
else if (score>=70&&score<80)
{
grade = 'B';
}
else if (score>=60&&score<70)
{
grade = 'C';
}
else if (score>=50&&score<60)
{
grade = 'D';
}
else if (score<50)
{
grade = 'F';
}
return(grade);
}
การบ้าน หน้า28
#include<stdio.h>
#include<conio.h>
float myavg(void)
{
float a,b,avg;
printf("Enter a : ");
scanf("%f",&a);
printf("Enter b : ");
scanf("%f",&b);
avg = (a+b)/2;
return(avg);
}
main()
{
float avg;
avg = myavg();
printf("Average is %.2f\n",avg);
getch();
}
#include<conio.h>
float myavg(void)
{
float a,b,avg;
printf("Enter a : ");
scanf("%f",&a);
printf("Enter b : ");
scanf("%f",&b);
avg = (a+b)/2;
return(avg);
}
main()
{
float avg;
avg = myavg();
printf("Average is %.2f\n",avg);
getch();
}
การบ้าน ข้อที่1
#include<stdio.h>
#include<conio.h>
int findmax(int n1,int n2);
main()
{
int n1,n2,ans;
printf("Enter number1 : ");
scanf("%d",&n1);
printf("Enter number2 : ");
scanf("%d",&n2);
ans = findmax(n1,n2);
printf("The max number is %d",ans);
getch();
}
int findmax(int num1,int num2)
{
int max;
if (num1 > num2)
{
max = num1;
}
else if (num2 > num1)
{
max = num2;
}
return(max);
}
#include<conio.h>
int findmax(int n1,int n2);
main()
{
int n1,n2,ans;
printf("Enter number1 : ");
scanf("%d",&n1);
printf("Enter number2 : ");
scanf("%d",&n2);
ans = findmax(n1,n2);
printf("The max number is %d",ans);
getch();
}
int findmax(int num1,int num2)
{
int max;
if (num1 > num2)
{
max = num1;
}
else if (num2 > num1)
{
max = num2;
}
return(max);
}
ไม่มีความคิดเห็น:
แสดงความคิดเห็น