# DAY7 C language - function call (HQYJ)

##### Homework 1: Define the implementation of a function with parameters and no return value. The calling function passes the three sides of the triangle, and the called function judges them to determine whether a triangle can be formed. If a triangle can be formed, determine whether the triangle is an equilateral triangle or an isosceles triangle. A triangle is still a half triangle. If a triangle cannot be formed, the output cannot be triangulated.
```#include <stdio.h>
#include <math.h>

void IsTriangle(double a, double b, double c);

int main(int argc, char const *argv[])
{
double a,b,c;
printf("Please enter the side lengths of the three sides of the triangle:");
scanf("%lf%lf%lf",&a,&b,&c);
IsTriangle(a,b,c);
return 0;
}

void IsTriangle(double a, double b, double c)
{
//Whether the triangle is established or not
if(a>0&&b>0&&c>0&&(a+b>c)&&(b+c>a)&&(a+c>b))
{
//Equilateral Triangle Judgment Conditions
if(a==b&&b==c)
{
printf("The triangle is an equilateral triangle!\n");
}
//Isosceles triangle judgment condition
else if (a==b||b==c||a==c)
{
printf("The triangle is an isosceles triangle!\n");
}
//Conditions for judging a right triangle
else if((pow(a,2)+pow(b,2)==pow(c,2))||(pow(b,2)+pow(c,2)==pow(a,2))||(pow(a,2)+pow(c,2)==pow(b,2)))
{
printf("The triangle is a right triangle!\n");
}
else
{
printf("This triangle is a normal triangle!\n");
}

}
else
{
printf("Cannot form a triangle! ! !\n");
}
}```

##### It is required to input the electricity consumption in the calling function, and output the electricity fee to be paid in the called function
```#include <stdio.h>

void Caculate_Electric(double a);

int main(int argc, char const *argv[])
{
double electri_fee;
scanf("%lf",&electri_fee);
Caculate_Electric(electri_fee);

return 0;
}

void Caculate_Electric(double a)
{
double money;
if(a >= 1 && a <= 100)
{
money = a*0.35;
}
else if (a > 100 && a <= 200)
{
money = 100*0.35+(a-100)*0.46;
}
else
{
money = 100*0.35+100*0.46+(a-200)*0.68;
}
}```

##### Homework 3: Define a function with parameters and no return value, complete the input string in the main function, pass the array name as a function parameter, and store the numeric characters in the string into a new array in the called function, and count the odd and even numbers respectively Number, sum, average output.
```#include <stdio.h>

void character(char A[],int n);

int main(int argc, char const *argv[])
{
char str[80];
gets(str);
character(str,strlen(str));

return 0;
}

void character(char A[],int n)
{
char B[n];
int j = 0;  //number of numbers
int odd = 0,even = 0;   //odd number even number
int sum = 0;
printf("The numbers in this string are:\n");
for(int i = 0; i < n; i++)
{
if(A[i]>='0'&&A[i]<='9')
{
B[j] = A[i];
printf("%c\t",B[j]);
sum += B[j]-'0';
if((B[j]-'0')%2==0)
even++;
else
odd++;
j++;
}
}
printf("\n where odd numbers have%d indivual,Even number has%d indivual\n",odd,even);
printf("\n and:%d,average value:%lf\n",sum,(double)sum/j);
}```

##### Call the custom function with parameters and return value, and after calculating the total score, output the total score in the calling function
```#include <stdio.h>

void Data_Entry(double A[],int n);  //Data Entry
void Data_Output(double A[],int n); //data printing
void BubbleSort(double A[],int n);  //Bubble Sort

int main(int argc, char const *argv[])
{
printf("\n<-------------------delimiter------------------->\n");
printf("\n The entered student grades are as follows:\n");
printf("\n<-------------------delimiter------------------->\n");
printf("\n<-------------------delimiter------------------->\n");

return 0;
}

//Data Entry
void Data_Entry(double A[],int n)
{
for(int i = 0; i < n;)
{
scanf("%lf",&A[i]);
if(A[i]>=0 && A[i]<=100){
i++;
}else{
printf("Input error, please re-enter! ! !\n");
}
}
}

//data printing
void Data_Output(double A[],int n)
{
for (int i = 0; i < n; i++)
{
printf("%.1lf\t",A[i]);
}
printf("\n");
}

//Bubble Sort
void BubbleSort(double A[],int n)
{
double temp;
for (int i = 1; i <= n-1; i++)  //External passes
{
int flag = 0;       //A flag indicating whether the current bubbling has changed
for (int j = 0; j < n-i; j++)
{
if(A[j] > A[j+1])   //Reverse order of each other
{
//exchange
temp = A[j];
A[j] = A[j+1];
A[j+1] = temp;

flag = 1;   //Indicates that a transformation has occurred
}
}
if(flag == 0)
break;
}
Data_Output(A,6);
}