c program finding call function

fiksx

Two integers are stored in the arrays a 1 and a 2, respectively, and the product is calculated by the same procedure as the calculation, but it does not output the correct result. question is : want to produce 312*321 = 1 0 0 1 5 2 but this first program produce ? 0 9 9 11 5 2 to produce right result 1 0 0 1 5 2, call function name func(c,N*2)

#include <stdio.h>
#include <stdlib.h>
#define N 3
int main()
 {

 int a1[N]={1,2,3};
 int a2[N]={2,1,3};
 int b[N][N];
 int c[N*2];
 int i,j;

 for(i=0;i<N;i++){
    for(j=0;j<N;j++)
b[i][j]=a1[j]*a2[i];
 }


 c[0]=b[0][0];
 c[1]=b[0][1]+b[1][0];
 c[2]=b[0][2]+b[1][1]+b[2][0];
 c[3]=b[1][2]+b[2][1];
 c[4]=b[2][2];

 for(i=N*2-1;i>=0;i--)
 {
     printf("%d ",c[i]);
 }
    printf("\n");
    return 0;
}

The result:0 9 9 11 5 2

       |0|1|2| ->A1
  ----------------
A2<-| 0|2|4|6|     
    | 1|1|2|3| 
    | 2|3|6|9|

this array is the same as 321*312 calculate using hand in paper

Problem: Define the function func () to output the correct result 1 0 0 1 5 2, call func (c, N * 2); below i post the code with the call function func() in bold. any idea?? and also what the logic behind func()? trial and error? is there algorithm behind this?

#include <stdio.h>
#include <stdlib.h>
#define N 3
int main()
 {

 int a1[N]={1,2,3};
 int a2[N]={2,1,3};
 int b[N][N];
 int c[N*2];
 int i,j;

 for(i=0;i<N;i++){
    for(j=0;j<N;j++)
b[i][j]=a1[j]*a2[i];
 }


 c[0]=b[0][0];
 c[1]=b[0][1]+b[1][0];
 c[2]=b[0][2]+b[1][1]+b[2][0];
 c[3]=b[1][2]+b[2][1];
 c[4]=b[2][2];

 **func(c,N*2);**

 for(i=N*2-1;i>=0;i--)
 {
     printf("%d ",c[i]);
 }
    printf("\n");
    return 0;
}

**void func(int a[],int digit)
{
   here no idea....
    }**
Tiefan Ju

Try with this;

void func(int a[], int digit)
{
    int i, c = 0;
    for(i = 0; i < digit; i ++)
    {
        a[i] += c;
        c = a[i] / 10;
        a[i] = a[i] % 10;
    }
}

Collected from the Internet

Please contact [email protected] to delete if infringement.

edited at
0

Comments

0 comments
Login to comment

Related

From Dev

Forcing a program to call a function in C with an input string

From Dev

Pattern/function finding program in python

From Dev

How to call a C++ function in a C++ Program

From Dev

What is the c program exit(0) equivalent function call in erlang?

From Dev

Having a c++ program call an html function/event listener

From Dev

Unable to understand behaviour of "system" function call in C program

From Dev

Failed to compile or link yasm program that call c function

From Dev

Finding the cumulative sum with different function call

From Dev

Program seems to be skipping function call

From Dev

Finding dependencies for a compiled C++ program

From Dev

C++ - Function Call To execvp Returns Cannot Access Error In C++ Shell Program

From Dev

Program call delay - C & Linux

From Dev

Segfault in C program, malloc call

From Dev

Is system() call in C program safe?

From Dev

Definition of a function in a C program

From Dev

Compiled C program with call to undefined/undeclared function; no error or warning reported. Why?

From Dev

Undefined reference error when I try to call compiled NASM function from C program

From Dev

Compiled C program with call to undefined/undeclared function; no error or warning reported. Why?

From Dev

Make a function to call while the program is running

From Dev

Call a specific function when the console program terminates

From Dev

Cannot call bool function with array program

From Dev

Program segfaults when I call the atoi() function

From Dev

Cannot call bool function with array program

From Dev

finding median via function in c plus plus

From Dev

Hash table's finding function in c?

From Dev

finding median via function in c plus plus

From Dev

Hash table's finding function in c?

From Dev

C++ function call

From Dev

Finding the PID of a process launched by exec() or system() in C program

Related Related

  1. 1

    Forcing a program to call a function in C with an input string

  2. 2

    Pattern/function finding program in python

  3. 3

    How to call a C++ function in a C++ Program

  4. 4

    What is the c program exit(0) equivalent function call in erlang?

  5. 5

    Having a c++ program call an html function/event listener

  6. 6

    Unable to understand behaviour of "system" function call in C program

  7. 7

    Failed to compile or link yasm program that call c function

  8. 8

    Finding the cumulative sum with different function call

  9. 9

    Program seems to be skipping function call

  10. 10

    Finding dependencies for a compiled C++ program

  11. 11

    C++ - Function Call To execvp Returns Cannot Access Error In C++ Shell Program

  12. 12

    Program call delay - C & Linux

  13. 13

    Segfault in C program, malloc call

  14. 14

    Is system() call in C program safe?

  15. 15

    Definition of a function in a C program

  16. 16

    Compiled C program with call to undefined/undeclared function; no error or warning reported. Why?

  17. 17

    Undefined reference error when I try to call compiled NASM function from C program

  18. 18

    Compiled C program with call to undefined/undeclared function; no error or warning reported. Why?

  19. 19

    Make a function to call while the program is running

  20. 20

    Call a specific function when the console program terminates

  21. 21

    Cannot call bool function with array program

  22. 22

    Program segfaults when I call the atoi() function

  23. 23

    Cannot call bool function with array program

  24. 24

    finding median via function in c plus plus

  25. 25

    Hash table's finding function in c?

  26. 26

    finding median via function in c plus plus

  27. 27

    Hash table's finding function in c?

  28. 28

    C++ function call

  29. 29

    Finding the PID of a process launched by exec() or system() in C program

HotTag

Archive