ข้อ 1 (page 23)
#include<stdio.h>
#include<conio.h>
#include<math.h>
float n2=2;
float power(float n1,float n2)
{
float c;
c=pow(n1,n2);
return(c);
}
float sqroot(float n1)
{
float a;
a=sqrt(n1);
return(a);
}
main()
{
int num2,num3=2;
float num1,result,ans;
printf("Enter number : ");
scanf("%f",&num1);
printf("Please select choice (1 = power , 2 = square root) : ");
scanf("%d",&num2);
if(num2==1)
{
result=power(num1,num3);
printf("Result = %.2f",result);
getch();
}
else
{
if(num2==2)
{
result=sqroot(num1);
printf("Result = %.2f",result);
getch();
}
else
{
printf("Menu Error!!!");
getch();
}
}
}
ข้อ 2 (page 27 )
#include<stdio.h>
#include<conio.h>
char cal_grade(float score);
main()
{
float x;
char grade;
printf("Enter score : ");
scanf("%f",&x);
grade=cal_grade(x);
printf("You get %c !!!",grade);
getch();
}
char cal_grade(float score)
{
char grade;
if(80<=score&&score<=100)
{
grade='A';
}
else
{
if(70<=score&&score<=79)
{
grade='B';
}
else
{
if(60<=score&&score<=69)
{
grade='C';
}
else
{
if(50<=score&&score<=59)
{
grade='D';
}
else
{
grade='F';
}
}
}
}
return(grade);
}
ข้อ 3 (page 28)
#include<stdio.h>
#include<conio.h>
float cal_avg(float x,float y);
main()
{
float a,b,c;
printf("Enter a : ");
scanf("%f",&a);
printf("Enter b : ");
scanf("%f",&b);
c=cal_avg(a,b);
printf("Average is %f",c);
getch();
}
float cal_avg(float x,float y)
{
float sum,avg;
sum=x+y;
avg=sum/2;
return(avg);
}
ข้อ 4
#include<stdio.h>
#include<conio.h>
int findmax(int x,int y);
main()
{
int a,b,c;
printf("Enter number 1 : ");
scanf("%d",&a);
printf("Enter number 2 : ");
scanf("%d",&b);
c=findmax(a,b);
printf("Max is %d",c);
getch();
}
int findmax(int x,int y)
{
int i;
if(x<y)
{
i=y;
}
else
{
i=x;
}
return(i);
}
Xn Completive Casino Login - xn--o80b910a26eepc81il5g.online
ตอบลบXn Completive Casino Login. Login Xn Completive 메리트 카지노 주소 Casino Log In To Online Casino. Login. Xn Completive Casino Log In To Online Casino. Login.