/* Fiz o codigo no site replit.com, lá aparece as instruções tudo certo, se puder recomendo rodar o codigo lá. Mas no caso aqui, siga as instruções abaixo: QUAL SERÁ O TAMANHO DA MATRIZ (a ou b)?? a)2x2 b)3x3 Insira os valores por linha e com espaço ex: 2x2: 3x3: 1 2 1 2 3 3 4 4 5 6 7 8 9 */ #include <stdio.h> #include <stdlib.h> int main() { char matriz; int a, b, c, d, e, f, g, h, i; printf("QUAL SERÁ O TAMANHO DA MATRIZ ??\n"); printf("a)2x2 b)3x3\n"); scanf("%c", &matriz); if( matriz == 'a' || matriz == 'A'){ printf("INSIRA OS VALORES DA PRIMEIRA LINHA:\n"); scanf("%i" "%i", &a, &b); printf("INSIRA OS VALORES DA SEGUNDA LINHA:\n"); scanf("%i" "%i", &c, &d); printf("MATRIZ: \n"); printf("%i %i\n", a, b); printf("%i %i\n", c, d); int multiplicaap = a * d; int multiplicaas = c * b; float deta = multiplicaap - multiplicaas; printf("DET = %.0f \n", deta); if(deta != 0){ //matriz de cofator int aa = 1 * d; int ab = -1 * b; int ac = -1 * c; int ad = 1 * a; printf("MATRIZ DE COFATOR: \n"); printf("%i %i\n", aa, ac); printf("%i %i\n", ab, ad); //matriz adjunta printf("MATRIZ ADJUNTA: \n"); printf("%i %i\n", aa, ab); printf("%i %i\n", ac, ad); //matriz inversa float ia = (1/deta) * aa; float ib = (1/deta) * ab; float ic = (1/deta) * ac; float id = (1/deta) * ad; printf("MATRIZ INVERSA: \n"); printf("%.2f %.2f\n", ia, ib); printf("%.2f %.2f\n", ic, id); } else { printf("NÂO EXISTE INVERSA POIS DET = 0 \n"); } } else if( matriz == 'b' || matriz == 'B'){ printf("INSIRA OS VALORES DA PRIMEIRA LINHA:\n"); scanf("%i" "%i" "%i", &a, &b, &c); printf("INSIRA OS VALORES DA SEGUNDA LINHA:\n"); scanf("%i" "%i" "%i", &d, &e, &f); printf("INSIRA OS VALORES DA TERCEIRA LINHA:\n"); scanf("%i" "%i" "%i", &g, &h, &i); printf("MATRIZ:\n"); printf("%i %i %i\n", a, b, c); printf("%i %i %i\n", d, e, f); printf("%i %i %i\n", g, h, i); int multiplicabp = (a * e * i) + (b * f * g) + (c * d * h); int multiplicabs = (c * e * g) + (a * f * h) + (b * d * i); float detb = multiplicabp - multiplicabs; printf("DET = %.0f \n", detb); if(detb != 0){ //matriz de cofator int aa = 1 * ((e * i) - (h * f)); int ab = -1 * ((d * i) - (g * f)); int ac = 1 * ((d * h) - (g * e)); int ad = -1 * ((b * i) - (h * c)); int ae = 1 * ((a * i) - (g * c)); int af = -1 * ((a * h) - (g * b)); int ag = 1 * ((b * f) - (e * c)); int ah = -1 * ((a * f) - (d * c)); int ai = 1 * ((a * e) - (d * b)); printf("MATRIZ DE COFATOR: \n"); printf("%i %i %i\n",aa, ab, ac ); printf("%i %i %i\n",ad, ae, af ); printf("%i %i %i\n",ag, ah, ai ); // matriz adjunta printf("MATRIZ ADJUNTA: \n"); printf("%i %i %i\n",aa, ad, ag ); printf("%i %i %i\n",ab, ae, ah ); printf("%i %i %i\n",ac, af, ai ); //matriz inversa float ia = (1/detb) * aa; float ib = (1/detb) * ad; float ic = (1/detb) * ag; float id = (1/detb) * ab; float ie = (1/detb) * ae; float iff = (1/detb) * ah; float ig= (1/detb) * ac; float ih = (1/detb) * af; float ij = (1/detb) * ai; printf("MATRIZ INVERSA: \n"); printf("%.2f %.2f %.2f\n", ia, ib, ic); printf("%.2f %.2f %.2f\n", id, ie, iff); printf("%.2f %.2f %.2f\n", ig, ih, ij); } else { printf("NÂO EXISTE INVERSA POIS DET = 0 \n"); } } else printf("Valor não encontrado!! Digite a ou b\n"); return 0; }
Write, Run & Share C Language code online using OneCompiler's C online compiler for free. It's one of the robust, feature-rich online compilers for C language, running the latest C version which is C18. Getting started with the OneCompiler's C editor is really simple and pretty fast. The editor shows sample boilerplate code when you choose language as 'C' and start coding!
OneCompiler's C online editor supports stdin and users can give inputs to programs using the STDIN textbox under the I/O tab. Following is a sample C program which takes name as input and print your name with hello.
#include <stdio.h>
int main()
{
char name[50];
printf("Enter name:");
scanf("%s", name);
printf("Hello %s \n" , name );
return 0;
}
C language is one of the most popular general-purpose programming language developed by Dennis Ritchie at Bell laboratories for UNIX operating system. The initial release of C Language was in the year 1972. Most of the desktop operating systems are written in C Language.
When ever you want to perform a set of operations based on a condition if-else
is used.
if(conditional-expression) {
// code
} else {
// code
}
You can also use if-else for nested Ifs and if-else-if ladder when multiple conditions are to be performed on a single variable.
Switch is an alternative to if-else-if ladder.
switch(conditional-expression) {
case value1:
// code
break; // optional
case value2:
// code
break; // optional
...
default:
// code to be executed when all the above cases are not matched;
}
For loop is used to iterate a set of statements based on a condition.
for(Initialization; Condition; Increment/decrement){
// code
}
While is also used to iterate a set of statements based on a condition. Usually while is preferred when number of iterations are not known in advance.
while(condition) {
// code
}
Do-while is also used to iterate a set of statements based on a condition. It is mostly used when you need to execute the statements atleast once.
do {
// code
} while (condition);
Array is a collection of similar data which is stored in continuous memory addresses. Array values can be fetched using index. Index starts from 0 to size-1.
data-type array-name[size];
data-type array-name[size][size];
Function is a sub-routine which contains set of statements. Usually functions are written when multiple calls are required to same set of statements which increases re-usuability and modularity.
Two types of functions are present in C
Library functions are the in-built functions which are declared in header files like printf(),scanf(),puts(),gets() etc.,
User defined functions are the ones which are written by the programmer based on the requirement.
return_type function_name(parameters);
function_name (parameters)
return_type function_name(parameters) {
//code
}