【C语言】基础篇

打印 上一主题 下一主题

主题 1768|帖子 1768|积分 5304

马上注册,结交更多好友,享用更多功能,让你轻松玩转社区。

您需要 登录 才可以下载或查看,没有账号?立即注册

x

  • 简单输出“helloword”
  1. #include<stdio.h>
  2. int main(){
  3.         printf("hello world!");
  4.         return 0;
  5. }
复制代码


  •  和与商
  1. #include<stdio.h>
  2. int main(){
  3.         int a,b,sum,quotient;
  4.         printf("Enter two numbers:");
  5.         scanf("%d %d",&a,&b);
  6.         sum = a + b;
  7.         quotient = a / b;
  8.         printf("%d + %d = %d\n",a,b,sum);
  9.         if(b != 0){
  10.         printf("%d / %d = %d",a,b,quotient);
  11.         }
  12.         else{
  13.                 printf("请检查你输入的数字是否正确。");
  14.         }
  15.         return 0;
  16. }
复制代码


  • 判定奇偶
  1. #include<stdio.h>
  2. int main(){
  3.         int number;
  4.         printf("Enter a number:");
  5.         scanf("%d",&number);
  6.         if(number%2 == 0){
  7.                 printf("%d is even",number);
  8.         }
  9.         else{
  10.                 printf("%d is odd",number);
  11.         }
  12.         return 0;
  13. }
复制代码


  • 判定闰年
  1. #include<stdio.h>
  2. int main(){
  3.         int year;
  4.         printf("Enter a year:");
  5.         scanf("%d",&year);
  6.         if(year % 4 == 0 & year % 100 != 0 | year % 400 == 0){
  7.                 printf("%d is a leap year",year);
  8.         }
  9.         else{
  10.                 printf("%d is not a leap year",year);
  11.         }
  12. }
复制代码


  • 求阶乘
  1. #include<stdio.h>
  2. int main(){
  3.         int n,i;
  4.         int t = 1;
  5.         printf("Enter a number:");
  6.         scanf("%d",&n);
  7.         for(i = 1;i <= n;i++){
  8.                 t = t * i;
  9.         }
  10.         printf("factorial = %d",t);
  11.         return 0;
  12. }
复制代码


免责声明:如果侵犯了您的权益,请联系站长,我们会及时删除侵权内容,谢谢合作!更多信息从访问主页:qidao123.com:ToB企服之家,中国第一个企服评测及商务社交产业平台。
回复

使用道具 举报

0 个回复

倒序浏览

快速回复

您需要登录后才可以回帖 登录 or 立即注册

本版积分规则

盛世宏图

论坛元老
这个人很懒什么都没写!
快速回复 返回顶部 返回列表