function-c programming

 ariel milla · February 2, 2015 write the function c for swapping two column of a matrix

Replies

 ariel milla · February 4, 2015 I agree with you c studentI think that this forum is made for those who want to understand and help others to understand so....any way  i just wanna say i found the solution so for those who cares this is my mistake i shouldn't put  [j] in call of the function and i forgot to add * in declaration of function==>int*M8][4]so from the call the code must be like that:permutation(&M,cn1,cn2,nbl);for(i=0;i<=nbl;i++)for(j=0;j<=4;j++){printf("%3d",M[j]);if(j==4){printf(""\n");}}return 0; Lazar Bulic · February 3, 2015 I shouldn't just copy paste the code but here it is. The solution isn't the most efficient one as  it going through whole matrix just to swap 2 columns but who cares http://pastebin.com/Cz0UpwSj ariel milla · February 3, 2015 ok  I tried this code but it not workI did not understand how I made a call of a function  with several parameters#include #include void permutation(int M[8][4],int nc1,int nc2,int nbl){int i,p;for(i=0;i<=nbl;i++){    p=M[nc1];    M[nc1]=M[nc2];    M[nc2]=p;}}int main(){    int cn1,cn2,nbl,i,j,M[8][4];    printf("give number of lines of the matrix:\n");    printf("nbl=");    scanf("%d",&nbl);    printf("enter elements of matrix:\n");    for(i=0;i<=nbl;i++)for(j=0;j<=4;j++)    {        printf("M[%d][%d]=",i,j);        scanf("%d",&M[j]);    }     printf("======Matrix====== \n\n");    for(i=0;i<=nbl;i++)        for(j=0;j<=4;j++)        {            printf("%4d",M[j]);            if(j==4)            {                printf("\n\n");            }        }        printf("column swapping1=");  scanf("%d",&cn1);        printf("column swapping2=");        scanf("%d",&cn2);        for(i=0;i<=nbl;i++)        for(j=0;j<=4;j++)        permutation(M[j],cn1,cn2,nbl);    return 0;} J show · February 3, 2015 I havent been on the forum that long but for the future whats the easiest way of uploaded code on here? just copying and pasting code in the reply box or screenshot or? ariel milla · February 2, 2015 yes but i don't know how i can make a call of this function
• 1

C

129,670 followers