高分急求C语言编程题的答案!!!!!!!

2024-11-01 12:59:43
推荐回答(3个)
回答1:

第一题:
#include
int isPrime(int n);
void main(){
int count=0;
int i=0;
for(i=301;i<=400;i++){
if(isPrime(i)){
printf("%d ",i);
count++;
}
}
printf("\n%d\n",count);
}

int isPrime(int n){
int i=0;
if(n==2)
return 1;
for(i=2;i if(n%i==0)
return 0;
return 1;
}

第二题:
#include
#define MAX_SIZE 100
void main(){
int i=0;
char ch[MAX_SIZE]={'\0'};
int english=0;
int number=0;
gets(ch);
while(ch[i]!='\0'){
if((ch[i]>='a'&&ch[i]<='z') || (ch[i]>='A'&&ch[i]<='Z'))
english++;
else if(ch[i]>='0'&&ch[i]<='9')
number++;
i++;
}
printf("%d %d\n",english,number);
}
第三题:
#include
int fib(int,int ,int);
void main(){
int i=0;
float sum=0;
for(i=1;i<=10;i++){
sum += (float)fib(i,2,3)/fib(i,1,2);
}
printf("%f\n",sum);
}

int fib(int n,int first,int second){
int i=0;
if(n==1)
return first;
else if(n==2)
return second;
else
return fib(n-1,first,second)+fib(n-2,first,second);
}

第四题:
#include
/*Sunday Monday Tuesday Wednesday Thursday Friday Saturday*/
void main(){
char ch;
printf("please input the first letter : ");
scanf("%c",&ch);
getchar();
switch(ch){
case 'm' :
case 'M' :
printf("Monday\n");
break;
case 'w' :
case 'W' :
printf("Wednesday\n");
break;
case 'f' :
case 'F' :
printf("Wednesday\n");
break;
case 't' :
case 'T' :
printf("please input the second letter : ");
scanf("%c",&ch);
if(ch=='u'||ch=='U')
printf("Tuesday\n");
else if(ch=='h'||ch=='H')
printf("Thursday\n");
break;
case 's' :
case 'S' :
printf("please input the second letter : ");
scanf("%c",&ch);
if(ch=='u'||ch=='U')
printf("Sunday\n");
else if(ch=='a'||ch=='A')
printf("Saturday\n");
break;
}
}
未完,待续,算了,我直接把剩下的发到你邮箱吧

回答2:

1.#include
void main()
{
int i,j,m,n,k;
for(j=0,i=301;i<=400;i++)
{
m=200;
for(n=2;n<=m;n++)
{
k=i%n;
if(k==0) break;
else continue;
}
if(n>m)
{
j++;
printf("%d ",i);
}
else
continue;
}
printf("\n");
printf("共有素数%d个\n",j);
}
2.#include "stdio.h"
void main ()
{
char c;
int i=0,j=0;
c=getchar();
while (c!='\n')
{
if(c<'0'||c>'9')
i++;
if(c>='0'&&c<='9')
j++;
c=getchar();
}
printf("%d个数字\n",j);
printf("%d个英文字母\n",i);
}
3.#include "stdio.h"
void main ()
{
float s=0;
int i=1,j=2,m,n;
for(n=1;n<=10;n++)
{
s=s+j*1.0/i;
m=j;
j=i+j;
i=m;
}
printf("%f\n",s);
}
4.#include "stdio.h"
void main ()
{
char a,b,c;
printf("Please input the first number\n");
scanf("%1s",&a);
if(a=='M')
printf("Monday\n");
if(a=='W')
printf("Wednesday\n");
if(a=='F')
printf("Friday\n");
if(a=='T')
{
printf("Please intput the second number\n");
scanf("%1s",&b);
if(b=='u')
printf("Tuesday\n");
else if(b=='h')
printf("Thursday\n");
}
if(a=='S')
{
printf("Please intput the second number\n");
scanf("%1s",&c);
if(c=='u')
printf("Sunday\n");
else if(c=='a')
printf("Saturday\n");
}
}
5.#include "stdio.h"
void main ()
{
int a[3][3]={1,2,3,4,5,6,7,8,9},i,j,b[3][3];
printf("原数组:\n");
for (i=0;i<=2;i++)
{
for(j=0;j<=2;j++)
{
printf("%5d",a[i][j]);
b[j][i]=a[i][j];
}
printf("\n");
}
printf("转置后数组:\n");
for(i=0;i<=2;i++)
{
for(j=0;j<=2;j++)
printf("%5d",b[i][j]);
printf("\n");
}
}
6.#include "stdio.h"
void main ()
{
int grade;
printf ("Please input your grade:");
scanf("%d",&grade);
if (grade<60)
printf("不及格\n");
else if (grade>=60&&grade<70)
printf("及格\n");
else if (grade>=70&&grade<80)
printf("中等\n");
else if (grade>=80&&grade<90)
printf("良好\n");
else if (grade>=90&&grade<=100)
printf("优秀\n");
}

校友~

回答3:

第一题:
#include

int
isPrime(int
n);
void
main(){
int
count=0;
int
i=0;
for(i=301;i<=400;i++){
if(isPrime(i)){
printf("%d
",i);
count++;
}
}
printf("\n%d\n",count);
}
int
isPrime(int
n){
int
i=0;
if(n==2)
return
1;
for(i=2;iif(n%i==0)
return
0;
return
1;
}
第二题:
#include

#define
MAX_SIZE
100
void
main(){
int
i=0;
char
ch[MAX_SIZE]={'\0'};
int
english=0;
int
number=0;
gets(ch);
while(ch[i]!='\0'){
if((ch[i]>='a'&&ch[i]<='z')
||
(ch[i]>='A'&&ch[i]<='Z'))
english++;
else
if(ch[i]>='0'&&ch[i]<='9')
number++;
i++;
}
printf("%d
%d\n",english,number);
}
第三题:
#include

int
fib(int,int
,int);
void
main(){
int
i=0;
float
sum=0;
for(i=1;i<=10;i++){
sum
+=
(float)fib(i,2,3)/fib(i,1,2);
}
printf("%f\n",sum);
}
int
fib(int
n,int
first,int
second){
int
i=0;
if(n==1)
return
first;
else
if(n==2)
return
second;
else
return
fib(n-1,first,second)+fib(n-2,first,second);
}
第四题:
#include

/*Sunday
Monday
Tuesday
Wednesday
Thursday
Friday
Saturday*/
void
main(){
char
ch;
printf("please
input
the
first
letter
:
");
scanf("%c",&ch);
getchar();
switch(ch){
case
'm'
:
case
'M'
:
printf("Monday\n");
break;
case
'w'
:
case
'W'
:
printf("Wednesday\n");
break;
case
'f'
:
case
'F'
:
printf("Wednesday\n");
break;
case
't'
:
case
'T'
:
printf("please
input
the
second
letter
:
");
scanf("%c",&ch);
if(ch=='u'||ch=='U')
printf("Tuesday\n");
else
if(ch=='h'||ch=='H')
printf("Thursday\n");
break;
case
's'
:
case
'S'
:
printf("please
input
the
second
letter
:
");
scanf("%c",&ch);
if(ch=='u'||ch=='U')
printf("Sunday\n");
else
if(ch=='a'||ch=='A')
printf("Saturday\n");
break;
}
}
未完,待续,算了,我直接把剩下的发到你邮箱吧