Auto commit

This commit is contained in:
smallkun 2025-03-06 12:46:40 +08:00
parent 43a25c48b0
commit 9229598107
21 changed files with 577 additions and 0 deletions

View File

@ -0,0 +1,34 @@
/*-------------------------------------------------------
-------------------------------------------------------*/
#include <stdio.h>
main()
{
int y,m,d,s,f;
s=0;
printf("请输入一个日期YYYY-MM-DD");
scanf("%d-%d-%d",&y,&m,&d);
if(y%4==0&&y%100!=0||y%400==0)
f=1;
else
f=0;
switch(m-1)
{
/**********Program**********/
case 11: s+=30;
case 10: s+=31;
case 9: s+=30;
case 8: s+=31;
case 7: s+=31;
case 6: s+=30;
case 5: s+=31;
case 4: s+=30;
case 3: s+=31;
case 2: s+=f+28;
case 1: s+=31;
/********** End **********/
}
s=s+d ;
printf("%d-%d-%d是这一年中的第%d天\n",y,m,d,s);
}

View File

@ -0,0 +1,49 @@
/*-------------------------------------------------------
100510,
2 3 5 7 11 13 17 19 23 29
31 37 41 43 47 53 59 61 67 71
73 79 83 89 97 101 103 107 109 113
127 131 137 139 149 151 157 163 167 173
179 181 191 193 197 199 211 223 227 229
233 239 241 251 257 263 269 271 277 281
283 293 307 311 313 317 331 337 347 349
353 359 367 373 379 383 389 397 401 409
419 421 431 433 439 443 449 457 461 463
467 479 487 491 499 503 509 521 523 541
average=241.330000
-------------------------------------------------------*/
#include <stdio.h>
#include <math.h>
main()
{
int i,j,k,m,sum;
double avg;
k=0;
sum=0;
for(i=2;k<100;i++)
{
m=sqrt(i);
/**********Program**********/
for(j=2;j<=m;j++){
if(i%j==0){
break;
}
}
if(j>m){
printf("%5d", i);
k++;
sum+=i;
if(k%10==0){
printf("\n");
}
}
/********** End **********/
}
avg=sum/100.0;
printf("\naverage=%f\n",avg);
}

View File

@ -0,0 +1,32 @@
/*-------------------------------------------------------
100200510
101 103 107 109 113 127 131 137 139 149
151 157 163 167 173 179 181 191 193 197
199
-------------------------------------------------------*/
#include <stdio.h>
#include <math.h>
main()
{
int i,j,k,m;
k=0;
for(i=101;i<200;i+=2 )
{
m=sqrt(i);
/**********Program**********/
for(j=2;j<=m;j++){
if(i%j==0){
break;
}
}
if(j > m){
printf("%5d", i);
k++;
if(k%10==0){
printf("\n");
}
}
/********** End **********/
}
}

View File

@ -0,0 +1,31 @@
/*-------------------------------------------------------
使for循环输出99乘法表:
1x1=1 1x2=2 1x3=3 1x4=4 1x5=5 1x6=6 1x7=7 1x8=8 1x9=9
2x1=2 2x2=4 2x3=6 2x4=8 2x5=10 2x6=12 2x7=14 2x8=16 2x9=18
3x1=3 3x2=6 3x3=9 3x4=12 3x5=15 3x6=18 3x7=21 3x8=24 3x9=27
4x1=4 4x2=8 4x3=12 4x4=16 4x5=20 4x6=24 4x7=28 4x8=32 4x9=36
5x1=5 5x2=10 5x3=15 5x4=20 5x5=25 5x6=30 5x7=35 5x8=40 5x9=45
6x1=6 6x2=12 6x3=18 6x4=24 6x5=30 6x6=36 6x7=42 6x8=48 6x9=54
7x1=7 7x2=14 7x3=21 7x4=28 7x5=35 7x6=42 7x7=49 7x8=56 7x9=63
8x1=8 8x2=16 8x3=24 8x4=32 8x5=40 8x6=48 8x7=56 8x8=64 8x9=72
9x1=9 9x2=18 9x3=27 9x4=36 9x5=45 9x6=54 9x7=63 9x8=72 9x9=81
-------------------------------------------------------*/
#include <stdio.h>
main()
{
int i,j;
/**********Program**********/
for(i=1;i<10;i++){
for(j=1;j<10;j++){
printf("%dx%d=%-4d", i, j, i*j);
}
printf("\n");
}
/********** End **********/
}

View File

@ -0,0 +1,31 @@
/*-------------------------------------------------------
n行的菱形n由键盘输入
5
*
***
*****
***
*
-----------------------------------------------------*/
#include <stdio.h>
#include <math.h>
main()
{
int i,j,k,n;
printf("请输入一个奇数(行数)n:");
scanf("%d",&n);
for(i=-n/2; i<=n/2;i++)
{
/**********Program**********/
for(j=0;j<abs(i);j++){
printf(" ");
}
for(k=0;k<n-j*2;k++){
printf("*");
}
printf("\n");
/********** End **********/
}
}

View File

@ -0,0 +1,19 @@
/*-------------------------------------------------------
50015313+53+33使for循环
-------------------------------------------------------*/
#include <stdio.h>
main()
{
int a,b,c,i;
/**********Program**********/
for(i=100;i<500;i++){
a = i%10;
b = i%100/10;
c = i/100;
if(a*a*a + b*b*b + c*c*c == i)
/********** End **********/
printf("%d\n",i);
}
}

View File

@ -0,0 +1,30 @@
/*-------------------------------------------------------
1123581321100004
1 1 2 3
5 8 13 21
34 55 89 144
233 377 610 987
1597 2584 4181 6765
-------------------------------------------------------*/
#include <stdio.h>
main()
{
int a,b,c,i;
a=b=1;
printf("%d\t%d\t",a,b);
for(i=3;;i++)
{
c=a+b;
if(c>10000)
break;
printf("%d\t",c);
/**********Program**********/
if(i%4==0){
printf("\n");
}
a = b;
b = c;
}
/********** End **********/
}

View File

@ -0,0 +1,29 @@
/*-------------------------------------------------------
1123581321204
1 1 2 3
5 8 13 21
34 55 89 144
233 377 610 987
1597 2584 4181 6765
-------------------------------------------------------*/
#include <stdio.h>
main()
{
int a,b,c,i;
a=b=1;
printf("%d\t%d\t",a,b);
for(i=3;i<=20;i++)
{
c=a+b;
printf("%d\t",c);
/**********Program**********/
if(i%4==0){
printf("\n");
}
a = b;
b = c;
/********** End **********/
}
}

View File

@ -0,0 +1,28 @@
/*-------------------------------------------------------
使for循环输出99乘法表: %dx%d=%-4d)
1x1=1 1x2=2 1x3=3 1x4=4 1x5=5 1x6=6 1x7=7 1x8=8 1x9=9
2x1=2 2x2=4 2x3=6 2x4=8 2x5=10 2x6=12 2x7=14 2x8=16
3x1=3 3x2=6 3x3=9 3x4=12 3x5=15 3x6=18 3x7=21
4x1=4 4x2=8 4x3=12 4x4=16 4x5=20 4x6=24
5x1=5 5x2=10 5x3=15 5x4=20 5x5=25
6x1=6 6x2=12 6x3=18 6x4=24
7x1=7 7x2=14 7x3=21
8x1=8 8x2=16
9x1=9
-------------------------------------------------------*/
#include <stdio.h>
main()
{
int i,j;
/**********Program**********/
for(i = 1;i<10;i++){
for(j=1;j<=10-i;j++){
printf("%dx%d=%-4d", i, j, i*j);
}
printf("\n");
}
/********** End **********/
}

View File

@ -0,0 +1,34 @@
/*-------------------------------------------------------
使for循环输出99乘法表:
1x9=9
2x8=16 2x9=18
3x7=21 3x8=24 3x9=27
4x6=24 4x7=28 4x8=32 4x9=36
5x5=25 5x6=30 5x7=35 5x8=40 5x9=45
6x4=24 6x5=30 6x6=36 6x7=42 6x8=48 6x9=54
7x3=21 7x4=28 7x5=35 7x6=42 7x7=49 7x8=56 7x9=63
8x2=16 8x3=24 8x4=32 8x5=40 8x6=48 8x7=56 8x8=64 8x9=72
9x1=9 9x2=18 9x3=27 9x4=36 9x5=45 9x6=54 9x7=63 9x8=72 9x9=81
-------------------------------------------------------*/
#include <stdio.h>
main()
{
int i,j;
for(i=1;i<=9;i++)
{
for(j=1;j<10-i;j++)
{
printf("\t");
}
/**********Program**********/
for(j=10-i;j<10;j++){
printf("%dx%d=%-4d", i, j, i*j);
}
printf("\n");
}
/********** End **********/
}

View File

@ -0,0 +1,31 @@
/*-------------------------------------------------------
使for循环输出99乘法表:
1x1=1 1x2=2 1x3=3 1x4=4 1x5=5 1x6=6 1x7=7 1x8=8 1x9=9
2x2=4 2x3=6 2x4=8 2x5=10 2x6=12 2x7=14 2x8=16 2x9=18
3x3=9 3x4=12 3x5=15 3x6=18 3x7=21 3x8=24 3x9=27
4x4=16 4x5=20 4x6=24 4x7=28 4x8=32 4x9=36
5x5=25 5x6=30 5x7=35 5x8=40 5x9=45
6x6=36 6x7=42 6x8=48 6x9=54
7x7=49 7x8=56 7x9=63
8x8=64 8x9=72
9x9=81
-------------------------------------------------------*/
#include <stdio.h>
main()
{
int i,j;
for(i=1;i<=9;i++)
{
for(j=1;j<i;j++)
{
printf("\t");
}
/**********Program**********/
for(j=i;j<10;j++){
printf("%dx%d=%-4d", i, j, i*j);
}
printf("\n");
}
/********** End **********/
}

View File

@ -0,0 +1,24 @@
/*-------------------------------------------------------
s=a+aa+aaa+aaaa+aaa的值a为一个数字3+33+333+3333+33333a以及所加数字个数n由键盘输入,a=3,n=5使for
-------------------------------------------------------*/
#include <stdio.h>
main()
{
int a,n,s,i,t;
s=t=0;
printf("请输入数字a:");
scanf("%d",&a);
printf("请输入求和的项数n:");
scanf("%d",&n);
/**********Program**********/
t = a;
for(i=0;i<n;i++){
s += t;
t*=10;
t+=a;
}
/********** End **********/
printf("s=%d\n",s);
}

View File

@ -0,0 +1,26 @@
/*-------------------------------------------------------
(使math库abs)
1
123
12345
1234567
12345
123
1
-------------------------------------------------------*/
#include <stdio.h>
#include <math.h>
main()
{
int i,j;
for(i=-3;i<=3;i++)
{
/**********Program**********/
for(j=0;j<7-abs(i)*2;j++){
printf("%d", j+1);
}
printf("\n");
/********** End **********/
}
}

View File

@ -0,0 +1,21 @@
/*-------------------------------------------------------
111011110113使while循环
-------------------------------------------------------*/
#include <stdio.h>
main()
{
int n,s,t;
s=0;
printf("请输入一个整数:");
scanf("%d",&n);
/**********Program**********/
//1011 从最末尾开始 依次除出
//加入s之前将前加入的数*1
while(n){
s += s + n%2;
n /= 2;
}
/********** End **********/
printf("%d\n",s);
}

View File

@ -0,0 +1,23 @@
/*-------------------------------------------------------
m是否素数,m由键盘输入(使for
-------------------------------------------------------*/
#include <stdio.h>
#include <math.h>
main()
{
int m,i,k;
printf("请输入一个正整数 :");
scanf("%d",&m);
k=sqrt(m);
/**********Program**********/
for(i=2;i<=k;i++){
if(m % i == 0){
break;
}
}
/********** End **********/
if(i>k)
printf("%d是素数\n",m);
else
printf("%d不是素数\n",m);
}

View File

@ -0,0 +1,22 @@
/*-------------------------------------------------------
m是否素数,m由键盘输入(使for循环
-------------------------------------------------------*/
#include <stdio.h>
main()
{
int m,i;
printf("请输入一个正整数 :");
scanf("%d",&m);
/**********Program**********/
for(i=2;i<m;i++){
if(m%i==0){
break;
}
}
/********** End **********/
if(i==m)
printf("%d是素数\n",m);
else
printf("%d不是素数\n",m);
}

View File

@ -0,0 +1,30 @@
/*-------------------------------------------------------
使for循环输出99乘法表:
1x1=1
2x1=2 2x2=4
3x1=3 3x2=6 3x3=9
4x1=4 4x2=8 4x3=12 4x4=16
5x1=5 5x2=10 5x3=15 5x4=20 5x5=25
6x1=6 6x2=12 6x3=18 6x4=24 6x5=30 6x6=36
7x1=7 7x2=14 7x3=21 7x4=28 7x5=35 7x6=42 7x7=49
8x1=8 8x2=16 8x3=24 8x4=32 8x5=40 8x6=48 8x7=56 8x8=64
9x1=9 9x2=18 9x3=27 9x4=36 9x5=45 9x6=54 9x7=63 9x8=72 9x9=81
-------------------------------------------------------*/
#include <stdio.h>
main()
{
int i,j;
/**********Program**********/
for(i=1;i<10;i++){
for(j=1;j<=i;j++){
printf("%dx%d=%-4d", i, j, i*j);
}
printf("\n");
}
/********** End **********/
}

View File

@ -0,0 +1,29 @@
/*-------------------------------------------------------
5(使for循环
-------------------------------------------------------*/
#include <stdio.h>
main()
{
int n,s,max,min,i;
double avg;
scanf("%d",&n);
s=max=min=n;
for(i=2;i<=5;i++)
{
scanf("%d",&n);
/**********Program**********/
if(n > max){
max = n;
}
if(n < min){
min = n;
}
s+=n;
/********** End **********/
}
avg=s/5.0;
printf("max=%d,min=%d,avg=%f\n",max,min,avg);
}

View File

@ -0,0 +1,23 @@
/*-------------------------------------------------------
2000300010
-------------------------------------------------------*/
#include <stdio.h>
main()
{
int year,count;
count=0;
for(year=2000;year<=3000;year++)
{
if(year%4==0&&year%100!=0 || year%400==0) {
printf("%-6d",year);
/**********Program**********/
count++;
if(count%10==0){
printf("\n");
}
}
/********** End **********/
}
}

View File

@ -0,0 +1,31 @@
/*-------------------------------------------------------
20003262
-------------------------------------------------------*/
#include <stdio.h>
main()
{
int i, year,month,day,days;
days=0;
printf("请输入一年日期格式为yyyy-mm-dd");
scanf("%d-%d-%d",&year,&month,&day);
for(i=1;i<month;i++)
{
switch(i)
{
/**********Program**********/
case 1:
case 3:
case 5:
case 7:
case 8:
case 10:days+=31;break;
case 2: days+=28;days += (year%4==0&&year%100!=0||year%400==0)?1:0;break;
default:
days+=30;
/********** End **********/ }
}
days=days+day;
printf("%d-%d-%d是这一年中的第%d天\n",year,month,day,days);
}