高分求两道大一C语言编程题答案,答对的保证再追加100分

作者&投稿:郭可 (联系方式在网页底部的电邮联系)
高分求两道C语言程序题!!好的话继续追加分数!!~

#include

main()
{
int year, month, day, run, num;
while(scanf("%d%d%d", &year, &month, &day) != EOF)
{
if(year % 4 == 0 && year % 100 != 0 || year % 400 == 0)
run = 1;
else
run = 0;

if(run == 1)
switch(month)
{
case 1 : num = day;break;
case 2 : num = 31 + day;break;
case 3 : num = 60 + day;break;
case 4 : num = 91 + day;break;
case 5 : num = 121 + day;break;
case 6 : num = 152 + day;break;
case 7 : num = 182 + day;break;
case 8 : num = 213 + day;break;
case 9 : num = 244 + day;break;
case 10 : num = 274 + day;break;
case 11 : num = 305 + day;break;
case 12 : num = 335 + day;break;
}
else
switch(month)
{
case 1 : num = day;break;
case 2 : num = 31 + day;break;
case 3 : num = 59 + day;break;
case 4 : num = 90 + day;break;
case 5 : num = 120 + day;break;
case 6 : num = 151 + day;break;
case 7 : num = 181 + day;break;
case 8 : num = 212 + day;break;
case 9 : num = 243 + day;break;
case 10 : num = 273 + day;break;
case 11 : num = 304 + day;break;
case 12 : num = 334 + day;break;
}

printf("%d
", num);

}

return 0;
}
这是年月日的
Sample Input
1983 3 17
1984 3 21
2000 2 29

Sample Output
76
81
60


#include
#include
int main()
{
bool f( int num);
long n, i, j;

while(scanf("%ld", &n) != EOF)
{
if(n == 0)
return 0;

for(i = 2; i < n; i++)
{
if(f(i) == 1 && f(n - i) == 1)
{
printf("%ld = %ld + %ld
", n, i, n - i);
break;
}
}
}

return 0;
}

bool f( int num)
{
if (num==2||num==3||num==5)
return 1;
unsigned long c=7;
if (num%2==0||num%3==0||num%5==0||num==1)
return 0;
int maxc=int(sqrt(num));
while (c<=maxc)
{
if (num%c==0)
return 0;
c+=4;
if (num%c==0)
return 0;
c+=2;
if (num%c==0)
return 0;
c+=4;
if (num%c==0)
return 0;
c+=2;
if (num%c==0)
return 0;
c+=4;
if (num%c==0)
return 0;
c+=6;
if (num%c==0)
return 0;
c+=2;
if (num%c==0)
return 0;
c+=6;
}
return 1;
}


这是整数分解的
Sample Input

8
20
42
0


Sample Output

8 = 3 + 5
20 = 3 + 17
42 = 5 + 37


这2道是ACM上原题,我以前做过的,AC

把错误贴出来我看看(算了,你的错太多了,下面是修该好的程序,不懂发消息问我)

#include
#include //不包含这个头文件,exit()则无定义

void
crfpx(int *num, int n)
{
int val;
int i, j, k;
for (i = 1; i < n; i++) {
val = num[i];
for (j = i-1; j >=0 && num[j] > val; j--)
num[j+1] = num[j];
num[j+1]=val;
}
puts("Sorted: ");
for (i = 0; i < n; i++)
printf("%5d", num[i]);
putchar('
');
}

int
main(void)
{
FILE *fp;
int a[80], b[80], i, j;
if ((fp=fopen("text", "w")) == NULL) { /* 以写方式打开文本文件 */
printf("cannot open file.
");
exit(1);
}
for(i = 0; ; i++) {
fscanf(stdin, "%d,", &a[i]); /* 从标准输入设备(键盘)上读取数据,以","号格开,-1结束 */
fprintf(fp, "%d,", a[i]); /* 以格式输出方式写入文件 */
if (a[i] == -1)
break;
}
fclose(fp); /* 写文件结束关闭文件 */
if ((fp=fopen("text", "r")) == NULL) { /* 以读方式打开文本文件 */
printf("cannot open file.
");
exit(1);
}
for (j = 0; ; j++) {
fscanf(fp, "%d,", &b[j]); /* 以格式输入方式从文件读取数据 */
fprintf(stdout, "%d,", b[j]); /* 将数据显示到标准输出设备上 */
if (b[j] == -1)
break;
}
fclose(fp); /* 读文件结束关闭文件 */
printf("%d
", j);
crfpx(b, j);

return 0;
}

/*
1.
*/

#include <stdio.h>
#include <malloc.h>

char* ReadFile(const char* psz)
{
FILE* fp = fopen(psz, "r");
if( NULL == fp ) return NULL;

fseek(fp, 0, SEEK_END);
int nLen = ftell(fp);
char* pszBuff = (char*)malloc(nLen + 1);
fseek(fp, 0, SEEK_SET);
int nSize = fread(pszBuff, 1, nLen, fp);
pszBuff[nSize] = 0;
fclose(fp);

return pszBuff;
}

void Sort(const char* psz)
{
FILE* fp = fopen("New.txt", "w");
while( *psz )
{
if( ((*psz >= '0') && (*psz <= '9')) ||
((*psz >= 'A') && (*psz <= 'F')) ||
((*psz >= 'a') && (*psz <= 'f')) )
{
printf("%c", *psz);
psz++;
continue;
}

fprintf(fp, "%c", *psz);

psz++;
}
}

int main()
{
char* pszBuff = ReadFile("Old.txt");
if( NULL == pszBuff ) return 0;

Sort(pszBuff);
free(pszBuff);
printf("\n");

}

/*
2.
*/
#include <stdio.h>
#include <malloc.h>

void input(int array[], int n)
{
for(int i = 0; i < n; i++)
{
scanf("%d", &array[i]);
}
}

int find(int array[], int n, int x)
{
int count = 0;
for(int i = 0; i < n; i++)
{
if( x == array[i] )
{
count++;
}
}

return count;
}

main()
{
int arr[5];
printf("waiting for array input:\n");
input(arr, 5);
int x;
printf("please enter the target :\n");
scanf("%d", &x);
int count = find(arr, 5, x);
if( 0 == count )
{
printf("Not find!\n");
return 0;
}
printf("the key %d count:\n", count);
}

1.
#include <stdio.h>
#include <stdlib.h>
void main()
{
FILE *in,*out;
char ch;
char char1[100]={""};

int i =0;
if ((in=fopen("c:\\old.txt","r")) == NULL)
{
printf("this file not exsit\n");
exit(0);
}
if ((out=fopen("c:\\new.txt","w")) == NULL)
{
printf("this file not exsit\n");
exit(0);
}

ch = fgetc(in);
while (ch != EOF)
{
if ( (48<=ch && ch<=57)||(65<=ch&& ch<=70)||(97<=ch&& ch<=102))
{

char1[i] = ch;
i++;
}

else
{
fputc(ch,out);

}

ch = fgetc(in);
}
printf("%s\n",char1);
fclose(in);
fclose(out);
}

2.
#include <stdio.h>
#include <malloc.h>
void Input(int *arr,int n)
{
for (int i=0;i<n;i++)
{
scanf("%d",&arr[i]);
}
}

int find(int *arr,int n,int key)
{
int count =0;
for (int i =0;i<n;i++)
{
if (key = arr[i])
{
count++;
}
}
return count;

}

main()
{
int n;
int key,keycount;
printf("Please input the number of yhe array:\n");
scanf("%d",&n);
int *arr = (int*) malloc(sizeof(int)*n);
Input(arr,n);
printf("Please input the find key:\n");
scanf("%d",&key);
keycount = find(arr,n,key);
if (key == 0)
{
printf("Not find!\n");
}
else
{

printf("the key %d count:\n",keycount);
}
free(arr);
}

相关视频

C语言编写一个程序,急用!!高分悬赏(正确答案追加分数)
plu[i][2] = input;plu[i][3] = result;} printf("===十道题目回答如下===\\n\\n");for(int j = 0; j < 10; j++){ printf("%d + %d = %d\\t", plu[j][0], plu[j][1], plu[j][2]);if(plu[j][2] != plu[j][3])printf("(正确答案为%d)", plu[j][3]...

c语言作业,高分求高手,邮箱:[email protected]
不懂可以Hi我 第一题:(1)k > 0 (2)k \/= 10 (3)continue 第二题:include <stdlib.h> main(){ int i,j,k;char ch;scanf("%c",&ch);k=ch-'A'+1;for (i=1;i<=k;i++){ for (j=40;j>=i;j--)printf("%c",' ');for (j=1;j<=2*i-1;j++) \/\/错误...

大一,差不多学完c语言了,网上哪里有c语言的编程题目???我就是想多...
5、A、B、C三人进入决赛,赛前A说:“B和C得第二,我得第一”;B说:“我进入前两名,丙得第三名”;C说:“A不是第二,B不是第一”。比赛产生了一、二、三名,比赛结果显示:获得第一的选手全说对了,获得第二的选手说对了一句,获得第三的选手全说错了。编程求出A、B、C三名选手...