| 网站首页 | 业界新闻 | 小组 | 威客 | 人才 | 下载频道 | 博客 | 代码贴 | 在线编程 | 编程论坛
欢迎加入我们,一同切磋技术
用户名:   
 
密 码:  
共有 873 人关注过本帖
标题:C语言问题求助
只看楼主 加入收藏
yixiu868
Rank: 2
等 级:论坛游民
帖 子:28
专家分:22
注 册:2010-10-25
收藏
得分:0 
回复 6楼 死蜜蜂
肯定不可以哦,每次都把a[5]提出了,再每个向后移一位
2011-08-22 21:05
wicky
Rank: 1
等 级:新手上路
帖 子:6
专家分:0
注 册:2011-8-22
收藏
得分:0 
很好的一道题目……学习中
2011-08-23 00:55
lihang_19925
Rank: 1
等 级:新手上路
帖 子:2
专家分:0
注 册:2011-8-23
收藏
得分:0 
#include<stdio.h>
int main()
{
    int n;
    int a[10];
    int i,j;
    printf("要输入  个数");
    scanf("%d",&n);
    for(i=0;i<n;i++)
        scanf("%d",&a[i]);
    for(i=0;i<n;i++)
    {
        for(j=0;j<n;j++)
        {
            if(n-i+j>=n)
            printf("%d ",a[-i+j]);
        else printf("%d ",a[n-i+j]);
        }
    printf("\n");
    }
            return 0;
}
经过运行,没有错误
2011-08-23 15:37
zusjun
Rank: 1
等 级:新手上路
帖 子:8
专家分:5
注 册:2011-8-14
收藏
得分:0 
#include<stdio.h>
#include<malloc.h>
#define LEN sizeof(struct node)
struct node
{
     int num;
     struct node *next;
};
int n=0;
void main()
{
    struct node *creat (void);
    struct node *chang_list(struct node *head);
    void print(struct node *head);
    struct node *head,*head1,*head2,*head3,*head4,*head5;
    //int num;
    printf("input the num \n");
    head=creat();
    print(head);//1
    head1=chang_list(head);
    print(head1);//2
    head2=chang_list(head1);
    print(head2);//3
    head3=chang_list(head2);
    print(head3);//4
    head4=chang_list(head3);
    print(head4);//5
    head5=chang_list(head4);
    print(head5);//6
}
struct node *creat(void)
{
    //ruct node *p1,*p2,*head;
    struct node *p1;
    struct node *p2;
    struct node *head;
   
    p1=p2=(struct node*)malloc(LEN);
        
    scanf("%d",&p1->num);
    head=NULL;
    while(p1->num!=0)
    {
        n=n+1;
        if(n==1)head=p1;
        else
        {
            p2->next=p1;
            p2=p1;
            p1=(struct node*)malloc(LEN);
            scanf("%d",&p1->num);
        }
    }
        p2->next=NULL;
        return(head);
}
void print(struct node *p)
{
    struct node *p1;
    p1=p;
    if(p1!=NULL)
        do
        {
            
            printf("%d ",p1->num);
            p1=p1->next;
        }while(p1!=NULL);
        printf("\n");
        
}
struct node *chang_list(struct node *head)
{
    struct node *p1,*p2;
    p1=head;
    while(p1->next->next!=NULL)
      {
        p1=p1->next;

      }   
     p2=p1->next;
     p1->next=NULL;
     p2->next=head;
     head=p2;

    return(head);
}

这是我用指针写的,结果正确,不过struct node *chang_list(struct node *head) 是根据你的要求写的,看下吧,运行结果完全是没有问题的。
            









2011-08-23 23:13
edwardflee
Rank: 4
等 级:业余侠客
帖 子:145
专家分:234
注 册:2011-7-27
收藏
得分:0 
楼上大侠们的算法都好巧哦,新手只会用笨方法
程序代码:
/*
时间:2011年8月24日9:28:02
功能:输入6个数比如:1 4 7 3 5 2.可以得到
                                              1 4 7 3 5 2
                                              2 1 4 7 3 5
                                              5 2 1 4 7 3
                                              3 5 2 1 4 7
                                              7 3 5 2 1 4
                                              4 7 3 5 2 1
目的:论坛回复,练习数组的使用

*/
# include <stdio.h>

int main(void)
{
    int a[6];
    int i,j;

    printf("请输入6个数字\n");        //输入6个数字
   
    for (i=0; i<6; ++i)
        scanf("%d",&a[i]);

    printf("\n显示输出结果:\n");

   
    for (j=0; j<6; ++j)            //输出排列好的数组
    {
        for (i=6-j; i<6; ++i)
            printf("%3d",a[i]);
       
        for (i=0; i<6-j; ++i)
            printf("%3d",a[i]);

        printf("\n");
    }

    return 0;
}
/*
在VC++6.0中的输出结果为:
————————————
请输入6个数字
1
4
7
3
5
2

显示输出结果:
  1  4  7  3  5  2
  2  1  4  7  3  5
  5  2  1  4  7  3
  3  5  2  1  4  7
  7  3  5  2  1  4
  4  7  3  5  2  1
Press any key to continue

————————————
*/


学C的秘诀=每天都来泡论坛
2011-08-24 09:53
快速回复:C语言问题求助
数据加载中...
 
   



关于我们 | 广告合作 | 编程中国 | 清除Cookies | TOP | 手机版

编程中国 版权所有,并保留所有权利。
Powered by Discuz, Processed in 0.017399 second(s), 7 queries.
Copyright©2004-2024, BCCN.NET, All Rights Reserved