C程序设计第四章作业6

程序员成长之旅 · 程序员成长之旅/C语言/习题(C语言程序设计)/第四章习题 · 138 字

问:

输入x 求y,要求如下:

答:

#include<stdio.h>

int main()

{

int x=0000.0000, y=0000.0000, Error1=0;

Error1 = scanf("%d", &x);

if (Error1 == 0)

{

setbuf(stdin, NULL);

printf("You enter data is error!\n");

exit();

}

if (x < 1)

{

printf("You enter X:[%d],Y:[%d]\n", x, y);

}

else if (x >= 1 && x < 10)

{

printf("You enter X:[%d],Y:[%d]\n", x, 2*x-1);

}

else if (x >= 10)

{

printf("You enter X:[%d],Y:[%d]\n", x, 3*x-11);

}

else

{

setbuf(stdin, NULL);

printf("You enter data is error!\n");

}

return 0;

}