菱形和水仙花数
来源:互联网 发布:数据存储安全 编辑:程序博客网 时间:2024/05/27 06:15
1.在屏幕打印菱形(n=7);
include <stdio.h>int main(){ int n; int i=0;int j=0; printf("input n\n"); scanf("%d", &n); //打印上边部分 for (i= 0; i < n; i++){ for (j = 0; j < n - 1 - i; j++){ printf(" "); } for (j = 0; j <1 +2* i; j++){ printf("*"); } printf("\n"); }} // 打印下半部分 for (i = 1; i < n; i++){ for (j = 0; j <i ; j++){ printf(""); } for (j = 0; j <2*n-2*i-1 ; j++){ printf("*"); } printf("\n");}return 0;}#2.计算10000以内所有水仙花数 #include<stdio.h>
include
3.求Sn=a+aa+aaa+aaaa+aaaaa的前5项之和,其中a是一个数字,例如:2+22+222+2222+22222include
#include<stdio.h>int main(){int i = 0;int a = 0;int sum = 0;int num=0;scanf("%d",&num); //输入数字元素for (i = 0; i < 5; i++){a = a * 10 + num;//观察得到sum = sum + a;}printf("%d", sum);return 0;}
4.编写一个程序,它从标准输入读取C源代码,并验证所有的花括号都正确的成对出现。
include<stdio.h>include<windows.h> //system("pause")的头文件int main(){ char ch; int count = 0; while ((ch = getchar()) != EOF){ if ( (ch) == '{'){ count++; } if ((ch) =='}'&&count == 0){ printf("花括号不匹配"); return 0; } if ((ch) == '}'){ count--; } } if (count == 0){ printf("花括号匹配\n"); } else { printf("花括号不匹配\n"); } system("pause"); return 0; }
阅读全文
0 0
- 菱形和水仙花数
- 用C#编写九九乘法口诀、菱形、水仙花数
- 水仙花数、Sn求和、输出菱形星、验证花括号
- 水仙花数
- 水仙花数
- 水仙花数
- 水仙花数
- 水仙花数
- 水仙花数
- 水仙花数
- 水仙花数
- 水仙花数
- 水仙花数
- 水仙花数
- 水仙花数
- 水仙花数
- 水仙花数
- 水仙花数
- 第五届光电信息协会竞赛——XXXX
- php中的布尔值
- 文章标题
- 设计模式之禅16
- day7_类的重要方法和socket基础
- 菱形和水仙花数
- python 3.x 字典的11种方法
- Codeforces --- Mahmoud and Ehab and the MEX
- 深入了解PHP【生命周期】
- Item 11:在赋值操作符中处理自我赋值【effective C++读书笔记】
- VisualSVN Server v3.7
- Android 退出登录功能
- 二进制数中返回1的个数的几种方法
- Codeforce 862B Mahmoud and Ehab and the bipartiteness (二分图染色 + 链式前向星)