need a program code?

hi there guys!! i wanted 2 know the program code for the multiplication of 2 matrices of the order i*j
i know its a foolish one but i dunno how to get it right !!!! do reply urgently!!
thanx
cooldudefido

Comments

  • : hi there guys!! i wanted 2 know the program code for the multiplication of 2 matrices of the order i*j
    : i know its a foolish one but i dunno how to get it right !!!! do reply urgently!!
    : thanx
    : cooldudefido
    :
    :
    Listen man, I did this for you in C, but decided that I didn't want you to turn it in as homework. So here it is in BW. Same idea to do it in C. The FOR's should clue you in.
    [code]
    [robert@localhost robert]$ cat matrix.bas
    10 FOR I = 1 TO 6
    20 PRINT
    30 FOR J = 1 TO 6
    40 PRINT I * J; CHR$(9);
    50 NEXT J
    60 NEXT I
    70 PRINT
    80 SYSTEM
    [robert@localhost robert]$ bwbasic matrix.bas

    1 2 3 4 5 6

    2 4 6 8 10 12

    3 6 9 12 15 18

    4 8 12 16 20 24

    5 10 15 20 25 30

    6 12 18 24 30 36

    [/code]
    It's not pretty, but it's BW. The C version was much prettier.

    The idea is for you to see how, and come up with your own C version.
  • : : hi there guys!! i wanted 2 know the program code for the multiplication of 2 matrices of the order i*j
    : : i know its a foolish one but i dunno how to get it right !!!! do reply urgently!!
    : : thanx
    : : cooldudefido
    : :
    : :
    : Listen man, I did this for you in C, but decided that I didn't want you to turn it in as homework. So here it is in BW. Same idea to do it in C. The FOR's should clue you in.
    : [code]
    : [robert@localhost robert]$ cat matrix.bas
    : 10 FOR I = 1 TO 6
    : 20 PRINT
    : 30 FOR J = 1 TO 6
    : 40 PRINT I * J; CHR$(9);
    : 50 NEXT J
    : 60 NEXT I
    : 70 PRINT
    : 80 SYSTEM
    : [robert@localhost robert]$ bwbasic matrix.bas
    :
    : 1 2 3 4 5 6
    :
    : 2 4 6 8 10 12
    :
    : 3 6 9 12 15 18
    :
    : 4 8 12 16 20 24
    :
    : 5 10 15 20 25 30
    :
    : 6 12 18 24 30 36
    :
    : [/code]
    : It's not pretty, but it's BW. The C version was much prettier.
    :
    : The idea is for you to see how, and come up with your own C version.
    :

    hey guy,
    thanx a bunch 4 the reply but i kinda didnt understand the concept still.............. i know addition and stuff ..... i want it 4 my own knowledge purpose ... no submissions, no nothing !!!!!!!!!! wats bw? do explain buddy
    i have one more doubt for you ......... i find it kinda confusing to understand the while and do.... while loops ? i mean how do i know when 2 use them ? i kinda prefer the for loop wherever possible
    i also wanted 2 know where 2 practise my skills .... i mean look once i have finished my c and c++ wat next? i mean .... how long am i gonna just keep writing programs on my borland compiler ..... i mean where do i test my skills n stuff ?
    you seem to be a guy who knows a helluva lot bout programmin hence kindly advice .
    thanx once again
    cooldudefido


  • C code:

    [code]/***********************************/
    #include

    int
    main()
    {
    int i, j;
    for (i = 0; i < 20; i++) {
    for (j = 0; j < 20; i++)
    printf("%d ", (i * j));
    printf("
    ");
    }
    /* the following is for "while" version.
    i = 0;
    while (i < 20) {
    j = 0;
    while (j < 20)
    printf("%d ", (i * j++));
    printf("
    ");
    i++;
    } */
    return 0;
    }
    /*********************************************/[/code]
  • : C code:
    :
    : [code]/***********************************/
    : #include
    :
    : int
    : main()
    : {
    : int i, j;
    : for (i = 0; i < 20; i++) {
    : for (j = 0; j < 20; i++) /* j++ not i++ */
    : printf("%d ", (i * j));
    : printf("
    ");
    : }
    : /* the following is for "while" version.
    : i = 0;
    : while (i < 20) {
    : j = 0;
    : while (j < 20)
    : printf("%d ", (i * j++));
    : printf("
    ");
    : i++;
    : } */
    : return 0;
    : }
    : /*********************************************/[/code]
    There is a bug in your code! When run it fills the console with 0's. i is incremented instead of j. When I changed that it worked.

    My C code:
    [code]
    #include

    #define ILIMIT 12
    #define JLIMIT 12

    int main() {
    int i, j;

    for(j = 1; j <= JLIMIT; j++) {
    printf("
    ");
    for(i = 1; i <= ILIMIT; i++)
    printf("%3d ", i * j);
    }
    printf("
    ");
    return 0;
    }
    [/code]


  • [b][red]This message was edited by BASIC Friend at 2002-8-10 18:11:25[/red][/b][hr]
    : hey guy,
    : thanx a bunch 4 the reply but i kinda didnt understand the concept still.............. i know addition and stuff ..... i want it 4 my own knowledge purpose ... no submissions, no nothing !!!!!!!!!! wats bw? do explain buddy
    : i have one more doubt for you ......... i find it kinda confusing to understand the while and do.... while loops ? i mean how do i know when 2 use them ? i kinda prefer the for loop wherever possible
    : i also wanted 2 know where 2 practise my skills .... i mean look once i have finished my c and c++ wat next? i mean .... how long am i gonna just keep writing programs on my borland compiler ..... i mean where do i test my skills n stuff ?
    : you seem to be a guy who knows a helluva lot bout programmin hence kindly advice .
    : thanx once again
    : cooldudefido
    :
    :
    BW is Bywater BASIC. It is a BASIC interpreter (a rather sucky one) that was written in C. The source code is free. It should compile with DJGPP under dos. My copy I compiled with GCC under linux. I wouldn't suggest using BW for anything but playing around. It isn't even a good BASIC interpreter.

    Let's see. while loops iterate (go over and over) until the condition is false. Like
    [code]
    i = 0;
    while(i < 10) {
    printf("%d
    ", i);
    i++;
    }
    [/code]
    this snippet will print the numbers 0 to 9. i is incremented each time, when i is equal to 10 then the condition is false and the loops ends.
    In this while loop the condition is tested before each iteration.

    In a do...while loop the condition is tested after the iteration.
    [code]
    i = 0;
    do {
    i++;
    printf("%d
    ", i);
    } while(i < 10);
    [/code]
    This snippet will print the numbers 1 thruogh 10.




  • for me, the different between the while and for loops are only for their initial and increament (or decrement) methods.

    i use for-loop, when i want to always initial particular object, and always want some increment or decrement or some required [expression] statement to control the condition-expression in the loop clause.

    for the for-loop, i use it when the loop is control by run time decision. that's mean when i don't know how long the loop will repeat when coding.

    you'll understand which is prefer after some practices.
  • : for me, the different between the while and for loops are only for their initial and increament (or decrement) methods.
    :
    : i use for-loop, when i want to always initial particular object, and always want some increment or decrement or some required [expression] statement to control the condition-expression in the loop clause.
    :
    : for the for-loop, i use it when the loop is control by run time decision. that's mean when i don't know how long the loop will repeat when coding.
    :
    : you'll understand which is prefer after some practices.
    :




    hey guys,
    thanx a bunch and some more for the overwhelming response !!!!!! u guys r simply fantastic !! i hope i am able 2 become even half as good as you !!!! i have a couple of doubts though!!!!! 4 starters y did u guys introduce int main() instead of main()??
    secondly why did you write return 0? i mean i have written so many programs and never have i written return 0 or anything!!!! do lemme know
    also can i write a function within a structure?? stupid question but still do answer for i know i can write a function within a class hence i wanna know whether i can or not write a function within a structure andif not then why?
    i think i have asked you all enough questions for 2day . thanx once again for replying . do stay in touch and keep replying .
    bye
    cooldudefido


  • in older C compiler, the default data type for the function return type is to int type. so for that version, when the int keyword is omitted before the function identifier, it's default to int type. the following are the same:

    [code]myFunc()
    {
    return 0;
    }

    int myFunc()
    {
    return 0;
    }[/code]

    but after the C language is standardized by ANSI, the int clause is required. in order to retain backward-compatibility, the old stype(first function stype of the above) is still allowed. but i recommmend all of us use the new style. since it increase code readability and make the type-checking easier.

    about the return type of the main function, you are allowed to write it's return type you want. but the following is recommeded:

    [code]int main()
    {
    return 0'
    }[/code]

    we return 0 from the program is for telling the operating system that our program is exited successfully. you can actually access this return type by using function named system. the system function prototype is somehtings like

    [code]system(const char *s); /* declared in header file . */[/code]

    this function is used to run particular command (or program) from operating system. we can use it to execute operating system command with this function, like:

    [code]system("dir")[/code]

    this command display the directory contents. since system function's return type is int type. when we have a program like:

    [code]int main() /* saved in file name you want. i use test.c here. */
    {
    return 0;
    }[/code]

    we can access this return value from other program. like:

    [code]int main()
    {
    /* the system function executes program named "test", and return the value from that program. after that printf function print out this value (o). */
    printf("%d
    ", system("test"));
    return 0;
    }[/code]

    have fun in C programming!!!
Sign In or Register to comment.

Howdy, Stranger!

It looks like you're new here. If you want to get involved, click one of these buttons!

Categories