C语言高手请帮忙看一下!

来源:百度知道 编辑:UC知道 时间:2024/06/25 19:58:02
请帮忙看一下这三道题吧,能答对了差不多就行,谢谢高手了!

二、编程序计算下面的分段函数(参考选择语句的知识,第三章)
x x < 1)
y = 2x-2 (1=< x < 10)
2x-20 (x >=10)

三、使用嵌套循环输出下列图像:(参考第五章‘循环嵌套’)
*
***
*****
*******
*********

四、定义一个可以容纳以下数据的联合(参考‘结构体与联合体’,第八章)
float f
char ch[10]
int date
第一个题分段函数那个,写的有点不太清楚,这里重发一下。

x x < 1)
y = 2x-2 (1=< x < 10)
2x-20 (x >=10)

1
#include<stdio.h>
void main()
{
int x,y;
printf("Please input number:\n");
scanf("%d",&x);
if(x<1)
y=x;
else if(x>=1&&x<10)
y=2*x-2;
else
y=2*x-20;
printf("y=%d\n",y);
}

2
#include<stdio.h>
void main()
{
int i,j;
for(i=0;i<5;i++){
for(j=4;j>i;j--)
printf(" ");
for(j=0;j<i*2+1;j++)
printf("*");
printf("\n");
}
}

3
struct A
{
float f;
char ch[10];
int date;
};

1.
#include<stdio.h>
main()
{int x,y;
printf("pls input the value of x:\n");
scanf("%d",&x);
printf("the value of x is %d\n",x);
if(x<1)
y=x;
else if ((x>=1)&&(x<10))
y=2*x-2;
else
y=2*x-20;