Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

homework #169

Open
wants to merge 6 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
27 changes: 27 additions & 0 deletions 1.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
#include <stdio.h>
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;

}
33 changes: 33 additions & 0 deletions 10.15(2).cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
#include <stdio.h>
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;

}
12 changes: 12 additions & 0 deletions 10.15.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
#include<stdio.h>
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;
}
45 changes: 45 additions & 0 deletions 9.26bug作业.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
//��һԪ���η��̵ĸ�
// ���� ��y = x2 + 10x + 17
// �� x = 2, �� y = 41
// �� y = 2, �� x = ?
/*#include <stdio.h>
#include <math.h>
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 <stdio.h>
#include <math.h>
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;
} //��˳������󼴿�
2 changes: 1 addition & 1 deletion HelloWorld.c
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
#include <stdio.h>
int main() {
printf("Hello World!\n");
printf("Hello World!aaa\n");

//try Jenkins again
return 0;
Expand Down
14 changes: 14 additions & 0 deletions average.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
//��������������ƽ��ֵ������0�����������
#include <stdio.h>
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;
}
26 changes: 26 additions & 0 deletions function sqrt2.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
#include <stdio.h>
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����ʡ��
18 changes: 18 additions & 0 deletions homework.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
#include<stdio.h>
int main(){
int i,n,k;
printf("��������������\n");
scanf("%d",&n);//
int a[n];
printf("�������飺\n");
for(i=0;i<n;i++){
scanf("%d",&a[i]);
}
printf("���������еĴ�ɾ���\n");
scanf("%d",&k);
for(i=0;i<n;i++){
if(a[i]==k) continue;
else printf("%d ",a[i]);
}
return 0;
}
75 changes: 75 additions & 0 deletions homework1.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,75 @@
//��������������������λ���ֵĺͣ���λ���ֵ�ƽ���ͣ�����������
#include <stdio.h>
int isPrime(int b){
int n,cont=0;
if(b==2){
return 1;
}
for(n=2;n<b;n++){
if(b%n==0)cont++;
}
if(cont!=0){
return 0;
}else return 1;
}

int sPrime(int b){
if (b<1000 && b>=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;
}



27 changes: 27 additions & 0 deletions homework3.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
//f(n)�����Ķ���Ϊ0~n�а�����1�ĸ���
//f(13)��0~13���1���� 1��10��11��12��13������f(13)=6
//f(1) = 1��
//����һ��f(n)=n��nֵ
// 2021-11-04

#include<stdio.h>
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;
}

36 changes: 36 additions & 0 deletions homework4.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
#include<stdio.h>
int isPrime(int b){
int n,cont=0;
if(b==2){
return 1;
}
if(b<=0)return 0;
for(n=2;n<b;n++){
if(b%n==0)cont++;
}
if(cont!=0) return 0;
else return 1;
}
int ab(int a,int b){
int ret1=1,ret2=1;
int i=0;
for(i=0;i<b;i++){
ret1*=a;
}
for(i=0;i<a;i++){
ret2*=b;
}
return ret1+ret2;
}
int main(){
int p,q;
for(p=0;p<10;p++){
for(q=0;q<10;q++){
if(isPrime(p)==1&&isPrime(q)==1&&isPrime(ab(p,q))){
printf("%d %d\n",p,q);
}
}
}

return 0;
}
35 changes: 35 additions & 0 deletions homework5.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
//����һ���ַ���������
//3072x1728,2720x1536,2560x1600,2560x1440,2304x1728,2048x1536,1920x1200,1920x1080,1440x900,1280x800,1280x720,1024x768,1024x640,800x600,800x500,800x450,640x480,640x400,640x360,480x360,480x300,480x270,320x240,320x200,320x180,240x180,176x144,160x120,160x100,160x90
//����һ����ʾ��֧�ֵķֱ����嵥���м䶺�ŷָ���
//�������뻭��Ŀ��͸ߣ�Ȼ���������嵥����ѡһ����ӽ��ķֱ������
//��������2000��1000������ķֱ���Ӧ����1920x1080����Ϊ�����ֱ��ʵ�������
//������³���
// 2021-11-14
#include <stdio.h>
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;
}

Loading