•

Check out our Community Blogs

Register and join over 40,000 other developers!

### Recent Blog Entries

• phi

I love this community !

• JackJames

hi i am jack i am seo expert jack james would love you to read new post

# 2x2 and 3x3 matrix calculating | TWO languages

matrix

### #1 TthomN

TthomN

CC Lurker

• Just Joined
• 3 posts

Posted 12 March 2011 - 10:26 AM

Hello, community here.

I'm student, 16 years old from Estonia. (:

I've started basic C programming in school, first year and pretty beginning. But somehow I feel programming is the Right speciality for me because I'm the guy that likes to do Everything by myself and to fell happy about it. So, I made one 2x2 and 3x3 matrix calculating program in two languages, Estonian and English. I'm giving away the whole Code, it's pretty basic, so I don't mind.
```//Author: Toomas Naadel 2011/02/20

#include <stdio.h>

float a, b, c, d, e, f, g, h, i, answer3x3, answer2x2;
int keel, choosing1, choosing2;

main()
{
printf("1. Eesti\n");
printf("2. English\n"); //Showing options to choose/Valikuvõimaluste kuvamine
printf("\nChoose the language/Vali keel:"); //Language choosing/Keele valimine
scanf("%d", &keel);

switch(keel)
{
case 1:

printf("\n1. Teist j2rku ruutmaatriksi determinandi arvutamine\n");
printf("2. Kolmandat j2rku ruutmaatriksi determinandi arvutamine\n"); //Valikuvõimaluste kuvamine.
printf("\nVali, mis ruutmaatriksit sa soovid arvutada:"); //Valimine.
scanf("%d", &choosing1);

switch(choosing1)

{
case 1:

printf("\n*Teist j2rku ruutmaatriksi determinandi arvutamine*\n"); //Funktsioon valik
printf("\nI a c I \nI b d I \n"); //2x2 matrix näidis.
printf("\nPalun, sisesta k6ik 4 v22rtust:"); //Väärtuste sisendamine.
scanf("%f %f %f %f", &a, &b, &c, &d); //Taking in the values that were entered.
printf("\n| %.0f %.0f |\n| %.0f %.0f |\n", a, c, b, d); //Teist järku ruutmaatriksi näitamine sisestatud värätustega.

printf("", determinantcalc2x2 (a, b, c, d, answer2x2) ); //Teist järku ruutmaatriksi arvutamise funktsiooni lisamine.

printf("\n");
system("pause");
break;
case 2:

printf("\n*Kolmandat j2rku ruutmaatriksi determinandi arvutamine\n"); //Name of the function.
printf("\nI a d g I \nI b e h I \nI c f i I \n"); //3x3 matrix example.
printf("\nPalun, sisesta k6ik 9 v22rtust:"); //Values input.
scanf("%f %f %f %f %f %f %f %f %f", &a, &b, &c, &d, &e, &f, &g, &h, &i); //Taking in the values that were entered.
printf("\n| %.0f %.0f %.0f |\n| %.0f %.0f %.0f |\n| %.0f %.0f %.0f |\n", a, d, g, b, e, h, c, f, i); //Showing 3x3 matrix with the values that were entered.

printf("", determinantcalc3x3 (a, b, c, d, e, f, g, h, i, answer3x3) ); //3x3 determinant calculating function including.

printf("\n");
system("pause");
break;
}

break;
case 2:

printf("\n1. 2x2 Matrix A determinant calculating\n");
printf("2. 3x3 Matrix A determinant calculating\n"); //Showing options to choose.
printf("\nChoose, what determinant you want to calculate:"); //Case choosing.
scanf("%d", &choosing2);

switch(choosing2)

{
case 1:

printf("\n*The determinant of a 2x2 matrix*\n"); //Name of the function.
printf("\nI a c I \nI b d I \n"); //2x2 matrix example.
printf("\nPlease, input all the 4 values:"); //Values input.
scanf("%f %f %f %f", &a, &b, &c, &d); //Taking in the values that were entered.
printf("\n| %.0f %.0f |\n| %.0f %.0f |\n", a, c, b, d); //Showing 2x2 matrix with the values that were entered.

printf("", determinantcalc2x2 (a, b, c, d, answer2x2) ); //2x2 determinant calculating function including.

printf("\n");
system("pause");
break;
case 2:

printf("\n*The determinant of a 3x3 matrix*\n"); //Name of the function.
printf("\nI a d g I \nI b e h I \nI c f i I \n"); //3x3 matrix example.
printf("\nPlease, input all the 9 values:"); //Values input.
scanf("%f %f %f %f %f %f %f %f %f", &a, &b, &c, &d, &e, &f, &g, &h, &i); //Taking in the values that were entered.
printf("\n| %.0f %.0f %.0f |\n| %.0f %.0f %.0f |\n| %.0f %.0f %.0f |\n", a, d, g, b, e, h, c, f, i); //Showing 3x3 matrix with the values that were entered.

printf("", determinantcalc3x3 (a, b, c, d, e, f, g, h, i, answer3x3) ); //3x3 determinant calculating function including.

printf("\n");
system("pause");
break;
}

break;

printf("\n");
system("pause");
}

}

int determinantcalc3x3() //kolmandat järku determinandi arvutamise funktsioon/2x2 matrix determinant calculating function
{
if(keel == 1) //Juhul kui keelevalikuks on Eesti/if Estonian is chosen language
{
answer3x3 = ((a * e * i)+(d * h * c)+(g * b * f)-(c * e * g)-(f * h * a)-(i * b * d)); //answer3x3'le väärtuse andmine arvutamise teel.
printf("\nKolmandat j2rku determinant A on %.2f", answer3x3);//Vastuse näitamine.
}
else
{
answer3x3 = ((a * e * i)+(d * h * c)+(g * b * f)-(c * e * g)-(f * h * a)-(i * b * d)); //Giving answer3x3 a value by calculating it.
}
}
int determinantcalc2x2() //Teist järku determinandi arvutamise funktsioon/2x2 matrix determinant calculating function
{
if(keel == 1) //Juhul kui keelevalikuks on Eesti/if Estonian is chosen language
{
answer2x2 = ((a * d)-(b * c)); //answer2x2'le väärtuse andmine arvutamise teel.
printf("\nTeist j2rku determinant A on %.2f", answer2x2);//Vastuse näitamine.
}
else
{
answer2x2 = ((a * d)-(b * c)); //Giving answer2x2 a value by calculating it.
}
}
```

I would be happy to hear some feedback about it, What is wrong, what could have done differently and stuff.
And maybe somekinda tricky excerise for me to learn programming.
I'm now heading to tutorials section,

Edited by TthomN, 12 March 2011 - 10:27 AM.
spoiler bbcode isn't in this forum

• 0

### #2 Flying Dutchman

Flying Dutchman

• Expert Member
• 1090 posts
• Location:::1
• Programming Language:C++, Python

Posted 12 March 2011 - 01:12 PM

Heya, I haven't really checked your code but it looks solid at first glance. I'd suggest you try and avoid global variables, you can read a bit about those here and here, and rather pass variables to functions. Also, main function should be of type int and return 0 upon success.

One way you could improve your application is to save translations into a file, them prompt user to choose a language and load those translations from file. That way you would only have to code once and you could easily add more language translations.
• 0

The roots of education are bitter, but the fruit is sweet.

### Also tagged with one or more of these keywords: matrix

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download