数组循环输入输出
#include <stdio.h>
int main()
{
int num[1024], n;
scanf("%d", &n);
for (int i = 0; i < n; i++)
scanf("%d", &num[i]);
for (int i = 0; i < n; i++)
printf("%d ", num[i]);
}
圆柱体的表面积
#include <stdio.h>
#include <math.h>
int main()
{
const double pi = acos(-1.0);
double r, h, s1, s2, s;
scanf("%lf%lf", &r, &h);
s1 = pi * r * r;
s2 = 2 * pi * r * h;
s = s1 * 2.0 + s2;
printf("Area = %.3f\n", s);
return 0;
}
交换变量-1
#include <stdio.h>
int main()
{
int a, b, t;
scanf("%d%d", &a, &b);
t = a;
a = b;
b = t;
printf("%d %d\\n", a, b);
return 0;
}
交换变量-2
#include <stdio.h>
int main()
{
int a, b;
scanf("%d%d", &a, &b);
a = a + b;
b = a - b;
a = a - b;
printf("%d %d", a, b);
return 0;
}
交换变量-3
#include <stdio.h>
int main()
{
int a, b;
scanf("%d%d", &a, &b);
printf("%d %d", b, a);
return 0;
}