From fb8b8b943a3e0797724222eb380cf6dde3bee84f Mon Sep 17 00:00:00 2001 From: wangcSCU <91170982+wangcSCU@users.noreply.github.com> Date: Tue, 28 Sep 2021 18:50:33 +0800 Subject: [PATCH 1/4] Create wangchen MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 2021.9.26作业 --- wangchen | 45 +++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 45 insertions(+) create mode 100644 wangchen diff --git a/wangchen b/wangchen new file mode 100644 index 00000000..7b2e6ab8 --- /dev/null +++ b/wangchen @@ -0,0 +1,45 @@ +//求一元二次方程的根 +// 例如 :y = x2 + 10x + 17 +// 当 x = 2, 求 y = 41 +// 当 y = 2, 求 x = ? +/*#include +#include +int main() { + float x1, x2; + float y, a, b, c; + printf("请输入系数:\n"); + scanf("%f, %f, %f, %f", &y, &a, &b, &c); + c = c - y; + a = 2 * a; + float temp = sqrt(b*b - 4* a*c); + x1 = (-b + temp)/(a); + x2 = (-b - temp)/(a); + printf("一元二次方程根:\n"); + printf("%f\n", x1); //这是做什么? + printf("%f\n", x2); + return 0; +}*/ +//第13行中将a扩大为2倍,因此第14行中的4*a*c变为8*a*c,公式错误,所以成为了bug。 + + + //求一元二次方程的根 +// 例如 :y = x2 + 10x + 17 +// 当 x = 2, 求 y = 41 +// 当 y = 2, 求 x = ? +#include +#include +int main() { + float x1, x2; + float y, a, b, c; + printf("请输入系数:\n"); + scanf("%f, %f, %f, %f", &y, &a, &b, &c); + c = c - y; + float temp = sqrt(b*b - 4* a*c); + a = 2 * a; + x1 = (-b + temp)/(a); + x2 = (-b - temp)/(a); + printf("一元二次方程根:\n"); + printf("%f\n", x1); //这是做什么? + printf("%f\n", x2); + return 0; +} //将顺序调整后即可 From 439c6ff1f276fc3dc788a43d8b4b66a51f1906bc Mon Sep 17 00:00:00 2001 From: wangcSCU <2020141240013@stu.scu.edu.cn> Date: Wed, 13 Oct 2021 13:41:51 +0800 Subject: [PATCH 2/4] a --- "9.26bug\344\275\234\344\270\232.cpp" | 45 +++++++++++++++++++ HelloWorld.c | 2 +- ...4\346\254\241\346\226\271\347\250\213.cpp" | 16 +++++++ "\346\240\271\345\217\2672.cpp" | 16 +++++++ "\351\227\260\345\271\264.cpp" | 10 +++++ 5 files changed, 88 insertions(+), 1 deletion(-) create mode 100644 "9.26bug\344\275\234\344\270\232.cpp" create mode 100644 "\344\270\200\345\205\203\344\272\214\346\254\241\346\226\271\347\250\213.cpp" create mode 100644 "\346\240\271\345\217\2672.cpp" create mode 100644 "\351\227\260\345\271\264.cpp" diff --git "a/9.26bug\344\275\234\344\270\232.cpp" "b/9.26bug\344\275\234\344\270\232.cpp" new file mode 100644 index 00000000..475b2096 --- /dev/null +++ "b/9.26bug\344\275\234\344\270\232.cpp" @@ -0,0 +1,45 @@ +//һԪη̵ĸ +// y = x2 + 10x + 17 +// x = 2, y = 41 +// y = 2, x = ? +/*#include +#include +int main() { + float x1, x2; + float y, a, b, c; + printf("ϵ\n"); + scanf("%f, %f, %f, %f", &y, &a, &b, &c); + c = c - y; + a = 2 * a; + float temp = sqrt(b*b - 4* a*c); + x1 = (-b + temp)/(a); + x2 = (-b - temp)/(a); + printf("һԪη̸\n"); + printf("%f\n", x1); //ʲô + printf("%f\n", x2); + return 0; +}*/ +//13нaΪ2˵14е4*a*cΪ8*a*cʽԳΪbug + + + //һԪη̵ĸ +// y = x2 + 10x + 17 +// x = 2, y = 41 +// y = 2, x = ? +#include +#include +int main() { + float x1, x2; + float y, a, b, c; + printf("ϵ\n"); + scanf("%f, %f, %f, %f", &y, &a, &b, &c); + c = c - y; + float temp = sqrt(b*b - 4* a*c); + a = 2 * a; + x1 = (-b + temp)/(a); + x2 = (-b - temp)/(a); + printf("һԪη̸\n"); + printf("%f\n", x1); //ʲô + printf("%f\n", x2); + return 0; +} //˳󼴿 diff --git a/HelloWorld.c b/HelloWorld.c index 3c79b6c5..410ee3ff 100644 --- a/HelloWorld.c +++ b/HelloWorld.c @@ -1,6 +1,6 @@ #include int main() { - printf("Hello World!\n"); + printf("Hello World!aaa\n"); //try Jenkins again return 0; diff --git "a/\344\270\200\345\205\203\344\272\214\346\254\241\346\226\271\347\250\213.cpp" "b/\344\270\200\345\205\203\344\272\214\346\254\241\346\226\271\347\250\213.cpp" new file mode 100644 index 00000000..f95e1be3 --- /dev/null +++ "b/\344\270\200\345\205\203\344\272\214\346\254\241\346\226\271\347\250\213.cpp" @@ -0,0 +1,16 @@ +#include +#include +int main(){ + printf("ϵyabc"); + float x1,x2,y,a,b,c; + scanf("%f,%f,%f,%f",&y,&a,&b,&c); + c = c-y; + float temp = sqrt(b*b-4*a*c); + a = 2*a; + x1 = (-b + temp)/(a); + x2 = (-b - temp)/(a); + printf("x1 = %f\n",x1); + printf("x2 = %f\n",x2); + return 0; +} +// x*x + 10*x +17 = y diff --git "a/\346\240\271\345\217\2672.cpp" "b/\346\240\271\345\217\2672.cpp" new file mode 100644 index 00000000..39afe90f --- /dev/null +++ "b/\346\240\271\345\217\2672.cpp" @@ -0,0 +1,16 @@ +#include +#include +int main(){ +float n = 3; +float mysqrt(n); +float x = n/2; + while (x - n > 0.0001 || n - x > 0.0001){ + if (x*x > n) + x = (0+x)/2; + else + x = (x+n)/2; + } + printf("%f",x); + return 0.0f; +return 0; +} diff --git "a/\351\227\260\345\271\264.cpp" "b/\351\227\260\345\271\264.cpp" new file mode 100644 index 00000000..6657d36b --- /dev/null +++ "b/\351\227\260\345\271\264.cpp" @@ -0,0 +1,10 @@ +#include +int main(){ + int year; + scanf ("%d",&year); + if (year % 4 == 0 && year % 100 != 0 || year % 400 == 0) + printf ("%d ",year); + else + printf ("%d ",year); + return 0; +} From 46d037e4716537822931d40a15c949f6c867e182 Mon Sep 17 00:00:00 2001 From: wangcSCU <2020141240013@stu.scu.edu.cn> Date: Wed, 13 Oct 2021 16:28:32 +0800 Subject: [PATCH 3/4] 10.13 --- function sqrt2.cpp | 26 ++++++++++++++++++++++++++ sqrt2.cpp | 21 +++++++++++++++++++++ "\346\240\271\345\217\2672.cpp" | 21 +++++++++------------ 3 files changed, 56 insertions(+), 12 deletions(-) create mode 100644 function sqrt2.cpp create mode 100644 sqrt2.cpp diff --git a/function sqrt2.cpp b/function sqrt2.cpp new file mode 100644 index 00000000..0252a0b3 --- /dev/null +++ b/function sqrt2.cpp @@ -0,0 +1,26 @@ +#include +float squart(float value){ + float left = 0.0f; + float right = value; + float mid = (left + right)/2; + while((mid*mid - 2) > 0.01 ||(2 - mid*mid)> 0.01){ + if (mid*mid < value){ + left = mid; + } + else{ + right = mid; + } + mid = (left + right)/2; + } + return mid; +} + +int main(){ +float target = 2.0f; +printf("%f",squart(target)); + ///squart(2.0f); + ///printf("%f",mid); صmidֵmid + return 0; +} + +///жʡԣ float squart(float x,float y,float z){} floatʡ diff --git a/sqrt2.cpp b/sqrt2.cpp new file mode 100644 index 00000000..84eabddb --- /dev/null +++ b/sqrt2.cpp @@ -0,0 +1,21 @@ +#include + + + +int main(){ + float target = 2.0f; + float left = 0.0f; + float right = target; + float mid = (left + right)/2; + while((mid*mid - 2) > 0.01 ||(2 - mid*mid)> 0.01){ + if (mid*mid < target){ + left = mid; + } + else{ + right = mid; + } + mid = (left + right)/2; + } + printf("%f",mid); + return 0; +} diff --git "a/\346\240\271\345\217\2672.cpp" "b/\346\240\271\345\217\2672.cpp" index 39afe90f..5e783474 100644 --- "a/\346\240\271\345\217\2672.cpp" +++ "b/\346\240\271\345\217\2672.cpp" @@ -1,16 +1,13 @@ #include #include int main(){ -float n = 3; -float mysqrt(n); -float x = n/2; - while (x - n > 0.0001 || n - x > 0.0001){ - if (x*x > n) - x = (0+x)/2; - else - x = (x+n)/2; - } - printf("%f",x); - return 0.0f; -return 0; + } + + +///a = 0, b = 4; +c = (a + b)/2; //c = 2 +if c*c-2>0,c=a+(a+b)/2 + + + From a54d1d623cb87eb1735a5987a4aac4ef9ae49716 Mon Sep 17 00:00:00 2001 From: wangcSCU <2020141240013@stu.scu.edu.cn> Date: Fri, 7 Jan 2022 23:09:57 +0800 Subject: [PATCH 4/4] =?UTF-8?q?=E4=BD=9C=E4=B8=9A?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- 1.cpp | 27 ++++++++++++ 10.15(2).cpp | 33 ++++++++++++++ 10.15.cpp | 12 +++++ average.cpp | 14 ++++++ homework.cpp | 18 ++++++++ homework1.cpp | 75 +++++++++++++++++++++++++++++++ homework3.cpp | 27 ++++++++++++ homework4.cpp | 36 +++++++++++++++ homework5.cpp | 35 +++++++++++++++ homework6.cpp | 80 ++++++++++++++++++++++++++++++++++ n!.cpp | 16 +++++++ "\345\274\200\346\226\271.cpp" | 21 +++++++++ 12 files changed, 394 insertions(+) create mode 100644 1.cpp create mode 100644 10.15(2).cpp create mode 100644 10.15.cpp create mode 100644 average.cpp create mode 100644 homework.cpp create mode 100644 homework1.cpp create mode 100644 homework3.cpp create mode 100644 homework4.cpp create mode 100644 homework5.cpp create mode 100644 homework6.cpp create mode 100644 n!.cpp create mode 100644 "\345\274\200\346\226\271.cpp" diff --git a/1.cpp b/1.cpp new file mode 100644 index 00000000..603b8e46 --- /dev/null +++ b/1.cpp @@ -0,0 +1,27 @@ +#include +int main(){ + int a, n, m, p, sum1 = 0, sum2 = 0, sum3 = 0; + printf("please put into a number between 0 and 100: "); + scanf("%d",&a); + + for(n = 0; n <= a; n = n +1){ + sum1 = sum1 + n; + } + printf("%d\n",sum1); //for + + while(m <= a){ + sum2 = sum2 + m; + m++; + } + printf("%d\n",sum2); //while + + do{ + p++; + sum3 = sum3 + p; + }while(p < a); + printf("%d\n",sum3); //do while + + + return 0; + +} diff --git a/10.15(2).cpp b/10.15(2).cpp new file mode 100644 index 00000000..700a5f68 --- /dev/null +++ b/10.15(2).cpp @@ -0,0 +1,33 @@ +#include +int main(){ +/*first + int i = 1; + float m = 3.2; + printf("%f %d",m,i);*/ +/*second + printf("item\tunit\tpurchase\n\tprice\tdate\n"); + printf("\\"); + printf("\"");*/ + +/*third + int i = 40; + float x = 839.21f; + printf("|%d|%5d|%-5d|%5.3d|\n",i,i,i,i); + printf("|%10.3f|%10.3e|%-10g|\n",x,x,x,x);*/ + +/*Adds two fractions*/ + int num1, denom1, num2, denom2, result_num, result_denom; + + printf("Enter first fraction:"); + scanf("%d/%d",&num1, &denom1); + + printf("Enter second fraction:"); + scanf("%d/%d",&num2, &denom2); + + result_num = num1 * denom2 + num2 * denom1; + result_denom = denom1 * denom2; + printf("The sum is %d/%d\n",result_num, result_denom); + + return 0; + +} diff --git a/10.15.cpp b/10.15.cpp new file mode 100644 index 00000000..2d3d763d --- /dev/null +++ b/10.15.cpp @@ -0,0 +1,12 @@ +#include +int main(){ + int height ,length ,width,v,v1; + scanf("%d",&height); + scanf("%d",&length); + scanf("%d",&width); + + v = height*length*width; + v1 = (v+165)/166; + printf("%d",v1); + return 0; +} diff --git a/average.cpp b/average.cpp new file mode 100644 index 00000000..5517822c --- /dev/null +++ b/average.cpp @@ -0,0 +1,14 @@ +//ƽֵ0 +#include +int main(){ + int number, sum = 0, count = 0; + + scanf("%d",&number); + while(number != 0){ + sum += number; + count ++; + scanf("%d",&number); + } + printf("%f\n",1.0*sum/count); + return 0; +} diff --git a/homework.cpp b/homework.cpp new file mode 100644 index 00000000..e1add2be --- /dev/null +++ b/homework.cpp @@ -0,0 +1,18 @@ +#include +int main(){ + int i,n,k; + printf("\n"); + scanf("%d",&n);// + int a[n]; + printf("飺\n"); + for(i=0;i +int isPrime(int b){ + int n,cont=0; + if(b==2){ + return 1; + } + for(n=2;n=100){ + //λֺ + //printf("%dİλΪ%dʮλΪ%dλΪ%dλֵĺΪ%d\n",b,b/100,(b/10)%10,(b%100)%10,(b/100)+((b/10)%10)+((b%100)%10)); + if(isPrime((b/100)+((b/10)%10)+((b%100)%10))==1){ + return 1; + }else return 0; + } + else if (b<10000 && b>=1000){ + //printf("%dǧλΪ%dλΪ%dʮλΪ%dλΪ%dλֵĺΪ%d\n",b,b/1000,(b/100)%10,((b/10)%100)%10,((b%1000)%100)%10,(b/1000)+((b/100)%10)+(((b/10)%100)%10)+(((b%1000)%100)%10)); + if(isPrime((b/1000)+((b/100)%10)+(((b/10)%100)%10)+(((b%1000)%100)%10))==1){ + return 1; + } else return 0; + } +} + +int ssPrime(int b){ + if (b<1000 && b>=100){ + //987 + //λƽ + //printf("%dİλΪ%dʮλΪ%dλΪ%dλֵƽΪ%d\n",b,b/100,(b/10)%10,(b%100)%10,(b/100)*(b/100)+((b/10)%10)*((b/10)%10)+((b%100)%10)*((b%100)%10)); + if(isPrime((b/100)*(b/100)+((b/10)%10)*((b/10)%10)+((b%100)%10)*((b%100)%10))==1){ + return 1; + }else return 0; + + } + else if (b<10000 && b>=1000){ + //1765 + //printf("%dǧλΪ%dλΪ%dʮλΪ%dλΪ%dλֵƽΪ%d\n",b,b/1000,(b/100)%10,((b/10)%100)%10,((b%1000)%100)%10,(b/1000)*(b/1000)+((b/100)%10)*((b/100)%10)+(((b/10)%100)%10)*(((b/10)%100)%10)+(((b%1000)%100)%10)*(((b%1000)%100)%10)); + if(isPrime((b/1000)*(b/1000)+((b/100)%10)*((b/100)%10)+(((b/10)%100)%10)*(((b/10)%100)%10)+(((b%1000)%100)%10)*(((b%1000)%100)%10))==1){ + return 1; + } else return 0; + } +} + +int superPrime(int b){ + if(isPrime(b)==1){ + if(sPrime(b)==1){ + if(ssPrime(b)==1){ + printf("%d ",b); + return 1; + }else return 0; + } + } +} + +int main(){ + int b=100,sum=0,k=0; + for(b=100;b<10000;b++){ + if(superPrime(b)==1){ + sum+=b; + k++; + } + } + printf("\n%f",(float)sum/k); + return 0; +} + + + diff --git a/homework3.cpp b/homework3.cpp new file mode 100644 index 00000000..3f9c2a3a --- /dev/null +++ b/homework3.cpp @@ -0,0 +1,27 @@ +//f(n)ĶΪ0~nа1ĸ +//f(13)0~13а1 110111213f(13)=6 +//f(1) = 1 +//һf(n)=nnֵ +// 2021-11-04 + +#include +int f(int n){ + int i,sum=0,k; + for(i=1;i<=n;i++){//13 + for(k=i;k>0;){ + if(k%10==1){ + sum++; + } + k=k/10; + } + } + return sum; +} +int main(){ + for(int i=0;i<100;i++){ + if(f(i)==i) + printf("f(%d)=%d ",i,i); + } + return 0; +} + diff --git a/homework4.cpp b/homework4.cpp new file mode 100644 index 00000000..8de8a850 --- /dev/null +++ b/homework4.cpp @@ -0,0 +1,36 @@ +#include +int isPrime(int b){ + int n,cont=0; + if(b==2){ + return 1; + } + if(b<=0)return 0; + for(n=2;n +int main(){ + int x,y,i,j,mid,b[30]; + scanf("%d %d", &x, &y); + int a[30][2]={{3072,1728},{2720,1536},{2560,1600},{2560,1440},{2304,1728},{2048,1536},{1920,1200},{1920,1080},{1440,900},{1280,800},{1280,720},{1024,768},{1024,640},{800,600},{800,500},{800,450},{640,480},{640,400},{640,360},{480,360},{480,300},{480,270},{320,240},{320,200},{320,180},{240,180},{176,144},{160,120},{160,100},{160,90}}; + for(i=0;i<30;i++){ + if(x*y-a[i][0]*a[i][1]<0){ + b[i]=a[i][0]*a[i][1]-x*y; + }else b[i]=x*y-a[i][0]*a[i][1]; + } + for(i=0;i<30;i++){ + for(j=0;j<29-i;j++){ + if(b[j]>b[j+1]){ + mid=b[j+1]; + b[j+1]=b[j]; + b[j]=mid; + } + } + } + for(i=0;i<30;i++){ + if(b[0]==a[i][0]*a[i][1]-x*y||b[0]==x*y-a[i][0]*a[i][1]){ + printf("ѡеķֱ%d%d",a[i][0],a[i][1]); + } + } + + return 0; +} + diff --git a/homework6.cpp b/homework6.cpp new file mode 100644 index 00000000..08eaba1b --- /dev/null +++ b/homework6.cpp @@ -0,0 +1,80 @@ +#include +#include + +int min(int x, int y) { + return x < y ? x : y; +} + +int max(int x, int y) { + return x > y ? x : y; +} + +void convolution(int* input1, int* input2, int* output, int mm, int nn) +{ + //洢ַ + int* xx = (int*)malloc(sizeof(int) * (mm + nn - 1)); + //ʼ + for (int i = 0; i < mm + nn - 1; i++) + { + xx[i] = 0; + //λٵľΪ + for (int j = 0; j < min(mm,nn) ; j++) { + //һȵڶִ + if (mm <= nn) { + if (i - j >= 0 && i - j < max(mm, nn)) { + printf("%d ", input1[j]); + printf("%d ", input2[i-j]); + xx[i] += input1[j] * input2[i - j]; + } + } + //һȵڶִ + else { + if (i - j >= 0 && i - j < max(mm, nn)) { + printf("%d ", input1[i-j]); + printf("%d ", input2[j]); + xx[i] += input2[j] * input1[i - j]; + } + } + printf("\n"); + } + } + printf("\n"); + for (int i = 0; i < mm+nn-1; i++) { + output[i] = xx[i]; + } + delete[] xx; +} + +int main() { + int mm, nn; + printf("һĿ\n"); + scanf_s("%d", &mm); + + //mallocռ + int* input1 = (int*)malloc(sizeof(int) * mm); + printf("һֵ\n"); + for (int i = 0; i < mm; i++) { + scanf_s("%d", &input1[i]); + } + printf("ڶĿ\n"); + scanf_s("%d", &nn); + int* input2 = (int*)malloc(sizeof(int) * nn); + printf("ڶֵ\n"); + for (int j = 0; j < nn; j++) { + scanf_s("%d", &input2[j]); + } + + //ռ + int* output = (int*)malloc(sizeof(int) * (mm+nn-1)); + convolution(input1, input2, output, mm, nn); + + printf("\n"); + for (int i = 0; i < mm + nn - 1; i++) + { + printf("%d ", output[i]); + } + printf("\n"); + + return 0; +} + diff --git a/n!.cpp b/n!.cpp new file mode 100644 index 00000000..39038ed8 --- /dev/null +++ b/n!.cpp @@ -0,0 +1,16 @@ +//Ľ׳ +#include +int main(){ + int a; + int b = 1; + scanf("%d",&a); + while(a > 1){ + + b = a * b; + a--; + } + printf("%d",b); + + return 0 ; + +} diff --git "a/\345\274\200\346\226\271.cpp" "b/\345\274\200\346\226\271.cpp" new file mode 100644 index 00000000..76153741 --- /dev/null +++ "b/\345\274\200\346\226\271.cpp" @@ -0,0 +1,21 @@ +#include + +int main(){ + float a,b,c; + float u; + printf("\n"); + scanf("%f",&u); + a=0.0f,b=u; + c=(a+b)/2; + while(b-a>0.0001){ + if(c*c>=u){ + b=c; + c=(a+b)/2; + }else if(c*c