C语言编程十大经典例题

这些都是基本的 c 程序,可以帮助刚踏入 c 编程世界的新手。快来试试吧:
1、c 语言编程 – hello world
              #includeint main(){ printf(hello world); printf(linux迷 www.linuxmi.com); return 0;}
2. c 语言编程 - 执行算术运算
                  #includeint main(){int a,b;printf(enter two numbers:);scanf(%d%d,&a,&b);printf(sum=%d difference=%d product=%d quotient=%d,a+b,a-b,a*b,a/b);return 0;} 3.c 编程 - 求圆的面积
                            #include#includeint main(){ float r; float n=3.14; float s; //n*r*r;该行必须在输入r值以后 printf(请输入该圆的半径:); scanf(%f,&r); s=n*r*r; printf(%.7f,s);//输出小数点后7位 return 0;}
4.c编程 - 在3个数字中找到最大值
                            #includeint main() {int a, b, c;printf(enter value of a, b & c : );scanf(%d %d %d, &a, &b, &c);if ((a > b) && (a > c))printf(a is greatest);if ((b > c) && (b > a))printf(b is greatest);if ((c > a) && (c > b))printf(c is greatest);return 0;}
5.c编程 - 查找偶数或奇数
                                #includeint main(){int n;printf(enter a number:);scanf(%d,&n);if(n%2==0){printf(number is even);}else{printf(number is odd);}return 0;}
6. c编程 - 显示一个数字的因数
                            #include int main(){int n,i;printf(enter a positive integer: );scanf(%d,&n);printf(factors of %d are: , n);for(i=1;i<=n;++i){if(n%i==0)printf(%d ,i);} return 0;}
7. c编程 - 检查质数
                                          #include int main(){int n, i, flag = 0;printf(enter a positive integer: );scanf(%d,&n);for(i=2; i<=n/2; ++i){// condition for nonprime numberif(n%i==0){flag=1;break;}}if (flag==0)printf(%d is a prime number.,n);elseprintf(%d is not a prime number.,n);return 0;}
8.c编程 - 检查闰年
                                              #includeint main(){int year;printf(enter a year: );scanf(%d,&year);if(year%4 == 0){if( year%100 == 0){// year is divisible by 400, hence the year is a leap yearif ( year%400 == 0)printf(%d is a leap year., year);elseprintf(%d is not a leap year., year);}elseprintf(%d is a leap year., year );}elseprintf(%d is not a leap year., year);return 0;}
9.c编程 -  从1加到n的和
                        #includeint main(){int i,n,sum=0;printf(upto how many terms you want to find the sum:);scanf(%d,&n);for(i=1;i<=n;i++){sum = sum + i;}printf(sum is %d,sum);return 0;}
10. c编程 - 一个数的阶乘
                                        #include int main(){int n, i;unsigned long long factorial = 1;printf(enter an integer: );scanf(%d,&n);// show error if the user enters a negative integerif (n < 0)printf(error! factorial of a negative number doesn't exist.);else{for(i=1; i<=n; ++i){factorial *= i; // factorial = factorial*i;}printf(factorial of %d = %llu, n, factorial);}return 0;}
这些 c 编程示例,可以很好的帮助初学者进行编码之旅。
写在最后:另外,对于准备学习c/c++编程的小伙伴,如果你想更好的提升你的编程核心能力(内功)不妨从现在开始!
整理分享(多年学习的源码、项目实战视频、项目笔记,基础入门教程)
欢迎转行和学习编程的伙伴,利用更多的资料学习成长比自己琢磨更快哦!
原文标题:c语言实战例题:小白必会的 10 个c语言经典练习题!源码分享
文章出处:【微信公众号:c语言编程学习基地】欢迎添加关注!文章转载请注明出处。

模拟电路网络课件 第六节:二极管基本电路及其分析方法
2016年科技产业十大趋势风潮 VR虚拟实境排名第一
车载GPS系统设计的特殊要求和注意事项
六分科技专注于GNSS高精度定位服务
光电子器件的特性和用途
C语言编程十大经典例题
区块链ICO的本质是什么?
嵌入式机器人是什么以及如何使用
如何保证PCB电路板铣加工的
物联网落地受益于芯片 谁将主宰半导体行业
一文详解安森美的智能感知技术
AMD将与法拉利有活动?或将正式发布第二代线程撕裂者Ryzen ThreadRipper
纳微半导体发布新一代650V MPS™ SiC碳化硅二极管
大屏畅享、一键直达2020欧洲杯,海信聚好看“嗨聚欧洲杯”专区正式上线
按钮操控电动机起停线路原理
芯片技术在充电桩中的应用
荧光定量食品重金属检测仪的产品概述
PPM-DCBLKS电磁流量计技术参数
360安全路由2怎么样?360安全路由2实现千兆级别仅售199元
半导体产业代表着人类高科技制造技术的精华