《C语言及程序设计初步》第33讲实践项目
2016-01-11 01:56
531 查看
项目1:
项目2:
#include <stdio.h> int main() { int n=1,total=0; while(n<=500) { total = total+2*n; n++; } printf("%d",total); return 0; }
#include <stdio.h> int main() { int n,total=0; for(n=1;n<=500;n++) { total = total+2*n; } printf("%d",total); return 0; }
#include <stdio.h> int main() { int n=1,total=0; do { total = total+2*n; n++; } while(n<=500); printf("%d",total); return 0; }
项目2:
#include <stdio.h> int main() { double n,m,factorial=1; printf("Please enter the value of n:"); scanf("%lf",&n); for(m=1;m<=n;m++) factorial = factorial*m; printf("factorial=%.0lf",factorial); return 0; }项目3:
//输出1000以内能被3整除且个位数为6的所有整数 #include <stdio.h> int main() { int i,j; for(i=0;i<100;i++) { j = i*10+6; if(j%3==0) printf("%d\n",j); } printf("\n"); return 0; }
相关文章推荐
- C++11多线程简单示例
- C++读取name values形式Config 配置文件
- 用C语言打印杨辉三角
- C++基础题目
- QML与C++交互
- Ubuntu 12.04 安装eclipse for c++
- 最小生成树prim (c++ 已大改)
- C++中括号()操作符的重载举例及解析
- c语言实现数组栈
- Sicily 1198. Substring
- c语言实现双链表
- 一起talk C栗子吧(第九十六回:C语言实例--使用共享内存进行进程间通信二)
- C/C++获取程序执行时间的五个方法对比
- 哈弗曼树讲解---c语言实现
- c语言 c99 标准
- C++学习笔记42——重载操作符之箭头操作符
- POJ 1003 Hangover 水题一道 练习C++编程
- C++编程学习之旅 由浅及深
- 实型常量
- 【C/C++学院】0831-类与对象的异常/面试100题1-100