赞
踩
试卷一:
#include <stdio.h>
int main() {
int a[5];
int i;
for (i = 0; i < 5; i++) {
a[i] = 0;
}
for (i = 0; i < 5; i++) {
printf("%d ", a[i]);
}
return 0;
}
#include <stdio.h>
#include <string.h>
#include <cstdlib>
struct Person {
char *name;
int age;
};
int main() {
struct Person p[3];
int i;
for (i = 0; i < 3; i++) {
p[i].name = (char *) malloc(20 * sizeof(char));
scanf("%s %d", p[i].name, &p[i].age);
}
for (i = 0; i < 3; i++) {
printf("%s %d", p[i].name, p[i].age);
}
}
#include <stdio.h>
void swap(int *a, int *b) {
int temp = *a;
*a = *b;
*b = temp;
}
int main() {
int a, b;
scanf("%d %d", &a, &b);
swap(&a, &b);
printf("%d %d", a, b);
return 0;
}
试卷二:
#include <stdio.h>
#include <string.h>
#include <cstdlib>
struct Book {
int id;
char *title;
float price;
};
int main() {
struct Book b;
b.title = (char *) malloc(20 * sizeof(char));
scanf("%d %s %f", &b.id, b.title, &b.price);
printf("%d %s %f", b.id, b.title, b.price);
return 0;
}
#include <stdio.h>
int fact(int n) {
int i;
int result = 1;
for (i = 1; i <= n; i++) {
result *= i;
}
return result;
}
int main() {
int n;
scanf("%d", &n);
printf("%d", fact(n));
return 0;
}
#include <stdio.h>
int main() {
int n;
scanf("%d", &n);
printf("%d", n % 10 * 100 + n / 10 % 10 * 10 + n / 100);
return 0;
}
试卷三:
#include <stdio.h>
#include <string.h>
#include <cstdlib>
struct Rectangle {
int width;
int height;
};
int main() {
struct Rectangle r;
scanf("%d %d", &r.width, &r.height);
printf("%d %d", r.width, r.height);
return 0;
}
#include <stdio.h>
int main() {
int a, b;
scanf("%d %d", &a, &b);
printf("%d %d %d %d", a + b, a - b, a * b, a / b);
return 0;
}
#include <stdio.h>
int max(int a, int b) {
return a > b ? a : b;
}
int main() {
int a, b;
scanf("%d %d", &a, &b);
printf("%d", max(a, b));
return 0;
}
试卷四:
#include <stdio.h>
#include <math.h>
int main() {
int a, b, c;
scanf("%d %d %d", &a, &b, &c);
if (a + b > c && a + c > b && b + c > a) {
printf("%f %f", a + b + c,
sqrt((a + b + c) / 2 * ((a + b + c) / 2 - a) * ((a + b + c) / 2 - b) * ((a + b + c) / 2 - c)));
} else {
printf("无法构成三角形");
}
return 0;
}
#include <stdio.h>
#include <string.h>
#include <cstdlib>
struct Person {
char *name;
int age;
};
int main() {
struct Person *p = (struct Person *) malloc(sizeof(struct Person));
p->name = (char *) malloc(20 * sizeof(char));
scanf("%s %d", p->name, &p->age);
printf("%s %d", p->name, p->age);
return 0;
}
#include <stdio.h>
float average(float a, float b) {
return (a + b) / 2;
}
int main() {
float a, b;
scanf("%f %f", &a, &b);
printf("%f", average(a, b));
return 0;
}
试卷五:
#include <stdio.h>
#include <string.h>
#include <cstdlib>
struct Student {
char *name;
int score;
char grade;
};
int main() {
struct Student s[3];
int i;
for (i = 0; i < 3; i++) {
s[i].name = (char *) malloc(20 * sizeof(char));
scanf("%s %d %c", s[i].name, &s[i].score, &s[i].grade);
}
for (i = 0; i < 3; i++) {
printf("%s %d %c", s[i].name, s[i].score, s[i].grade);
}
return 0;
}
#include <stdio.h>
int main() {
int n, i, sum1 = 0, sum2 = 0;
scanf("%d", &n);
for (i = 1; i <= n; i++) {
if (i % 2 == 0) {
sum1 += i;
} else {
sum2 += i;
}
}
printf("%d %d", sum1, sum2);
return 0;
}
#include <stdio.h>
#include <string.h>
int main() {
char s1[20], s2[20];
scanf("%s %s", s1, s2);
if (strcmp(s1, s2) == 0) {
printf("相等");
} else {
printf("不相等");
}
return 0;
}
试卷六:
#include <stdio.h>
#include <string.h>
#include <cstdlib>
struct Point {
float x;
float y;
};
int main() {
struct Point p[4];
int i;
for (i = 0; i < 4; i++) {
scanf("%f %f", &p[i].x, &p[i].y);
}
for (i = 0; i < 4; i++) {
printf("%f %f", p[i].x, p[i].y);
}
return 0;
}
#include <stdio.h>
int main() {
int n, i;
scanf("%d", &n);
for (i = 2; i <= n; i++) {
while (n % i == 0) {
printf("%d ", i);
n /= i;
}
}
return 0;
}
#include <stdio.h>
#include <math.h>
float power(float base, float exp) {
return pow(base, exp);
}
int main() {
float base, exp;
scanf("%f %f", &base, &exp);
printf("%f", power(base, exp));
return 0;
}
试卷七:
#include <stdio.h>
int main() {
int year;
scanf("%d", &year);
if (year % 4 == 0 && year % 100 != 0 || year % 400 == 0) {
printf("是闰年");
} else {
printf("不是闰年");
}
return 0;
}
#include <stdio.h>
int main(){
int n, m, sum = 0;
scanf("%d", &n);
m = n;
while (m != 0) {
sum = sum * 10 + m % 10;
m /= 10;
}
if (sum == n) {
printf("是回文数");
} else {
printf("不是回文数");
}
return 0;
}
#include <stdio.h>
int factorial(int n){
if (n == 1) {
return 1;
} else {
return n * factorial(n - 1);
}
}
int main() {
int n;
scanf("%d", &n);
printf("%d", factorial(n));
return 0;
}
试卷八:
#include <stdio.h>
struct Complex {
float real;
float imag;
};
int main() {
struct Complex c;
scanf("%f %f", &c.real, &c.imag);
printf("%f %f", c.real, c.imag);
return 0;
}
#include <stdio.h>
int main() {
int n, i, count = 0;
scanf("%d", &n);
for (i = 1; i <= n; i++) {
if (n % i == 0) {
count++;
}
}
printf("%d", count);
return 0;
}
#include <stdio.h>
int main() {
int n, i;
float sum = 0;
scanf("%d", &n);
for (i = 0; i < n; i++) {
float value;
int count;
scanf("%f %d", &value, &count);
sum += value * count;
}
printf("%f", sum);
return 0;
}
试卷九:
#include <stdio.h>
#include <string.h>
int main() {
char s[100];
scanf("%s", s);
int i, j;
for (i = 0, j = strlen(s) - 1; i < j; i++, j--) {
char temp = s[i];
s[i] = s[j];
s[j] = temp;
}
printf("%s", s);
return 0;
}
#include <stdio.h>
int prime(int n) {
int i;
for (i = 2; i < n; i++) {
if (n % i == 0) {
return 0;
}
}
return 1;
}
int main() {
int n;
scanf("%d", &n);
if (prime(n)) {
printf("是素数");
} else {
printf("不是素数");
}
return 0;
}
#include <stdio.h>
int gcd(int a, int b) {
int i;
for (i = a; i > 0; i--) {
if (a % i == 0 && b % i == 0) {
return i;
}
}
}
int main() {
int a, b;
scanf("%d %d", &a, &b);
printf("%d", gcd(a, b));
return 0;
}
试卷十:
#include <stdio.h>
int main(){
char s[100], c;
scanf("%s %c", s, &c);
int i, count = 0;
for (i = 0; s[i] != '\0'; i++) {
if (s[i] == c) {
count++;
}
}
printf("%d", count);
return 0;
}
#include <stdio.h>
struct Circle {
float radius;
};
int main() {
struct Circle *c;
scanf("%f", &c->radius);
printf("%f", c->radius);
return 0;
}
#include <stdio.h>
int reverse(int n) {
int sum = 0;
while (n != 0) {
sum = sum * 10 + n % 10;
n /= 10;
}
return sum;
}
int main() {
int n;
scanf("%d", &n);
printf("%d", reverse(n));
return 0;
}
Copyright © 2003-2013 www.wpsshop.cn 版权所有,并保留所有权利。