4个小代
来源:互联网 发布:英雄联盟网络转播权 编辑:程序博客网 时间:2024/06/06 03:28
1.在屏幕上输出以下图案:
*
***
*****
*******
*********
***********
*************
***********
*********
*******
*****
***
*
#include<stdio.h>
#include<string.h>int main()
{
int i=0;
int j=0;
int k=0;
for(i=1;i<8;i++)
{
for(j=0;j<7-i;j++)
{
printf(" ");
}
for(k=0;k<2*i-1;k++)
{
printf("*");
}
printf("\n");
}
for(i=2;i<8;i++)
{
for(j=1;j<i;j++)
{
printf(" ");
}
for(k=13;k>=2*i-1;k--)
{
printf("*");
}
printf("\n");
}
return 0;
}
2.求出0~999之间的所有“水仙花数”并输出
#include<stdio.h>
#include<math.h>
int main()
{
int a=0;
int b=0;
int c=0;
int d=0;
int e=0;
for(a=0;a<1000;a++)
{
b=a/100;
c=(a/10)%10;
d=a%10;
e=pow(b,3)+pow(c,3)+pow(d,3);
if(a==e&&a>99)
printf("%d\n",a);
}
return 0;
}
3.求Sn=a+aa+aaa+aaaa+aaaaa的前5项之和
#include<stdio.h>
#include<math.h>
int main()
{
int a=0;
int Sn=0;
int i=0;
int j=0;
for(i=1;i<10;i++)
{
for(j=5;j>0;j--)
{
for(a=0;a<j;a++)
{
Sn=Sn+i*pow(10,a);
}
}
printf("Sn=%d\n",Sn);
Sn=0;
}
return 0;
}
4.编写一个程序,它从标准输入读取C源代码,并验证所有的花括号都正确的成对出现。
#include<stdio.h>
int main()
{
int ch=0;
int count=0;
while((ch=getchar())!=EOF)
{
if(ch=='{')
count++;
if(ch=='}'&&count==0)
printf("不匹配\n");
if(ch=='}'&&count!=0)
count--;
}
if(count==0)
printf("匹配\n");
else
printf("不匹配\n");
return 0;
}
- 4个小代
- 4
- 4
- (4)
- 4
- 4
- 4
- 4
- 4
- 4
- 4
- 4
- 4
- 4
- 4
- 4
- 4
- 4
- HDU 1035-Robot Motion
- http状态码表
- Java——使用DOM4j解析XML文档
- 2017 CCPC 哈尔滨
- leetcode: 32. Longest Valid Parentheses
- 4个小代
- 密码学:基于python支持448位输入的sha-1算法
- Angular2 ng-boostarp 日历控件
- 为什么修改jsp不用重启tomcat,而修改servlet要重启tomcat
- jar命名打包war
- 17.11.11,web学习第一天,还有一年,努力吧青年
- windows中docker打包使用
- MyEclipse字体及颜色的设置
- Struts2拦截器