- 1、原创力文档(book118)网站文档一经付费(服务费),不意味着购买了该文档的版权,仅供个人/单位学习、研究之用,不得用于商业用途,未经授权,严禁复制、发行、汇编、翻译或者网络传播等,侵权必究。。
- 2、本站所有内容均由合作方或网友上传,本站不对文档的完整性、权威性及其观点立场正确性做任何保证或承诺!文档内容仅供研究参考,付费前请自行鉴别。如您付费,意味着您自己接受本站规则且自行承担风险,本站不退款、不进行额外附加服务;查看《如何避免下载的几个坑》。如果您已付费下载过本站文档,您可以点击 这里二次下载。
- 3、如文档侵犯商业秘密、侵犯著作权、侵犯人身权等,请点击“版权申诉”(推荐),也可以打举报电话:400-050-0827(电话支持时间:9:00-18:30)。
- 4、该文档为VIP文档,如果想要下载,成为VIP会员后,下载免费。
- 5、成为VIP后,下载本文档将扣除1次下载权益。下载后,不支持退款、换文档。如有疑问请联系我们。
- 6、成为VIP后,您将拥有八大权益,权益包括:VIP文档下载权益、阅读免打扰、文档格式转换、高级专利检索、专属身份标志、高级客服、多端互通、版权登记。
- 7、VIP文档为合作方或网友上传,每下载1次, 网站将根据用户上传文档的质量评分、类型等,对文档贡献者给予高额补贴、流量扶持。如果你也想贡献VIP文档。上传文档
查看更多
初学C语言常用简单程序代码
初学C语言常用简单程序代码
素数的筛选
#include stdio.h
#include math.h
#define N 1000
int main(int argc, char* argv[])
{
int i,j,num[N];
for(i=0;iN;i++)
num[i]=i+1;
for(i=1;i(int)sqrt((double)N);i++)
{
if(num[i])
{
for(j=i+1;jN;j++)
{
if(num[j])
if(num[j]%num[i]==0)
num[j]=0;
}
}
}
for(i=1;iN;i++)
if(num[i])
printf( %d,num[i]);
return 0;
}
输出时分秒
#include stdio.h
main()
{
int x,s,t,d;
scanf(%d,x);
s=x%60;
t=(x/60)%60;
d=(x/60)/60;
printf(%d时%d分%d秒,d,t,s);
}
三个数的交换
#include stdio.h
void main()
{
int a,b,c,t;
scanf(%d%d%d,a,b,c);
printf(The original number:a=%d,b=%d,c=%d\n,a,b,c);
t=a,a=b,b=t;
t=a,a=c,c=t;
printf(after swap:a=%d,b=%d,c=%d,a,b,c);
}
switch语句的运用
#include stdio.h
main()
{
int a,m;
printf(please input a number:);
scanf(%d,a);
switch(a/10)
{
case 10:
case 9: m=5; break;
case 8: m=4; break;
case 7:m=3; break;
case 6:m=2; break;
default:m=1;
}
printf(m=%d,m);
}
判断奇数和偶数
#include stdio.h
main()
{
int x;
printf(Please input a number: );
scanf(%d,x);
if(x%2==0)
printf(this is a oushu!);
else
printf(this is a jishu!);
}
小写改大写,若是大写则不变
include stdio.h
main()
{
char c1,c2;
printf(Input a letter\n);
scanf(%c,c1);
c2=(a=c1c1=z)?(c1-a+A):c1;
printf(%c,c2);
getchar();
return 0;
}
输入一个数,输出这个数是几位数
#include stdio.h
main()
{
int x,n;
printf(please input a number:);
scanf(%d,x);
n=0;
while(x!=0)
{
x=x/10;
n++;
}
printf(%d,n);
}
输入一个数,判断它是几位数,然后逆序输出
#includestdio.h
int main()
{
int num;
int len = 0;
int temp =0;
printf(Please input a number:\n);
scanf(%d,num);
while((num % 10)!=0)
{
temp = temp*10+(num%10);
len++;
num = num/10;
}
printf(length = %d\n,len);
printf(Reverse is %d, temp);
}
打印水仙花数
#include stdio.h
main()
{
int x, a,b,c;
for(x=100;x=999;x++)
{
a=x%10;
b=(x/10)%10;
c=x/100;
if(x==a*a*a+b*b*b+c*c*c)
{
printf(%5d,x);
}
}
原创力文档


文档评论(0)