7-1 有志者,事竟成!
直接输出即可
#include <stdio.h>
int main()
{
printf("===========================================\n");
printf(" Nothing is impossible to a willing heart!\n");
printf("===========================================\n");
return 0;
}
7-2 3721数
本题考察了if条件判断语句和循环
#include <stdio.h>
int main()
{
for(int i = 1; i < 100; i++)
{
if( i % 3 == 2 && i % 7 == 1 )
printf("%d\n", i);
}
return 0;
}
当然,如果代码能力有限也可以手算,把编译器语言直接改成PHP输入答案即可
8
29
50
71
92
7-3 判断闰年
首先明确什么是闰年?1、能被4整除,但不能被100整除;2、能被400整除; 然后使用if语句判断年份即可 要特别注意输出的内容
#include <stdio.h>
int main()
{
int year;
scanf("%d", &year);
if( year % 400 == 0 || ( year % 4 == 0 && year % 100 != 0))
{
printf("YE5");
}else
{
printf("N0");
}
return 0;
}
7-4 365次方
可以使用循环也可以使用math库里面的pow方法
#include <stdio.h>
int main()
{
double x;
scanf("%lf", &x);
printf("%.8f\n%.8f", pow(( 1 + x ), 365 ), pow(( 1 - x ), 365));
return 0;
}
7-5 简单的鸡兔同笼
7-6 Another chicken and rabbit cage?
鸡兔同笼 略
7-7 求一元二次方程的根
# include <stdio.h>
# include <stdlib.h>
# include <math.h>
int main() {
double a,b,c,value,value1,complex;
scanf("%lf %lf %lf",&a,&b,&c);
double de_ta = b * b - 4 * a * c;
if (a == 0 && b == 0) {
if (c == 0) printf("Zero Equation");
else printf("Not An Equation");
}else {
if (de_ta == 0) {
value = (-1 * b) / (2 * a);
printf("%.2lf",value);
}else if (de_ta > 0) {
if (a == 0) {
value = (-1) * (c / b);
printf("%.2lf",value);
}else {
value = (-1 * b - sqrt(de_ta)) / (2 * a);
value1 = (-1 * b + sqrt(de_ta)) / (2 * a);
printf("%.2lf\n%.2lf",value1,value);
}
}else {
value1 = sqrt(-1 * de_ta) / (2 * a);
value = (-1) * (b / (2 * a));
if (b == 0) {
printf("0.00+%.2lfi\n0.00%.2lfi",value1,-1*value1);
}else {
complex = (value1 > 0) ? value1:(-1)*value1;
printf("%.2lf+%.2lfi\n%.2lf%.2lfi",value,complex,value,-1*complex);
}
}
}
return 0;
}
7-8 日K蜡烛图
#include<stdio.h>
int main()
{
double open=0,close=0,high=0,low=0;
scanf("%lf %lf %lf %lf",&open,&high,&low,&close);
if(close<open)
printf("BW-Solid");
else if(close>open)
printf("R-Hollow");
else
printf("R-Cross");
if((low<open&&low<close)&&(high>open&&high>close))
printf(" with Lower Shadow and Upper Shadow");
else if(low<open&&low<close)
printf(" with Lower Shadow");
else if(high>open&&high>close)
printf(" with Upper Shadow");
return 0;
}
7-9 Bash博弈
#include <stdio.h>
int main()
{
int n[5]={18,23,4,9,15}, m[5]={8,5,9,2,4};
for (int i = 0; i < 5; i++)
{
if (n[i] % (m[i] + 1) == 0)
{
printf("GG\n");
}
else
{
printf("JJ\n");
}
}
return 0;
}
|