Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include<stdio.h>
- #include<stdlib.h>
- void disp(int *x,int y);
- void read(int *x,int y)
- {
- printf("Enter %d elements: ",y*y);
- int i,j;
- for(i=0;i<y;i++)
- {
- for(j=0;j<y;j++)
- {
- scanf("%d",x+y*i+j);
- }
- }
- }
- void sort(int *x,int y)
- {
- int n=y*y;
- int i,j;
- int min;
- int temp;
- for(i=0;i<n;i++)
- {
- min=i;
- for(j=i;j<n;j++)
- {
- if(x[j]<x[min]) min = j;
- }
- temp=x[i];
- x[i]=x[min];
- x[min]=temp;
- }
- }
- void asq(int *x,int y)
- {
- int *sq;
- sq=(int *)malloc(y*y*sizeof(int));
- int i,j,k;
- for(i=0;i<y*y;i++)
- *(sq+i)=0;
- for(i=0;i<y;i++)
- for(j=0;j<y;j++)
- for(k=0;k<y;k++)
- *(sq+i*y+j)+=*(x+i*y+k)**(x+k*y+j);
- disp(sq,y);
- }
- void disp(int *x,int y)
- {
- int i,j;
- for(i=0;i<y;i++)
- {
- for(j=0;j<y;j++)
- {
- printf(" %d",*(x+i*y+j));
- }
- printf("\n");
- }
- }
- int main()
- {
- int n;
- int *in,*square,*sorted,i,j;
- printf("Enter n: ");
- scanf("%d",&n);
- in= (int *)malloc(n*n*sizeof(int));
- square= (int *)malloc(n*n*sizeof(int));
- for(i=0;i<n;i++)
- for(j=0;j<n;j++)
- *(in + n*i + j)=0;
- while(1) {
- int choice;
- printf("\nEnter choice: \n1. Enter elements of array\n2. sort the array\n3. square the array\n4. display the array\n5. Exit\n");
- scanf("%d", &choice);
- if(choice == 1)
- read(in,n);
- else if(choice == 2)
- sort(in,n);
- else if(choice == 3)
- asq(in,n);
- else if(choice == 4)
- disp(in,n);
- else if(choice == 5)
- break;
- else
- printf("Invalid input!\n");
- }
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement