Advertisement
lily09290110

動態矩陣

Feb 20th, 2015
191
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 1.04 KB | None | 0 0
  1. #include<stdio.h>
  2. #include<stdlib.h>
  3. struct node
  4. {
  5.     int data;
  6.     struct node *next;
  7. };
  8. struct node *head,*ptr,*ptr1;
  9. struct node *add(int n)
  10. {
  11.     head=(struct node*)malloc(sizeof(struct node));
  12.     head->next=NULL;
  13.     ptr=head;
  14.     for(;n>0;n--)
  15.     {
  16.      ptr1=(struct node*)malloc(sizeof(struct node));
  17.      scanf("%d",&ptr1->data);
  18.      ptr1->next=NULL;
  19.      ptr->next=ptr1;
  20.      ptr=ptr->next;
  21.     }
  22.     return head;
  23. }
  24. struct node *op(struct node* head,int a,int b)
  25. {
  26.     int i,j;
  27.     ptr=head->next;
  28.     for(i=0;i<a*b;i++)
  29.     {
  30.         if((i%b)==0) printf("\n");
  31.         ptr->data*=ptr->data;
  32.         ptr=ptr->next;
  33.     }
  34.     return head;
  35. }
  36. void listprint(struct node* head,int a,int b)
  37. {
  38.     int i,j;
  39.     ptr=head->next;
  40.     for(i=0;i<a*b;i++)
  41.     {
  42.         if((i%b)==0) printf("\n");
  43.         printf("%d ",ptr->data);
  44.         ptr=ptr->next;
  45.     }
  46.     printf("\n");
  47. }
  48. int main()
  49. {
  50.    int a,b,i;
  51.    scanf("%d%d",&a,&b);
  52.    ptr=op(add(a*b),a,b);
  53.    listprint(ptr,a,b);
  54.    system("pause");
  55.    return 0;
  56. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement