BEGIN-2 序列求和
问题描述:
C语言代码:
#include <stdio.h>
int main(){
long long n;
scanf("%I64d",&n);
printf("%I64d",n*(n+1)/2);
return 0;
}
java代码:
import java.util.Scanner;
public class Main{
public static void main(String[] args) {
Scanner input = new Scanner(System.in);
long s = input.nextLong();
System.out.println(s*(s+1)/2);
}
}
BEGIN-3 圆的面积
问题描述:
C语言代码:
#include <stdio.h>
#define PI 3.14159265358979323
int main(){
int R;
double sum=.0;
scanf("%d",&R);
sum=PI*R*R;
printf("%.7lf",sum);
return 0;
}
Java代码:
import java.util.Scanner;
public class Main{
public static final double PI=3.14159265358979323;
public static void main(String[] args) {
double sum;
Scanner input = new Scanner(System.in);
int R = input.nextInt();
sum=PI*R*R;
System.out.printf("%.7f",sum);
}
}
BEGIN-4 Fibonacci数列
问题描述:
C语言代码:
#include<stdio.h>
#define M 10007
int main()
{
int a1,a2;
a1=a2=1;
int sum=1;//sum用来保存余数的变量
long n;
long i;
scanf("%ld",&n);
for(i=3;i<=n;i++)
{
sum=(a1%M+a2%M)%M;
a1=a2;
a2=sum;
}
printf("%d\n",sum);
return 0;
}
Java代码:
package 蓝桥杯;
import java.util.*;
public class Main {
public static int MAX=10007;
public static void main(String[] args) {
Scanner input = new Scanner(System.in);
int a = input.nextInt();
int arr1=1;
int arr2=1;
int rem=1;
for(int i=3;i<=a;i++){
rem=(arr1%MAX+arr2%MAX)%MAX;
arr1=arr2;
arr2=rem;
}
System.out.println(rem);
}
}