鄙人不才,是个小白,以下写的代码仅供参考,如有问题请及时提出,谢谢各位师傅。
P.S.我没有写文章的经验,哪里有问题请提出来。
#include
int main() {
int a, b, c, d;
scanf("%d%d", &a, &b);
c = 2 * (a + b);
d = a * b;
printf("%d\n%d", c, d);
return 0;
}
#include
#include
int main() {
double a, b, c, d, e, f;
scanf("%lf %lf", &a, &b);
c = 2.0;
d = sqrt(pow(a, c) + pow(b, c));
e = a + b + d;
f = (a * b) / 2.0;
printf("%.2f\n%.2f", e, f);
return 0;
}
#include
#include
#define PI 3.14159
int main() {
double a;
scanf("%lf",&a);
printf("%.3f\n%.3f",2 * PI * a, PI * pow(a, 2));
return 0;
}
#include
int main() {
int a, b, c;
scanf("%d", &a);
for(b = 1; b <= a; b++){
for(c = 0; c < a; c++){
printf("%d", b);
if(c != a - 1) printf(" ");
}
if(c = a - 1) printf("\n");
}
return 0;
}
#include
int main() {
int a, b, c, d;
scanf ("%d", &a);
d = a; //防止a被修改
for (b = 1; b <= a; b++)
{
for (c = d; c >= 1; c--)
{
printf ("%d", b);
if (c != 1) printf (" ");
else
{
printf ("\n");
d--;
break;
}
}
}
return 0;
}
#include
int main() {
int a, b, c, d, f;
scanf("%d", &a);
f = a; //防止a被修改
for (b = a; b >= 1; b--)
{
d = b;
for(c = f; c >= 1; c--)
{
printf ("%d", d);
if (c != 1)
{
printf (" ");
d--;
}
else
{
printf ("\n");
f--;
break;
}
}
}
return 0;
}
#include
int main() {
int a, b, c, d, e, f;
scanf("%d",&a);
f = a; //防止a被修改
for(b = 1; b <= a; b++){
d = b;
for(c = f; c >= 1 && d <= a; c--){
e = b * d;
printf ("%d*%d=%d",b,d,e);
if (c!=1)
{
printf("\t");
d++;
}
else
{
printf ("\n");
f--;
}
}
}
return 0;
}
#include
void upper_case_count(char arr[31]) {
// 请在下面实现统计并输出大写字母个数的功能
int a, b, c;
c = 0;
for (a = 0; a < 31; a++)
{
if (65 <= arr[a] && arr[a] <= 90) b = 1;
else b = 0;
c = c + b;
}
printf ("%d\n",c);
}
void lower_case_count(char arr[31]) {
// 请在下面实现统计并输出小写字母个数的功能
int a, b, c;
c = 0;
for (a = 0; a < 31; a++)
{
if (97 <= arr[a] && arr[a] <= 122) b = 1;
else b = 0;
c = c + b;
}
printf ("%d\n",c);
}
void digit_count(char arr[31]) {
// 请在下面实现统计并输出数字个数的功能
int a, b, c;
c = 0;
for (a = 0; a < 31; a++)
{
if (48 <= arr[a] && arr[a] <= 57) b = 1;
else b = 0;
c = c + b;
}
printf ("%d\n",c);
}
void space_count(char arr[31]) {
// 请在下面实现统计并输出空格个数的功能
int a, b, c;
c = 0;
for (a = 0; a < 31; a++)
{
if (arr[a] == 32) b = 1;
else b = 0;
c = c + b;
}
printf ("%d",c);
}
int main(){
char string[31];
int i;
for (i = 0; i < 30; i++) scanf ("%c",&string[i]);
upper_case_count(string);
lower_case_count(string);
digit_count(string);
space_count(string);
return 0;
}
#include
int gcd(int n, int m);
int lcm(int n, int m);
int main()
{
int n, m;
scanf("%d%d", &n, &m);
printf("%d\n", gcd(n, m));
printf("%d\n", lcm(n, m));
return 0;
}
int gcd(int n, int m)
{
if (m <= n) {
int a;
a = n % m;
if (a == 0) return m;
else
{
n = m;
m = a;
gcd (n,m);
}
}
else return gcd(m, n);
}
int lcm(int n, int m)
{
// 请在这里继续完成 lcm 函数
int a;
a = (n * m) / gcd (n,m);
return a;
}
#include
#define max(a,b) a>b?a:b
int sum1 (int num[3][3]);
int sum2 (int num[2][2]);
int main ()
{
int num1[3][3], num2[2][2];
int i, j;
for (i = 0; i < 3; i++)
{
for (j = 0; j < 3; j++) scanf ("%d",&num1[i][j]);
}
for (i = 0; i < 2; i++)
{
for (j = 0; j < 2; j++) scanf ("%d",&num2[i][j]);
}
i = sum1 (num1);
j = sum2 (num2);
printf ("%d",max(i,j));
return 0;
}
int sum1 (int num[3][3]) //计算三阶行列式的和
{
int sum;
int m, n;
m = num[0][0] * num[1][1] * num[2][2] + num[0][1] * num[1][2] * num[2][0] + num[1][0] * num[2][1] * num[0][2];
n = num[0][2] * num[1][1] * num[2][0] + num[0][1] * num[1][0] * num[2][2] + num[0][0] * num[2][1] * num[1][2];
sum = m - n;
return sum;
}
int sum2 (int num[2][2]) //计算二阶行列式的和
{
int sum;
sum = num[0][0] * num[1][1] - num[0][1] * num[1][0];
return sum;
}
这个目前还没有写[/捂脸]
#include
#include
#include
int main() {
int n, a, b = 0;
scanf("%d", &n);
char **p;
p = (char**) malloc (n * sizeof (char*));
for (a = 0; a < n; a++)
{
p[a] = (char*) malloc (100 * sizeof (char));
gets (p[a]);
}
for (a = 0; a < n; a++)
{
if (strlen (p[a]) > strlen (p[b])) b = a;
else b = b;
}
printf ("%s\n", p[b]);
for (a = 0; a < n; a++) free (p[a]);
free (p);
return 0;
}
#include
#include
int main ()
{
int a[3] = {
0, 0, 0};
char j[4];
scanf ("%s", j);
getchar(); //清空缓冲区中的回车
for (int i = 0; i < strlen(j); i++)
{
if (j[i] == 'r') a[0] = 1;
else if (j[i] == 'w') a[1] = 1;
else if (j[i] == 'x') a[2] = 1;
}
char c[2];
while (scanf ("%s", c) != EOF)
{
if (c[0] == '+')
{
if (c[1] == 'r') a[0] = 1;
else if (c[1] == 'w') a[1] = 1;
else if (c[1] == 'x') a[2] = 1;
}
else
{
if (c[1] == 'r') a[0] = 0;
else if (c[1] == 'w') a[1] = 0;
else if (c[1] == 'x') a[2] = 0;
}
}
printf ("%d\n", 4 * a[0] + 2 * a[1] + a[2]);
return 0;
}
抱歉,这个我也没写[/捂脸]