从键盘输入一个4个位的正整数存入x,如果x的值不小于5000,则输出x*2-1的值;如果x的值在2000到4000之间,则将x的值循环左移1个位后输出,如x等于2345,则输出3452;x的其它值则将x的值原样输出。
答案如下:
#include "stdio.h"
void main()
{
int x;
printf("请输入一个数:");
scanf("%d", &x);
if (x >= 5000)
{
printf("x*2-1 = %d\n", x * 2 - 1);
}
else if (x >= 2000 && x <= 4000)
{
int temp = x / 1000;
x = x % 1000 * 10 + temp;
printf("x循环左移后值为:%d\n", x);
}
else
printf("x原样输出:%d\n", x);
}
if…else就行