Auto commit

This commit is contained in:
smallkun 2025-03-06 23:47:59 +08:00
parent d12a28496d
commit 533f6eabc4
20 changed files with 509 additions and 0 deletions

View File

@ -0,0 +1,32 @@
/*
-------------------------------------------------------
---------------------------------------------------------
*****
*****
*****
*****
*****
*/
#include<stdio.h>
void main()
{
int i =0 , j =0 , k=0;
/**********Program**********/
for(i=0;i<5;i++){
for(j=0;j<i;j++){
printf(" ");
}
for(k=0;k<5;k++){
printf("*");
}
printf("\n");
}
/********** End **********/
printf("\n");
}

View File

@ -0,0 +1,25 @@
/*------------------------------------------------------------------------
使for循环输出Fibonacci数列的前15项5
Fibonacci数列1,1,2,3,5,8,13...........
----------------------------------------------------------------------*/
#include <stdio.h>
main()
{
int fib[15],i;
fib[0]=1;fib[1]=1;
/**********Program**********/
for(i=2;i<15;i++){
fib[i]=fib[i-1]+fib[i-2];
}
/********** End **********/
for(i=0;i<15;i++)
{
printf("%d\t",fib[i] );
if ( i%5==4 ) printf("\n");
}
}

View File

@ -0,0 +1,34 @@
/*-------------------------------------------------------
1. 101-200IsPrime2sqrt() --------------------------------------------------------*/
#include <stdio.h>
#include<math.h>
int IsPrime (int n)
{
int i=2;
for(i=2;i<=sqrt(n);i++)
/**********Program**********/
if(n%i==0){
return 0;
}
/********** End **********/
return 1;
}
int main( )
{
int i ;
for(i=100;i<=200;i++ )
{
if ( IsPrime( i) )
{
printf("% d",i);
}
}
return 0;
}

View File

@ -0,0 +1,40 @@
/*-------------------------------------------------------
10010001510
5
159 168 177 186 195 249 258 267 276 285
294 339 348 357 366 375 384 393 429 438
447 456 465 474 483 492 519 528 537 546
555 564 573 582 591 609 618 627 636 645
654 663 672 681 690 708 717 726 735 744
753 762 771 780 807 816 825 834 843 852
861 870 906 915 924 933 942 951 960
-------------------------------------------------------*/
#include<stdio.h>
main()
{
int m,n,k,i=0;
for(m=100;m<=1000;m++)
{
k=0;
n=m;
/**********Program**********/
while(n){
k+=n%10;
n/=10;
}
if(k%15==0){
i++;
printf("%5d", m);
if(i%10==0){
printf("\n");
}
}
/********** End **********/
}
}

View File

@ -0,0 +1,31 @@
/*-------------------------------------------------------
*********
*******
*****
***
*
--------------------------------------------------------*/
#include<stdio.h>
void main()
{
int i,j,k;
for( i=0 ; i<5; i++ )
{
printf("\n");
/**********Program**********/
for(j=0;j<i*2;j++){
printf(" ");
}
for(k=0;k<9-j;k++){
printf("*");
}
/********** End **********/
}
printf("\n");
}

View File

@ -0,0 +1,29 @@
/*-------------------------------------------------------
1.
*****
***
*
--------------------------------------------------------*/
#include<stdio.h>
void main()
{
int i,j,k;
/**********Program**********/
for(i=0;i<3;i++){
for(j=0;j<i;j++){
printf(" ");
}
for(k=0;k<5-j*2;k++){
printf("*");
}
printf("\n");
}
/********** End **********/
printf("\n");
}

View File

@ -0,0 +1,20 @@
/*-------------------------------------------------------
--------------------------------------------------------*/
#include <stdio.h>
main()
{
int a,b;
scanf("%d%d",&a , &b );
printf("a=%d,b=%d\n",a,b);
/**********Program**********/
a = a+b;
b = a-b;
a = a-b;
/********** End **********/
printf("a=%d,b=%d\n", a,b);
}

View File

@ -0,0 +1,20 @@
/*-------------------------------------------------------
123-321
--------------------------------------------------------*/
#include <stdio.h>
int main()
{
int i;
long sum = 0;
for(i = 123; i <= 321; i++ )
{
/**********Program**********/
if(i%2==0){
sum += i;
}
/********** End **********/
}
printf ("总和为 : %ld.\n",sum);
return 0;
}

View File

@ -0,0 +1,19 @@
/*-------------------------------------------------------
1233217使for循环
--------------------------------------------------------*/
#include <stdio.h>
void main()
{
int a=0;
/**********Program**********/
for(a=123;a<=321;a++){
if(a%7==0){
/********** End **********/
printf("%d\n",a);
}
}
}

View File

@ -0,0 +1,21 @@
/*-------------------------------------------------------
--------------------------------------------------------*/
#include <stdio.h>
void main()
{
int i;
float x,y,z=0;
printf("\n请输入10个数");
for(i=1;i<=10;i++)
{
/**********Program**********/
scanf("%f", &x);
if(x*x > z){
z = x*x;
y = x;
}
/********** End **********/
}
printf("平方最大的一个数是:%f\n",y);
}

View File

@ -0,0 +1,21 @@
/*-------------------------------------------------------
i
3142111使while循环
--------------------------------------------------------*/
#include<stdio.h>
main()
{
int i,sum=0,a;
scanf("%d",&i);
/**********Program**********/
while(i){
sum += i%10;
i/=10;
}
/********** End **********/
printf("%d\n",sum);
}

View File

@ -0,0 +1,20 @@
/*-------------------------------------------------------
-------------------------------------------------------*/
#include"stdio.h"
main()
{
int x,y,z=0;
scanf ("%d%d", &x,&y);
/**********Program**********/
if(x!=0 && y!=0){
z = x+y;
/********** End **********/
printf("z=%d\n", z);
}
else
printf("两个数中至少有一个数为零值\n");
}

View File

@ -0,0 +1,27 @@
/*-------------------------------------------------------
使Switch )
4 100
--------------------------------------------------------*/
#include"stdio.h"
main()
{
int year,month,day,days=0,i,d;
printf("请输入年-月-日:");
scanf("%d-%d-%d",&year,&month,&day);
for(i=1;i<month;i++)
{
/**********Program**********/
switch(i){
case 1:
case 3:
case 5:
case 7:
case 8:
case 10: days+=31;break;
case 2: days+=(28 + (year%4==0&&year%100!=0 || year%400==0?1:0));break;
default: days+=30;
}
/********** End **********/
}
printf("%d-%d-%d是该年第%d天\n",year,month,day,days + day);
}

View File

@ -0,0 +1,32 @@
/*------------------------------------------------------------------------
sum,While循环语句求1到n之间n)
3,n值由主函数传入
1018
----------------------------------------------------------------------*/
#include "stdio.h"
long sum(int n)
{
/**********Program**********/
int i, s=0;
for(i=1;i<=n;i++){
if(i%3==0){
s+=i;
}
}
return s;
/********** End **********/
}
void main()
{
int x;
long f;
scanf("%d",&x);
f=sum(x);
printf("%ld\n",f);
}

View File

@ -0,0 +1,31 @@
/*-------------------------------------------------------
*
***
*****
*******
*****
***
*
-------------------------------------------------------*/
#include <stdio.h>
main()
{
int i,j,k;
/**********Program**********/
for(i=-3;i<=3;i++){
for(j=0;j<(i<0?-i:i);j++){
printf(" ");
}
for(k=0;k<7-j*2;k++){
printf("*");
}
printf("\n");
}
/********** End **********/
}

View File

@ -0,0 +1,19 @@
/*------------------------------------------------------
n,2 n-1n整除的数
10 2 5
99 3 9 11 33
--------------------------------------------------------*/
#include "stdio.h"
int main ( )
{
int n,i;
printf("input a number:");
scanf ("%d", &n);
/**********Program**********/
for(i=2;i<n;i++)
if(n%i==0)
/********** End **********/
printf ("%d\n",i);
}

View File

@ -0,0 +1,19 @@
/*-------------------------------------------------------
21002004273 95
--------------------------------------------------------*/
# include <stdio.h>
main ()
{
int i;
for(i=100;i<200;i++)
/**********Program**********/
if(i%4==2 && i%7==3 && i%9==5)
/********** End **********/
printf ("%d",i);
}

View File

@ -0,0 +1,23 @@
/*-------------------------------------------------------
---------------------------------------------------------
331230112
使switch来实现
--------------------------------------------------------*/
#include<stdio.h>
main(){
int m,n;
scanf("%d",&m);
/**********Program**********/
n=0;
switch(m){
default: n+=(m-3)*2;
case 1:
case 2:
case 3:n+=12;
}
/********** End **********/
printf("本次收费为:%d",n);
}

View File

@ -0,0 +1,22 @@
/*-------------------------------------------------------
2"right""error"
--------------------------------------------------------*/
#include "stdio.h"
main( )
{
int a,b,c;
printf("please input a and b:\n");
scanf("%d,%d",&a , &b);
printf("please input the answer:\n");
scanf("%d",&c);
/**********Program**********/
if(a+b==c)
/********** End **********/
printf("right\n");
else
printf("error\n");
}

View File

@ -0,0 +1,24 @@
/*-------------------------------------------------------
3
l=(a+b+c)/2s=sqrt(l*(l-a)*(l-b)*(l-c))
--------------------------------------------------------*/
#include <stdio.h>
#include <math.h>
main()
{
float a,b,c,s,l;
scanf("%f,%f,%f",&a , &b , &c);
if(a+b<c||a+c<b||b+c<a)
printf("该3个数据不能构成三角形\n");
else
{
/**********Program**********/
l=(a+b+c)/2;
s=sqrt(l*(l-a)*(l-b)*(l-c));
/********** End **********/
printf("该三角形的面积为%.3f\n",s);
}
}