❶ 高分急求C语言编程题的答案!!!!!!!
第一题:
#include <stdio.h>
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<n;i++)
if(n%i==0)
return 0;
return 1;
}
第二题:
#include <stdio.h>
#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 <stdio.h>
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 <stdio.h>
/*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;
}
}
未完,待续,算了,我直接把剩下的发到你邮箱吧
❷ c语言编程题!字符串复制。输入一个字符串,把它复制到一个字符数组中,并输出。
#include <stdio.h>
int main()
{
char a[100] = "