求教2个C语言的编程题,高手请指教
c语言吧
全部回复
仅看楼主
level 1
第一题Write a C program to do the followings:•Ask the user to print pattern 1 or 2 using switch•Ask the user to input the size of the pattern•Use for loops to generate the pattern.Pattern 1Pattern 2***** ***** **** **** *** ***** ** * * The program should follow the sample output.Which pattern do you want to print (1,2)?1Size of the pattern:4**********Which pattern do you want to print (1,2)?2Size of the pattern:4**** *** ** *Which pattern do you want to print (1,2)?6Size of the pattern:4Do not have this pattern.第二题Modify the previous program so that the program can print pattern 3 and 4. (You can also add other kinds of patterns here if you can imagine)Pattern 3Pattern 4 * * ** * *** * **** * ***** * The program should follow the sample output.Which pattern do you want to print (1,2,3,4)?3Size of the pattern:4 * ** *******Which pattern do you want to print (1,2,3,4)?4Size of the pattern:4 * * **
2008年02月12日 14点02分 1
level 1
第一题的Pattern 2 是刚好和Pattern1反过来的,刚才没弄好.SORRYPattern 2***** **** *** ** *
2008年02月12日 14点02分 2
level 1
2楼的还是不对...怎么弄呢...应该是右边对齐!!!!!
2008年02月12日 14点02分 3
level 0
#include
void Pattern(int x, int y){ int i, j; for(i = 1;i <= x;++i) { for(j = 1;j <= x;++j) switch(y) { case 1:putchar(j<=i?'*':' ');break; case 2:putchar(j<=x-i+1?'*':' ');break; case 3:putchar(j<=i-1?' ':'*');break; case 4:putchar(j<=x-i?' ':'*');break; } putchar(10); }} int main(void){ int n, size; printf("Which pattern do you want to print (1,2,3,4)?"); scanf("%d", &n); if(!(n==1||n==2||n==3||n==4)) { printf("\nDo not have this pattern.\n"); //getch(); return 0; } printf("Size of the pattern:"); scanf("%d", &size); Pattern(size, n); //getch(); return 0;}
2008年02月12日 15点02分 4
level 0
#include
int main(){int n,i,j,k,h;while(cin>>h>>n,n!=0&&h!=0){if(h==1){for(i=n;i>0;i--){for(j=0;j
0;i--){for(j=0;j
2008年02月13日 02点02分 5
level 0
4楼的垃圾!!!!
2008年02月13日 14点02分 6
1