NotesWhat is notes.io?

Notes brand slogan

Notes - notes.io

#include <stdio.h>
#include <string.h>
#define size 10
int isNeg = 1;
void pt(int *base,int order)
{
int i, j;
for(i=0;i<order;i++)
{
for(j=0;j<order;j++)
printf("%dt", *(base+(i*size)+j));
printf("n");
}printf("DONEn");
}

int gcd(int m, int n)
{
if(n==0)
return m;
else
return gcd(n,m%n);
}


void changeRow(int *base,int row, int pivotRow, int pivotLoc, int order)
{
/*

row = the row to be reduced
pivotRow = WRT which row
pivotLoc = Start from this location, mostly equal to pivot row
order = nxn
*/

//mat[i][j] = *(*(base+i)+j)
int j;

int num2 = *(base+(row*size)+pivotLoc);
int pivot = *(base+(pivotRow*size)+pivotLoc);
if(num2 == 0) return;
int gc = gcd(num2,pivot);
num2 = num2/gc;
pivot = pivot/gc;
//printf("npivot %d %dn",pivot,num2);
for(j=pivotLoc;j<order;j++)
{
//printf("Chamging %d to %d-%dn",*(base+(row*size)+j), *(base+(row*size)+j) * pivot ,(*(base+(pivotRow*size)+j))* num2);
*(base+(row*size)+j) = *(base+(row*size)+j) * pivot - (*(base+(pivotRow*size)+j))* num2;
}
pt(base,order);
}


void swapRow(int *base, int row1, int order)
{
int j;
for(j=row1;j<order;j++)
if(*(base+(j*size)+row1) != 0)
break;
int row2 = j;
if(row2>=order) return;

for(j=0;j<order;j++)
{
int tmp = *(base+(row1*size)+j);
*(base+(row1*size)+j) = *(base+(row2*size)+j);
*(base+(row2*size)+j) = tmp;
}
isNeg = -isNeg;
printf("swapped R%d to R%dn", row1, row2);
pt(base,order);
}

int main(){
//************************************************************
//Getting inut and checking if square and showing the matrix
char input[256];
fgets(input,256,stdin); //take input row wise as string separated by space
int i,j,k,row,col,negFlag = 1;
row = 0; col = 0;
int mat[size][size], rowsize[size];

do{
int no = 0;
for(i=0;(k=input[i])!=10;i++)
{

if(k == 45) // if - means negative number
negFlag = -1;
else if(k!=32)//Not Space
no = (10*no) + k -'0';
else //if sace then save the number as element of array
{
mat[row][col++] = negFlag * no;
negFlag = 1;
no=0;
}
}
mat[row][col++] = negFlag * no; // last number as there is no space at the end
rowsize[row] = col; //save no of elements for square matrix comparision
row++; col = 0; no=0; // reset the values
fgets(input,256,stdin); // Next row input
}while(input[0]!='$'); //$ is the end signal

for(i=0;i<row;i++)
if(rowsize[i] != row)
{printf("NOT SQUAREn"); return 0;}
printf("SQUARE and The Matrix isn");
int order = row;
pt(&mat[0][0],order);
//*********************************************************

// Determinant
int det = 1;
int bias = 1;
for(i=0;i<order;i++)
{
det = det*mat[i][i];
if(mat[i][i] == 0)
printf("%d is zeron",mat[i][i]),swapRow(&mat[0][0],i,order);
for(j=i+1;j<order;j++)
changeRow(&mat[0][0],j,i,i,order),bias = bias*gcd(mat[i][i],mat[j][i]);
}

printf("%dn", bias);

printf("DET = %dn", isNeg*det/bias);

}
     
 
what is notes.io
 

Notes.io is a web-based application for taking notes. You can take your notes and share with others people. If you like taking long notes, notes.io is designed for you. To date, over 8,000,000,000 notes created and continuing...

With notes.io;

  • * You can take a note from anywhere and any device with internet connection.
  • * You can share the notes in social platforms (YouTube, Facebook, Twitter, instagram etc.).
  • * You can quickly share your contents without website, blog and e-mail.
  • * You don't need to create any Account to share a note. As you wish you can use quick, easy and best shortened notes with sms, websites, e-mail, or messaging services (WhatsApp, iMessage, Telegram, Signal).
  • * Notes.io has fabulous infrastructure design for a short link and allows you to share the note as an easy and understandable link.

Fast: Notes.io is built for speed and performance. You can take a notes quickly and browse your archive.

Easy: Notes.io doesn’t require installation. Just write and share note!

Short: Notes.io’s url just 8 character. You’ll get shorten link of your note when you want to share. (Ex: notes.io/q )

Free: Notes.io works for 12 years and has been free since the day it was started.


You immediately create your first note and start sharing with the ones you wish. If you want to contact us, you can use the following communication channels;


Email: [email protected]

Twitter: http://twitter.com/notesio

Instagram: http://instagram.com/notes.io

Facebook: http://facebook.com/notesio



Regards;
Notes.io Team

     
 
Shortened Note Link
 
 
Looding Image
 
     
 
Long File
 
 

For written notes was greater than 18KB Unable to shorten.

To be smaller than 18KB, please organize your notes, or sign in.