欢迎来到尧图网

客户服务 关于我们

您的位置:首页 > 财经 > 金融 > 【C语言】基础篇

【C语言】基础篇

2024/10/25 16:27:36 来源:https://blog.csdn.net/2301_79394155/article/details/142702916  浏览:    关键词:【C语言】基础篇
  • 简单输出“helloword”

#include<stdio.h>
int main(){printf("hello world!");return 0;
}
  •  和与商

#include<stdio.h>
int main(){int a,b,sum,quotient;printf("Enter two numbers:");scanf("%d %d",&a,&b);sum = a + b;quotient = a / b;printf("%d + %d = %d\n",a,b,sum);if(b != 0){printf("%d / %d = %d",a,b,quotient);}else{printf("请检查你输入的数字是否正确。");}return 0;
}
  • 判断奇偶

#include<stdio.h>
int main(){int number;printf("Enter a number:");scanf("%d",&number);if(number%2 == 0){printf("%d is even",number);}else{printf("%d is odd",number);}return 0;
}
  • 判断闰年

#include<stdio.h>
int main(){int year;printf("Enter a year:");scanf("%d",&year);if(year % 4 == 0 & year % 100 != 0 | year % 400 == 0){printf("%d is a leap year",year);}else{printf("%d is not a leap year",year);}
}
  • 求阶乘

#include<stdio.h>
int main(){int n,i;int t = 1;printf("Enter a number:");scanf("%d",&n);for(i = 1;i <= n;i++){t = t * i;}printf("factorial = %d",t);return 0;
}

版权声明:

本网仅为发布的内容提供存储空间,不对发表、转载的内容提供任何形式的保证。凡本网注明“来源:XXX网络”的作品,均转载自其它媒体,著作权归作者所有,商业转载请联系作者获得授权,非商业转载请注明出处。

我们尊重并感谢每一位作者,均已注明文章来源和作者。如因作品内容、版权或其它问题,请及时与我们联系,联系邮箱:809451989@qq.com,投稿邮箱:809451989@qq.com