- 博客(8)
- 收藏
- 关注
原创 C语言程序设计Day8
C语言程序设计Day8前n项求和#include<stdio.h>int main(){ int n; int i; double sum = 0.0; scanf("%d",&n); for (i = 1;i<=n;i++){ sum+=1.0/i; } printf("f(%d)=%f\n",n,sum); return 0 ;}
2021-02-01 23:11:16
85
原创 C语言程序设计Day7
C语言程序设计Day7素数#include<stdio.h>int main(){ int x; scanf("%d",&x); int i; int isPrime = 1; //x是素数; for(i=2;i<x;i++){ if(x%i==0){ isPrime=0; break; } } if(isPrime == 1){ printf("%d是素数。\n",x); }else { printf("%d不是素数。\n",
2021-01-31 22:11:38
86
原创 C语言程序设计Day6
C语言程序设计Day6for循环阶乘#include <stdio.h>int main(){ int i=1; int fact=1; int n; scanf("%d",&n); while(i<=n){ fact *= i; i++; } printf("%d!=%d",n,fact); return 0;}
2021-01-29 18:24:50
107
原创 C语言程序设计Day5
C语言程序设计Day5计算log2 of x#include <stdio.h>int main(){ int x; int ret; scanf("%d",&x); int t=x; while(x>1){ x/=2; ret++; } printf("log2 of %d is %d.",t,ret); return 0;} 猜数游戏#include <stdio.h>#include <stdlib.h>#i
2021-01-27 20:28:45
100
原创 C语言程序设计Day4
C语言程序设计Day4循环数数几位数:输入一个三位以下的数(含三位)判断他是几位数。#include <stdio.h>int main(){ int x; int n; printf("请输入一个数\n"); scanf("%d",&x); if(x>=100) { n=3; }else if(x>=10) { n=2; }else if(x>=1) { n=1; } printf("%d",n); return 0;
2021-01-26 20:00:10
79
原创 C语言程序设计Day3
C语言程序设计Day3if-else三个数比较大小#include <stdio.h>int main(){ int a,b,c; scanf("%d%d%d",&a,&b,&c); int max=0; if(a>b) { if(a>c) { max=a; }else{ max=c; } }else{ if(b>c) { max=b; }else{ max=c; } }
2021-01-25 21:53:00
55
原创 C语言程序设计Day2
C语言程序设计Day2#include <stdio.h>int main(){ int a,b; scanf("%d %d",&a,&b); int c=a/100; int d=a%100; int e=c*60+d; int time=b+e; int time1=time/60; int time2=time%60; int time3=time1*100+time2; printf("%d",time3); return 0; }
2021-01-20 17:49:04
102
1
原创 C语言程序设计 Day1
C语言程序设计Day1#include <stdio.h>int main(){ int a , b; scanf("%d",&a); scanf("%d",&b); int c=a+b; int d=a-b; int e=a*b; int f=a/b; printf("a+b=%d\n",c); printf("a-b=%d\n",d); printf("a*b=%d\n",e); printf("a/b=%d\n",f); return 0;
2021-01-20 00:10:38
308
1
空空如也
空空如也
TA创建的收藏夹 TA关注的收藏夹
TA关注的人