c语言学习
papillonlong
这个作者很懒,什么都没留下…
展开
-
比较两个实数的大小
输入两个实数,按由小到大的顺序输出这两个数。#include <stdio.h>#include <stdlib.h>/* run this program using the console pauser or add your own getch, system("pause") or input loop */int main(){ float a,b,t; scanf("%f,%f",&a,&b); if(a>b) {//将a和b原创 2021-04-13 21:59:15 · 476 阅读 · 1 评论 -
完数问题
输出1000以内的所有完数#include<stdio.h>int main() { int a; for(int i=1;i<=1000;i++)/*从1循环到1000*/ { a=0;/*用来记录i的所有因子的和*/ /*从1循环到i-1,寻找i的因子,如果j是i的因子,a就自增j*/ for(int j=1;j<i;j++) if(i%j==0) a+=j; if(a==i)/*如果i是完全数,则开始打印*/ {原创 2021-04-11 15:06:11 · 67 阅读 · 0 评论 -
c语言输出所有的水仙花数
c语言输出所有的水仙花数#include<stdio.h>int main(){ int n,a,b,c; for(a=1;a<10;a++) { for(b=0;b<10;b++) { for(c=0;c<10;c++) {n=100*a+10*b+c; if(n==(a*a*a+b*b*b+c*c*c)) printf("%d\n",n); } } } getchar();}这样就输出所有的水仙花数了。原创 2021-04-11 14:46:17 · 199 阅读 · 0 评论 -
c语言输出五位数的对称数
c语言输出五位数的对称数#include<stdio.h>int main() {int a[5], b; for(b=10000;b<100000;b++) {a[0]=b%10; a[1]=b/10%10; a[2]=b/100%10; a[3]=b/1000%10; a[4]=b/10000%10; if(a[4]==a[0]&&a[1]==a[3]) printf("%-10d",b);}}这样就可以得到所有的五位数的对称数了。原创 2021-04-11 14:14:48 · 1745 阅读 · 1 评论