C语言基础编程求教

来源:百度知道 编辑:UC知道 时间:2024/05/27 16:53:40
1. Write a function num_digits_in_base which takes an decimal integers x and b. The function returns the number
of digits required to represent the decimal integer x in base-b notation. For example: The decimal value 18 in base
10 requires 2 digits. When represented in base 2, 18 is represented as 10010, requires 5 binary digits (or bits). When
represented in base 4, 18 is represented as 102, requires 3 digits. You may assume that the input x is always a positive
integer and b is greater than or equal to 2.
Write a program that reads an input file, named “input_file.txt”. The file contains two numbers x and b. Your program
must read these two numbers from the file and output the number of digits required to express the decimal
number x in base b to an output file, named “output_file.txt”. Call this program number-digits.c.
2. Write a program that takes three distance values a, b, and c and identifies if a triangle can be formed whose sides
h

第一题没看懂
第二题
#include<stdio.h>
void main()
{
int a,b,c;
printf("请输入三边长\n");
scanf("%d %d %d",&a,&b,&c);
if((a+b)>c&&(a+c)>b&&(b+c)>a)
{
printf("能构成三角形\n");
if(a==b&&b==c)
printf("是等边三角形\n");
else
{
if(a==b||b==c||c==a)
printf("等腰三角形\n");
else printf("不是等腰三角形\n");
if((a*a+b*b)==c*c||(c*c+b*b)==a*a||(a*a+c*c)==b*b)
{
printf("直角三角形\n");
}
else printf("不是直角三角形\n");
}

}
else printf("不能构成三角形,不适用等边等腰直角三角形\n");
}
第三题
#include<stdio.h>
void main()
{
int x1,y1,x2,y2,y3,x3;
printf("请输入三点x1 y1 x2 y2 x3 y3\n");
scanf("%d %d %d %d %d %d",&x1,&y1,&x2,&y2,&x3,&y3);
if((x1-x2)/(y1-y2)==(x1-x3)/(y1-y3)||(x1-x2)/(y1-y2)==(x3-x