•

Check out our Community Blogs

Register and join over 40,000 other developers!

### Recent Status Updates

• phi

I love this community !

• JackJames

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

# Applying ratio and proportion - subtraction, multiplication, division

c

1 reply to this topic

### #1 abbie

abbie

CC Regular

• Member
• 36 posts
• Programming Language:C, Java, C++, C#, PHP, (Visual) Basic, JavaScript, PL/SQL, Visual Basic .NET, Assembly, VBScript
• Learning:C, Java, C++, C#, PHP, (Visual) Basic, JavaScript, PL/SQL, Visual Basic .NET, Assembly, VBScript

Posted 25 November 2012 - 03:18 AM

This is the output from this discussion: http://forum.codecal...ation-division/

Enjoy!

```#include <stdio.h>
#include <stdlib.h>
#include <time.h>

int subtraction (int M, int N, int A[100][50], int B[100][50]) {
int g[100][50], C[100][50], min, m, n;

printf("\nSUBTRACTION\n");

printf("\nIts Combined Value:\n\n");
for(m=0;m<M;m++) {
for(n=0;n<N;n++) {
g[m][n] = A[m][n]-B[m][n];
printf("  %d  ", g[m][n]);
}
printf("\n");
}

printf("\nIn its Adjusted Value:\n\n");

for(m=0;m<M;m++) {
for(n=0;n<N;n++) {
if (min>g[m][n]){  //finding the min
min = g[m][n];
}
C[m][n] = (g[m][n]-min)*(255/(255-min));
printf("  %d  ", C[m][n]);
}
printf("\n");
}

return 0;
}

//Output on multiplication
int multiplication(int M, int N, int A[100][50], int B[100][50]) {
int C[50][50], m, n;

printf("\nMULTIPLICATION\n");

printf("\nIts Combined Value:\n\n");
for(m=0;m<M;m++) {
for(n=0;n<N;n++) {
C[m][n]  = A[m][n]*B[m][n];
printf("  %d  ", C[m][n]);
}
printf("\n");
}

printf("\nIn its Adjusted Value:\n\n");

for(m=0;m<M;m++) {
for(n=0;n<N;n++) {
C[m][n] = C[m][n]/255;
printf("  %d  ", C[m][n]);
}
printf("\n");
}

return 0;

}

//Output on division

int division(int M, int N, int A[100][50], int B[100][50]) {
int C[50][50], m, n;

printf("\nDIVISION\n");

printf("\nIts Combined Value:\n\n");
for(m=0;m<M;m++) {
for(n=0;n<N;n++) {
if(C[m][n]=0) {
C[m][n] = 1;
}
C[m][n]  = A[m][n]/B[m][n];
printf("  %d  ", C[m][n]);
}
printf("\n");
}

printf("\nIn its Adjusted Value:\n\n");

for(m=0;m<M;m++) {
for(n=0;n<N;n++) {
C[m][n] = C[m][n]*255;
printf("  %d  ", C[m][n]);
}
printf("\n");
}

}

int main () {

int M, N, m, n;
int A[100][50], B[100][50];

printf("Enter Dimension of Image\n");
printf("Note: Please do not exceed width to 50.\n\n");

printf("Length: ");
scanf("%d", &M);
if(M<0) {
printf("\n\nERROR!! Please enter valid Length.\n");
printf("Length: ");
scanf("%d", &M);
}

printf("Width: ");
scanf("%d", &N);
if(N>50) {
printf("\n\nERROR!! Width must not exceed to 50.\n");
printf("Width: ");
scanf("%d", &N);
}
else if(N<0) {
printf("\n\nERROR!! Please enter valid Width.\n");
printf("Width: ");
scanf("%d", &N);
}

printf("\n\nImage size: %d by %d\n\n", M,N);

//Values of images A and B

srand ( time(NULL) );
printf("\nValues for A Image:\n\n");

for(m=0;m<M;m++) {
for(n=0;n<N;n++) {
A[m][n] = rand()%256;
printf("  %d  ", A[m][n]);
}
printf("\n");
}

printf("\nValues for B Image:\n\n");

for(m=0;m<M;m++) {
for(n=0;n<N;n++) {
B[m][n] = rand()%256;
printf("  %d  ", B[m][n]);
}
printf("\n");
}

subtraction(M, N, A, <img src='http://img.codecall.net/public/style_emoticons/<#EMO_DIR#>/cool.png' class='bbc_emoticon' alt='B)' />;
multiplication(M, N, A, <img src='http://img.codecall.net/public/style_emoticons/<#EMO_DIR#>/cool.png' class='bbc_emoticon' alt='B)' />;
division(M, N, A, <img src='http://img.codecall.net/public/style_emoticons/<#EMO_DIR#>/cool.png' class='bbc_emoticon' alt='B)' />;

system("pause");

return 0;

}```

Edited by Roger, 26 November 2012 - 11:11 AM.
moved to snippets and added reference.

• 0

### #2 BlackRabbit

BlackRabbit

CodeCall Legend

• Expert Member
• 3871 posts
• Location:Argentina
• Programming Language:C, C++, C#, PHP, JavaScript, Transact-SQL, Bash, Others
• Learning:Java, Others

Posted 17 December 2012 - 05:42 AM

Nice!
• 0

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

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