1、
#include
main()
{
int a, b, square;
scanf (“%d%d”, &a, &b);
square = a * a b * b;
if (square > 100) *判断a、b的平方和是否大于100 *、
{
printf (“their square is bigger than 100
”);
printf (“the digitale bigger than 100 is :%d”, square / 100);
}
else
{
printf (“their square is smaller than 100
”);
printf (“their addtion is: %d”, a b);
}
}
2、
#include
main()
{
int n;
if ((n % 5 == 0) && (n % 7 == 0)) * 判断n是否为5和7的公倍数 *
{
printf (“5 and 7 yes”);
}
else
{
if (n % 3 == 0) * 判断是否能被3整除 *
printf (“ 3 yes”);
else
printf (“no”);
}
}
3、(3题和平共处题与第2题相似的,只要把条件改一下就可以了)
#include
main()
{
int n;
if ((n % 3 == 0) && (n % 5 == 0))
{
printf (“3 and 5 yes”);
}
else
{
if (n % 7 == 0)
printf (“ 7 yes”);
else
printf (“no”);
}
}
4、
#include
main()
{
int n;
if ((n % 2 == 0) && (n % 3 == 0))
{
printf (“2&3 yes”);
}
else
{
if (n % 7 == 0)
printf (“ 3 yes”);
else
printf (“no”);
}
}
5、
#include
main()
{
int x, y;
printf ("x =");
scanf ("%d", &x);
if (x == 2) * 用一个多分支语句将几种情况分开计算*
y = 2 * x;
else if (x
main()
{
int x, y;
printf ("x =");
scanf ("%d", &x);
if (x == 1)
y = 1;
else if (x
main()
{
int x, y;
printf ("x =");
scanf ("%d", &x);
if (x
main()
{
int x, y;
printf ("x =");
scanf ("%d", &x);
if (x
main()
{
float score;
char grade;
printf ("please enter the score:");
scanf ("%f", &score);
if (score > 100 || score = 90)
grade = 'A';
else if (score >= 80)
*在这里的else if 语句条件中已经排除了在于等于90的情况,即此处等同于"score >= 80 && score = 70)
grade = 'C';
else if (score >= 60)
grade = 'D';
else
grade = 'E';
printf ("the grade is :%c", grade);
}
10、
#include
main()
{
int n, price;
printf ("please enter quantity:");
scanf ("%d", &n);
if (n
#include
main()
{
int a, b,final;
printf ("enter a,b:");
scanf ("%d%d", &a, &b);
if (a % b == 0)
final = a * a b * b;
else if ( b % a == 0)
final = a * a * a b * b * b;
else
final = abs(a - b);
printf ("final = %d", final);
}
12、
#include
#include
main()
{
float a, b, f;
printf ("enter a,b:");
scanf ("%f%f", &a, &b);
if (a > b)
f = fabs(a - b);
else if (a
#include
main()
{
int a, b, c, disc;
int x1, x2,x;
printf ("a,b,c=");
scanf ("%d%d%d", &a, &b, &c);
if (a == 0)
{
printf ("this is not a equation");
}
else
{
disc = b * b - 4 * a * c;
if ( disc > 0)
{
x1 = (- b sqrt(disc)) / (2 * a);
x2 = - b - sqrt(disc) / (2 * a);
printf ("there are two deferent root:%d %d", x1, x2);
}
else
{
x = - b / ( 2 * a);
printf ("there are two same root:%d", x);
}
}
}
14、
#include
main()
{
int n;
int n1, n2, n3;
printf ("please enter a number:");
scanf ("%d", &n);
if (n >= 100 && n
main()
{
enum workday {monday = 1, tuesday, wednesday, thursday, friday, saturday, sunday};
enum workday workdays;
int n;
printf ("please enter a days:");
scanf ("", &n);
if (n >= 1 && n
main()
{
int i, n;
float t, s = 0; * 用t 产生各项,s 为各项之和 *
printf ("n = ");
scanf ("%d", &n);
for (i = 1; i <= n; i )
{
t = 1。
0 / n; * 因为n 是整数,在1后面加小数使得结果不至于为零*
s = s t;
n = n 2;
}
printf ("the addtion is :%f", s);
}。
全部