求解C语言编程题。。。
3个回答
展开全部
#include <stdio.h>
int main()
{
float score = 0;
if(scanf("%f", &score) != 1)
{
puts("error");
return -1;
}
if(score > 100 || score < 0)
{
puts("score error");
return -1;
}
switch(score/10) //两个整数运算结果一定是个整数
{
case 10:
case 9:puts("A");break; //break:当前是用于跳出switch语句
case 8:puts("B");break;
case 7:puts("C");break;
case 6:puts("D");break;
default:puts("E");
}
return 0;
}
展开全部
#include
void dec2bin(unsigned int n, char * buff)
{
char *p = buff;
char tmp;
do {
*p++ = n % 2 == 0 ? '0' : '1';
n /= 2;
} while (n>0);
*p-- = '\0';
while (buff < p)
{
tmp = *p;
*p = *buff;
*buff = tmp;
p--;
buff++;
}
}
int main()
{
unsigned int n;
char buff[sizeof(int) * 8 +1];
scanf("%u", &n);
dec2bin(n, buff);
printf("%s\r\n", buff);
return 0;
}
void dec2bin(unsigned int n, char * buff)
{
char *p = buff;
char tmp;
do {
*p++ = n % 2 == 0 ? '0' : '1';
n /= 2;
} while (n>0);
*p-- = '\0';
while (buff < p)
{
tmp = *p;
*p = *buff;
*buff = tmp;
p--;
buff++;
}
}
int main()
{
unsigned int n;
char buff[sizeof(int) * 8 +1];
scanf("%u", &n);
dec2bin(n, buff);
printf("%s\r\n", buff);
return 0;
}
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
展开全部
#include
int main()
{
int x, i, t, s;;
int cnt=0;
scanf("%d", &x);
for (i=100; i<1000; ++i)
{
t=i;
s=0;
while (t)
{
s+=t%10;
t/=10;
}
if (x==s)
{
++cnt;
printf("%5d", i);
if (cnt%4==0)
printf("\n");
}
}
printf("\n合计公有:%d个\n",cnt);
return 0;
}
int main()
{
int x, i, t, s;;
int cnt=0;
scanf("%d", &x);
for (i=100; i<1000; ++i)
{
t=i;
s=0;
while (t)
{
s+=t%10;
t/=10;
}
if (x==s)
{
++cnt;
printf("%5d", i);
if (cnt%4==0)
printf("\n");
}
}
printf("\n合计公有:%d个\n",cnt);
return 0;
}
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询