哥哥姐姐们帮个忙 做一道高级程序语言设计(C语言)的题目 谢谢了
发布网友
发布时间:2022-05-10 15:42
我来回答
共4个回答
热心网友
时间:2023-10-14 03:30
#include <stdio.h>
/*
{ 2x+1 (1<=x<10)
y= { 3x+2 (11<x<=20)
{ 4x+3 (21<x<30)
*/
void main()
{
int X,Y;
while(scanf("%d",&X)!=EOF)
{
if(X<1||X>=30)
{
printf("X should in the Range [1,29]\n");
continue;
}
if(1<=X&&X<10)
printf("Y = %d\n",2*X+1);
else
if(X<=20)
printf("Y = %d\n",3*X+2);
else
printf("Y = %d\n",4*X + 3);
}
}
热心网友
时间:2023-10-14 03:31
#include <stdio.h>
void main()
{
float x,y;
printf("please enter x:\n");
scanf("%f",&x);
if(x>=1&&x<10)
y=2*x+1;
else if(x>11&&x<=20)
y=3*x+2;
else if(x>21&&x<30)
y=4*x+3;
else {printf("an error number,please enter x again:\n");scanf("%f",&x);}
printf("y is %f",y);
}
热心网友
时间:2023-10-14 03:31
#include <stdio.h >
void main()
{
int x,y;
scanf("%d",&x);
if(x>=1&&x<10)
y=2*x+1;
else if(x>=11&&x<=20)
y=3*x+2;
else if(x>21&&x<30)
y=4*x+3;
printf("%d",y);
else
printf("out of the x!");
}
可以直接运行··
热心网友
时间:2023-10-14 03:32
#include "stdio.h"
void main()
{
double x, y;
printf("Type in x or this function:\n");
scanf("%f",&x);
if(x<10&&x>=1){
y=2*x+1;
printf("the value of y equals 2x+1, thus %f\n",y);
}
else if (x<=20&&x>11){
y=3*x+2;
printf("the value of y equals 3x+2, thus %f\n",y);
}
else if (x>21&&x<30){
y=4*x+3;
printf("the value of y equals 4x+3 , thus %f\n",y);
}
else printf("This x is out of bound!!\n");
printf("push any key to exit...\n");
getch();
exit(0);
}