Exemplo n.º 1
0
Arquivo: 83.c Projeto: 13436120/Cgames
void main()
{
    int i,j,n;
    long max;
    clrscr();
    puts("============================================================");
    puts("||       This program will verify the Goldbach Guess.     ||");
    puts("|| That is any positive even number can be broken up into ||");
    puts("||               the sum of two prime numbers.            ||");
    puts("||       e.g., 4=2+2, 6=3+3, 8=3+5, 10=3+7, 12=5+7,...    ||");
    puts("============================================================");
    printf("\n >> Please input the scale n you want to verify : ");
    scanf("%ld",&max);
    printf("\n >> Now the program starts to verify the even number\n");
    printf(" >> less than %ld equals to sum of two prime numbers.\n\n",max);
    for(i=4,j=0;i<=max;i+=2)
    {
        for(n=2;n<i;n++)         /*将偶数i分解为两个整数*/
            if(fflag(n))         /*分别判断两个整数是否均为素数*/
                if(fflag(i-n))
                {
		    printf("%4d=%2d+%2d ",i,n,i-n);        /*若均是素数则输出*/
		    j++;
		    if(j==5)
		    {
			printf("\n");
			j=0;
		    }
                    break;
                }
            if(n==i)  printf("error %d\n",i);
    }
    puts("\n >> Press any key to quit...");
    getch();
}
Exemplo n.º 2
0
STATIC void
expandmeta(shinstance *psh, struct strlist *str, int flag)
{
	char *p;
	struct strlist **savelastp;
	struct strlist *sp;
	char c;
	/* TODO - EXP_REDIR */

	while (str) {
		if (fflag(psh))
			goto nometa;
		p = str->text;
		for (;;) {			/* fast check for meta chars */
			if ((c = *p++) == '\0')
				goto nometa;
			if (c == '*' || c == '?' || c == '[' || c == '!')
				break;
		}
		savelastp = psh->exparg.lastp;
		INTOFF;
		if (psh->expdir == NULL) {
			size_t i = strlen(str->text);
			psh->expdir = ckmalloc(psh, i < 2048 ? 2048 : i); /* XXX */
		}

		expmeta(psh, psh->expdir, str->text);
		ckfree(psh, psh->expdir);
		psh->expdir = NULL;
		INTON;
		if (psh->exparg.lastp == savelastp) {
			/*
			 * no matches
			 */
nometa:
			*psh->exparg.lastp = str;
			rmescapes(psh, str->text);
			psh->exparg.lastp = &str->next;
		} else {
			*psh->exparg.lastp = NULL;
			*savelastp = sp = expsort(*savelastp);
			while (sp->next != NULL)
				sp = sp->next;
			psh->exparg.lastp = &sp->next;
		}
		str = str->next;
	}
}