赞
踩
#include<stdio.h>
#include<math.h>
void main(){
int a,b,c;
scanf("%d%d%d",&a,&b,&c);
printf("%lf",sqrt(1.0*(a*a+b*b+c*c)));
}
#include<iostream>
using namespace std;
void main(){
int a,b,c;
cin>>a>>b>>c;
cout<<sqrt(1.0*(a*a+b*b+c*c));
}
import java.util.*;
public class one {
private static int x,y,z;
public static void main(String[] args) {
Scanner sc = new Scanner(System.in);
int x = sc.nextInt();
int y = sc.nextInt();
int z = sc.nextInt();
System.out.print(Math.sqrt(x*x+y*y+z*z));
}
}
x,y,z = map(int,input().split())
print((x*x+y*y+z*z)**0.5)
a>b?a:c>d?c:d应该理解为:a>b?a:(c>d?c:d)
#include<stdio.h> void main(){ float a,b,c; scanf("%f%f%f",&a,&b,&c); if((a+b)>c&&(b+c)>a&&(a+c)>b){ if(a==b==c) printf("等边三角形"); else if((a==b)||(a==c)||(a==c)) printf("等腰三角形"); else if((a*a+b*b)==c*c||(a*a+c*c)==b*b||(b*b+c*c)==a*a) printf("直角三角形"); else printf("普通三角形"); }else printf("不构成三角形"); }
import java.util.*; public class one { private static int a,b,c; public static void main(String[] args) { Scanner sc = new Scanner(System.in); int a = sc.nextInt(); int b = sc.nextInt(); int c = sc.nextInt(); if((a+b)>c&&(b+c)>a&&(a+c)>b){ if(a==b&&a==c) System.out.print("等边三角形"); else if((a==b)||(a==c)||(a==c)) System.out.print("等腰三角形"); else if((a*a+b*b)==c*c||(a*a+c*c)==b*b||(b*b+c*c)==a*a) System.out.print("直角三角形"); else System.out.print("普通三角形"); }else System.out.print("不构成三角形"); } }
a,b,c = map(int,input().split())
if (a+b)>c and (b+c)>a and (a+c)>b:
if a==b==c:
print("等边三角形")
elif a==b or a==c or a==c:
print("等腰三角形")
elif (a*a+b*b)==c*c or (a*a+c*c)==b*b or (b*b+c*c)==a*a:
print("直角三角形")
else:
print("普通三角形")
else:
print("不构成三角形")
//#include<bits/stdc++.h> #include<iostream> #include<cmath> using namespace std; int day[13]={0,31,28,31,30,31,30,31,31,30,31,30,31}; int main(){ int y1,m1,d1,y2,m2,d2,ans; ans=1; cin>>y1>>m1>>d1; cin>>y2>>m2>>d2; for(int i=y1;i<=y2;i++){ if(i==y2){ if(i%400==0||(i%4==0&&i%100!=0)){ day[2]=29; }else{ day[2]=28; } ans+=(day[m1]-d1); for(int j=m1+1;j<m2;j++){ ans+=day[j]; } ans+=d2; break; }else if(i==y2-1){ if(i%400==0||(i%4==0&&i%100!=0)){ day[2]=29; }else{ day[2]=28; } ans+=(day[m1]-d1); for(int a=m1+1;a<=12;a++){ ans+=day[a]; } for(int b=1;b<m2;b++){ ans+=day[b]; } ans+=d2; break; }else{ if(i%400==0||(i%4==0&&i%100!=0)){ ans+=366; }else{ ans+=365; } } } cout<<ans; return 0; }
#include<stdio.h> int main(){ int y,m,d,flag,s=0,i,p=1; while(p){ scanf("%d %d %d",&y,&m,&d); flag=(y%4==0&&y%100!=0||y%400==0); if(m==1||m==3||m==5||m==7||m==8||m==10||m==12){ if(d>=1&&d<=31){ p=0; } }else if(m==4||m==6||m==9||m==11){ if(d>=1&&d<=31){ p=0; } }else if(m==2){ if(d>=1&&d<=28+flag){ p=0; } }else{ p=1; } } for(i=1;i<=m;i++){ switch(i){ case 1:s=d;break; case 2:s=31+d;break; case 3:s=59+d;break; case 4:s=90+d;break; case 5:s=120+d;break; case 6:s=151+d;break; case 7:s=181+d;break; case 8:s=212+d;break; case 9:s=243+d;break; case 10:s=273+d;break; case 11:s=304+d;break; case 12:s=334+d;break; } } if(flag==1&&m>2){ s+=1; } printf("%d年%d月%d日是第%d天\n",y,m,d,s); return 0; }
y = int(input('请输入相应的年份,如2022>>>')) m = int(input('请输入相应的月份,如2>>>')) d = int(input('请输入相应的日期,如4>>>')) past_days = d if (y % 4 == 0 and y % 100 != 0) or (y % 400 == 0): ca = {1: 31, 2: 29, 3: 31, 4: 30, 5: 31, 6: 30, 7: 31, 8: 31, 9: 30, 10: 31, 11: 30, 12: 31} if m == 1: print('这是这一年的第', past_days, '天') else: for m in range(1, m): past_days += ca[m] print('这是这一年的第', past_days, '天') else: ca = {1: 31, 2: 28, 3: 31, 4: 30, 5: 31, 6: 30, 7: 31, 8: 31, 9: 30, 10: 31, 11: 30, 12: 31} if m == 1: print('这是这一年的第', past_days, '天') else: for m in range(1, m): past_days += ca[m] print('这是这一年的第', past_days, '天')
import time
y = input('请输入相应的年份,如2022>>>')
m = input('请输入相应的月份,如2>>>')
d = input('请输入相应的日期,如4>>>')
read_time = y + '-' + m + '-' + d
# 把用户输入的时间转换成一种格式化的显示,比如2019-8-25
t = time.strptime(read_time, '%Y-%m-%d')
# time模块的strptime方法可以把格式化的时间变成时间元组,
# 比如time.struct_time
# (tm_year=2019, tm_mon=4, tm_mday=9, tm_hour=0, tm_min=0, tm_sec=0, tm_wday=1, tm_yday=99, tm_isdst=-1)
print('这一天是这一年的第', t.tm_yday, '天')
# 时间元组中tm_yday对应的值就是这一天是这一年的第几天,所以直接取出来用就行
#include<stdio.h>
#include<math.h>
void main(){
float x,p,s,t;
int n=0,f=1;
x=0.5;p=1;s=x;t=x;
while(fabs(t)>=1e-6){
n++;
p=p*n;
f=-f;
t=(f*pow(x,2*n+1))/((2*n+1)*p);
s+=t;
}
printf("s=%f\n",s);
}
import java.util.*; public class one { private static int n=0,f=1; private static float x,p,s,t,c; public static void main(String[] args) { x = (float) 0.5;p=1;s=x;t=x; while(Math.abs(t)>=1e-6){ n++; p=p*n; f=-f; c=(float)Math.pow(x,2*n+1); t=(f*c)/((2*n+1)*p); s+=t; } System.out.printf("s=%f\n",s); } }
import math
n,f,x,p = 0,1,0.5,1
s = x
t = x
while math.fabs(t)>=1e-6:
n = n+1#python里面无自增
p = p*n
f = -f
t = (f*pow(x,2*n+1))/((2*n+1)*p)
s += t
print(s)
#include<stdio.h>
#include<math.h>
void main(){
float x0,x,r,fx1,fx,fr,eps=1e-5;
x=1.0;
do{
x0=x;
fx=x0-1-cos(x0);
fx1=1+sin(x0);
x=x0-fx/fx1;
}while(fabs(x-x0)>=eps);
printf("root=%.2f\n",x);
}
C语言中函数abs和fabs有什么区别?
区别一:用法不同
1、abs()是对整数取绝对值
2、fabs()是对浮点数取绝对值
区别二:函数原型不同
1、abs的函数原型为:int abs(int x)
2、fabs的函数原型为:double fabs(double x)
区别三:头文件不同
1、abs(): #include <stdlib.h>
2、fabs(): #include <math.h>
#include<stdio.h>
void main(){
int f1=1,f2=1,f3,i;
printf("%d\t%d\n",f1,f2);
for(i=3;i<=12;i++){
f3 = f1+f2;
printf("%d%c",f3,i%2?'\t':'\n');
f1 = f2;
f2 = f3;
}
}
import java.util.*;
public class one {
private static int f1=1,f2=1,f3,i;
public static void main(String[] args) {
System.out.printf("%d\t%d\n",f1,f2);
for(i=3;i<=12;i++){
f3 = f1+f2;
System.out.printf("%d%c",f3,i%2==1?'\t':'\n');
f1 = f2;
f2 = f3;
}
}
}
f1,f2 = 1,1
print(f1,f2)
for i in range(3,13):
f3 = f1+f2
f1 = f2
f2 = f3
if i % 2:
print(f2, f1+f2)
#include<stdio.h>
#include<math.h>
void main(){
int m,i;
scanf("%d",&m);
for(i=2;i<=sqrt(1.0*m);i++)
if(m%i==0)
break;
if(i>sqrt(1.0*m))
printf("Y");
else
printf("N");
}
import java.util.*;
public class one {
private static int m,i;
public static void main(String[] args) {
Scanner sc = new Scanner(System.in);
m = sc.nextInt();
for(i=2;i<=Math.sqrt(m);i++)
if(m%i==0)
break;
if(i>Math.sqrt(m))
System.out.printf("Y");
else
System.out.printf("N");
}
}
import math
m = eval(input())
n = 1
for i in range(2,int(math.sqrt(m))+1):
if m % i == 0:
print("N")
n = 0
break
if n==1:
print("Y")
#include<stdio.h>
void main(){
int n;
for(n=1000;n<10000;n++)
if(n*9==((n%10)*1000+(n/10%10)*100+(n/100%10)*10+(n/1000)))
printf("%d\t",n);
}
#include<stdio.h>
void main(){
int n;
for(n=1;n<1000;n++)
if(n==((n%10)*(n%10)*(n%10)+(n/10%10)*(n/10%10)*(n/10%10)+(n/100)*(n/100)*(n/100)))
printf("%d\t",n);
}
#include<iostream>
#include<cmath>
using namespace std;
void main(){
int n;
for(n=1;n<1000;n++){
double x=double(n%10);
double y=double(n/10%10);
double z=double(n/100);
if(double (n)==(pow(x,3)+pow(y,3)+pow(z,3)))
printf("%d ",int(n));
}
}
import java.util.*;
public class one {
private static int n;
public static void main(String[] args) {
for(n=1;n<1000;n++)
if(n==(Math.pow(n%10,3)+Math.pow(n/10%10,3)+Math.pow(n/100,3)))
System.out.print(n+" ");
}
}
for num in range(0,1000):
total = 0
num_str = str(num) #先转成字符型
for i in num_str:
total += int(i)**3
if total == num:
print(f"{num}是阿姆斯特朗数")
num_str = str(567) #先转成字符型
for i in num_str:
print(i)
#输出情况:
5
6
7
#include <iostream> #include<cmath> using namespace std; int prime(int n);//判断是否为素数 int main() { int i,n; for(i=4;i<=1000;i+=2) { for(n=2;n<i;n++) if(prime(n)&&prime(i-n)){ cout<<i<<"="<<n<<"+"<<i-n<<endl; break; } if(n==i) cout<<"error "<<endl; } return 0; } int prime(int i) { int j; if(i<=1)return 0; if(i==2)return 1; for(j=2;j<=(int)(sqrt((double)i));j++) if(i%j==0) return 0; return 1; }
import java.util.*; public class one { public static boolean isPrimeNumber(int n) { if(n<2)//所有小于2的整数包括负整数、0和1既不是质数、也不是合数 { return false; } for(int i=2;i<=Math.sqrt(n);i++)//当判断2时,由于既不符合if(n<2)又不符合for(int i=2;i<n;i++)直接返回true,1是所有n>=2的所有整数的公因素,所以计数直接从2开始 //质数的约数只有1和本身,不能被比它小的数整除 { if(n%i==0) { return false; } } return true; } public static void main(String[] args) { System.out.println("请输入验证哥德巴赫猜想需要查询数的范围:"); Scanner sc=new Scanner(System.in); int m=sc.nextInt(); System.out.println("输出结果为:"); for(int n=4;n<=m;n+=2)//哥德巴赫猜想前提是任意一个不小于3的偶数,所以计数从n=4开始,且以n+=2增加保证全是偶数 { for(int i=2;i<n;i++) { if(isPrimeNumber(i)&&isPrimeNumber(n-i)) { System.out.println(n+"="+i+","+(n-i)); } } } } }
def isprime(n): i = 2 while i<n: if n%i==0: return False i += 1 return True def guss(num): for j in range(2,num): if isprime(j) and isprime(num-j): print(num,'=',j,'+',num-j) return True return False k = 4 while guss(k) and k<1000: k += 2
#include<stdio.h>
void main(){
for(int i=1;i<=9;i++){
for(int j=1;j<=4*i-4;j++)
printf(" ");
for(int k=i;k<=9;k++)
printf("%4d",i*k);
printf("\n");
}
}
闰年表达式:(y%4==0&&y%100!=0)||(y%400==0)
continue;//后面语句不执行,直接开始下次循环!
#include<stdio.h> void main(){ int i,j; for(i=0;i<3;i++,i++) for(j=4;j>=0;j--){ if((i+j)%2){ j--; printf("%d, ",j); continue; } --i; j--; printf("%d, ",j); } }
#include<stdio.h>
void main(){
int i,k,m;
for(k=0,i=5;i<=1000;i+=5){
m=i;
while(m%5==0){
k++;
m/=5;
}
}
printf("%d\n",k);
}
#include<stdio.h>
void main(){
char cx,front='\0';
while((cx=getchar())!='\n'){
if(cx!=' ') putchar(cx);
if(cx==' '&&cx!=front)
putchar(cx);
front=cx;
}
}
Copyright © 2003-2013 www.wpsshop.cn 版权所有,并保留所有权利。