忍辱负重难逃交题不慎
关于GDPU的c语言线上实验系统,没交上就是无了。系统吞答案时,千万不要相信,所谓系统会有记录的鬼话。
#include
double fac(int n)
{
double f;
if(n == 1)
f=1;
else
f= n * fac(n-1);
return f;
}
main()
{
double s=0;
int i,n;
scanf("%d",&n);
for(i=1;i<=n;i++)
s=s + fac(i);
printf("s=%.2lf",s);
}
#include
int main()
{
int i, j, upp, low, dig, spa, oth;
char text[5][100];//【1】
upp = low = dig = spa = oth = 0;
for(i = 0; i<3; i++)
{
printf("please input line %d:", i + 1);
gets(text[i]);//【2】
for(j = 0; j < strlen(text[i]); j++)//【3】
{
if(text[i][j] >= 'A'&& text[i][j] <= 'Z')
upp++;
else if(text[i][j] >= 'a' && text[i][j] <= 'z')
low++;
else if(text[i][j] >= '0' && text[i][j] <= '9')
dig++;
else if(text[i][j] == ' ')
spa++;
else
oth++;
}
}
printf("\nupper: %d\nlower: %d\ndigit: %d\nblank: %d\nother: %d\n", upp, low, dig, spa, oth);
return 0;
}
#include
#include
struct student
{
char name[20];
int score;
};
void search(struct student *p, int n, char *c)
{
int i, index = -1;;
for(i = 0; i<n; i++, p++)
if(strcmp((p+i)->name,c) == 0)
{
index = i;
printf("score:%d",(p+i)->score);
break;
}
if(index == -1)
printf("No found");
}
void main()
{
char c[20];
int i;
struct student stu[5] = { { "mary", 90 }, { "jone", 60 }, { "henry", 75 }, { "sofia", 55 }, { "sunny", 88 } };
gets(c);
search(stu,5,c);
}
#include
int even(int x)
{
if(x % 2 == 0)
return 0;
else
return 1;
}
int main()
{
int n, m, i;
scanf("%d %d", &n, &m);
long long ans = 0;
for(i = n; i <= m; i++)
{
if(!even(i))
ans += i;
}
printf("s=%lld", ans);
return 0;
}
#include
//是因果数返回1
int f(int x)
{
int t = x;
int he = 0;
while(t)
{
he += t % 10;
t /= 10;
}
if(x % he == 0)
return 1;
return 0;
}
int main()
{
int n, m, i;
scanf("%d %d", &n, &m);
long long sum = 0;
int cnt = 0;
for(i = n; i <= m; i++)
{
if(f(i))
{
cnt++;
sum += i;
}
}
printf("count=%d,sum=%lld", cnt, sum);
return 0;
}
#include
int main()
{
int n, m, i;
scanf("%d", &n);
int a[100];
int wei = 1;
while(n)
{
int t = n % 10;
if((wei % 2) == (t % 2))
a[wei] = 1;
else
a[wei] = 0;
n /= 10;
wei++;
}
wei--;
int ans = 0;
for(i = wei; i > 0; i--)
{
ans = ans * 2 + a[i];
}
printf("%d", ans);
return 0;
}
#include
int main()
{
int n, m, i;
scanf("%d", &n);
int ans = 0;
for(i = 1; i <= n; i++)
ans = ans + i*i;
printf("%d", ans);
return 0;
}
仅供参考