//任意输入一个整数,算出它的位数, 例如12345,5位
#include <stdio.h>
int main(void)
{
int number, i=0;
printf("任意输入一个整数:\n");
scanf("%d", &number);
do
{
number = number / 10;
i++;
}while(number);
printf("位数为:%d", i);
}
42楼
//输入3个整数a,b,c,然后交换他们的值,使得a存放b的值,b存放c的值,c存放a的值
#include <stdio.h>
int main(void)
{
int a, b, c, t;
printf("输入3个整数的值:");
scanf("%d", &a);
scanf("%d", &b);
scanf("%d", &c);
t = a;
a = b;
b = c;
c = t;
printf("%d, %d, %d", a, b, c);
}
#include <stdio.h>
int main(void)
{
int a, b, c, t;
printf("输入3个整数的值:");
scanf("%d", &a);
scanf("%d", &b);
scanf("%d", &c);
t = a;
a = b;
b = c;
c = t;
printf("%d, %d, %d", a, b, c);
}
43楼
//输入年,月,输出这个月有多少天
#include <stdio.h>
int main(void)
{
int year, mon;
char flag = 0;
printf("输入年和月:");
scanf("%d %d", &year, &mon);
if((year%4 == 0 && (year%100 != 0)) || (year%400 == 0))
{
flag = 1;
}
switch(mon)
{
case 1:
case 3:
case 5:
case 7:
case 8:
case 10:
case 12:
printf("这个月有31天\n");
break;
case 4:
case 6:
case 9:
case 11:
printf("这个月有30天\n");
break;
case 2:
if(flag)
printf("这个月有29天\n");
else
printf("这个月有28天\n");
break;
default:
break;
}
}
#include <stdio.h>
int main(void)
{
int year, mon;
char flag = 0;
printf("输入年和月:");
scanf("%d %d", &year, &mon);
if((year%4 == 0 && (year%100 != 0)) || (year%400 == 0))
{
flag = 1;
}
switch(mon)
{
case 1:
case 3:
case 5:
case 7:
case 8:
case 10:
case 12:
printf("这个月有31天\n");
break;
case 4:
case 6:
case 9:
case 11:
printf("这个月有30天\n");
break;
case 2:
if(flag)
printf("这个月有29天\n");
else
printf("这个月有28天\n");
break;
default:
break;
}
}
44楼
//输入3个整数,按从大到小的顺序输出
#include <stdio.h>
int main(void)
{
int a, b, c;
printf("输入3个整数:");
scanf("%d", &a);
scanf("%d", &b);
scanf("%d", &c);
(a>b)? \
((c>a)?(printf("%d %d %d", c, a, b)) : ((b>c) ? (printf("%d %d %d", a, b, c)) : printf("%d %d %d", a, c, b))) : \
((b<c)?(printf("%d %d %d", c, b, a)) : ((a<c) ? (printf("%d %d %d", b, c, a)) : printf("%d %d %d", b, a, c)));
}
#include <stdio.h>
int main(void)
{
int a, b, c;
printf("输入3个整数:");
scanf("%d", &a);
scanf("%d", &b);
scanf("%d", &c);
(a>b)? \
((c>a)?(printf("%d %d %d", c, a, b)) : ((b>c) ? (printf("%d %d %d", a, b, c)) : printf("%d %d %d", a, c, b))) : \
((b<c)?(printf("%d %d %d", c, b, a)) : ((a<c) ? (printf("%d %d %d", b, c, a)) : printf("%d %d %d", b, a, c)));
}
45楼
//输入任意一个正整数,将其反转并输出, 例如345, 输出543
#include <stdio.h>
int main(void)
{
int number, i;
printf("输入一个正整数:");
scanf("%d", &number);
do
{
i = number % 10;
number = number / 10;
printf("%d", i);
}while(number);
}
#include <stdio.h>
int main(void)
{
int number, i;
printf("输入一个正整数:");
scanf("%d", &number);
do
{
i = number % 10;
number = number / 10;
printf("%d", i);
}while(number);
}
回复
有奖活动 | |
---|---|
【有奖活动】分享技术经验,兑换京东卡 | |
话不多说,快进群! | |
请大声喊出:我要开发板! | |
【有奖活动】EEPW网站征稿正在进行时,欢迎踊跃投稿啦 | |
奖!发布技术笔记,技术评测贴换取您心仪的礼品 | |
打赏了!打赏了!打赏了! |