本人因C语言考试,有一题不会,希望大家能帮帮我,很快就用,望大家速度,待遇优厚,谢了

C语言题(编程)
输出图案(用两种方法做):
1234567
2345671
3456712
4567123
5671234
6712345
7123456

方法1:#include<stdio.h>
main()
{
char s[7][8]={"1234567","2345671","3456712","4567123","5671234","6712345","7123456"};
int i;
for(i=0;i<7;i++)
printf("%s\n",s[i]);
}

方法二:
#include<stdio.h>
main()
{
int num[7]={1,2,3,4,5,6,7};
int i,j;

printf("\n");

for(i=0;i<7;i++)
{ for(j=0;j<7;j++)
printf("%d",num[(i+j)%7]);
printf("\n");
}

}
楼主如果需要,还可以给你做出很多种方式来~~呵呵
温馨提示:答案为网友推荐,仅供参考
第1个回答  2011-06-13
#include <iostream>
using namespace std;
int main(int argc, char *argv[])
{
int a[7]={1,2,3,4,5,6,7} ;
for(int i=0;i<7;i++){
for(int j=i;j<7+i;j++){
int k=j%7;
cout<<a[k] ;
}
cout<<endl ;
}
return 0;
}
一个问题2种方法,有点困难,因为思维定式,我就是这么想的,想不出第二种方法,换输入输出,把数字数组换成字符数组?这些东西,,太扯了
第2个回答  2011-06-13
#include "stdio.h"
void put1()
{
int i,j;
for (i=0;i<7;i++)
{
for(j=i;j<7;j++)
printf("%d",j+1);
for(j=i;j>0;j--)
printf("%d",i-j+1);
printf("\n");
}
}

void put2()
{
int i,j;
int a[7]={1,2,3,4,5,6,7};
for (i=0;i<7;i++)
{
for(j=0;j<7;j++)
printf("%d",a[(i+j)%7]);
printf("\n");
}
}

void main()
{
put1();
put2();
}
相似回答