实验10—指针2

/******密码变换问题******/
#include<stdio.h>
#include<string.h>
#define MAXLINE 100
void encrypt(char *);
int main(void)
{
    char line [MAXLINE];   /*定义字符串line*/

    printf("Input the string:");
    gets(line);     /*字符串输入函数gets(s),有返回值*/
    encrypt(line);  /*调用加密函数*/
    printf("%s%s\n","After being encrypted :",line);
    return 0;
}
void encrypt(char *s)     /*定义加密函数,对字符串进行加密*/
{
    for(; *s!='\0';s++)    /*通过指针s的移动来实现对字符串数组中每个元素的遍历和处理*/
        if(*s=='z')        /*将z变成a*/
            *s='a';
        else
            *s=*s+1;
}

/****n人围成一圈,报数3退出,直到最后一个****/

#include<stdio.h>

int main(void)

{

         int a[30];

         int n,i,j,*p;

          

         printf("Input n:");

         scanf("%d",&n);

 

         for(i=0;i<n;i++)a[i]=i+1;

         p=a-i;j=n;

         while(j!=1)

         {

                   i=1;

                   while(i<=3)

                   {

                            p++;

                            if(p==(a+n))p=a;

                            if(*p=0)continue;

                            else i++;

                   }

                   while(*p==0)

                   {

                            p++;

                            if(p==(a+n))p=a;

                   }

                   if(p!=0){printf("%d",*p);*p=0;j--;}

         }

         printf("\nLaast NO. is:");

         for(i=0;i<n;i++)if(a[i]!=0)printf("%d",a[i]);

         return 0;

        

}

posted @ 2013-11-14 12:08  zhaoyang16  阅读(177)  评论(0编辑  收藏  举报