2024-10-14 12:11:16 +05:30
# include <jni.h>
# include <stdio.h>
# include "A3.h"
2024-11-06 02:49:59 +05:30
// NOTE: No need to memorize this file
// The contents of this file can be referenced from A3.h which is the generated header file
// Refer explanation for more info: https://git.kska.io/sppu-te-comp-content/SystemsProgrammingAndOperatingSystem/src/branch/main/Codes/Group%20A/Assignment-A3/EXPLANATION.md
JNIEXPORT jint JNICALL Java_A3_add ( JNIEnv * env , jobject obj , jint a , jint b ) { // Function for addition
2024-10-14 12:11:16 +05:30
jint result = a + b ;
printf ( " \n %d + %d = %d \n " , a , b , result ) ;
return result ; // Return the result
}
2024-11-06 02:49:59 +05:30
JNIEXPORT jint JNICALL Java_A3_sub ( JNIEnv * env , jobject obj , jint a , jint b ) { // Function for subtraction
2024-10-14 12:11:16 +05:30
jint result = a - b ;
printf ( " \n %d - %d = %d \n " , a , b , result ) ;
return result ; // Return the result
}
2024-11-06 02:49:59 +05:30
JNIEXPORT jint JNICALL Java_A3_mul ( JNIEnv * env , jobject obj , jint a , jint b ) { // Function for multiplication
2024-10-14 12:11:16 +05:30
jint result = a * b ;
printf ( " \n %d * %d = %d \n " , a , b , result ) ;
return result ; // Return the result
}
2024-11-06 02:49:59 +05:30
JNIEXPORT jint JNICALL Java_A3_div ( JNIEnv * env , jobject obj , jint a , jint b ) { // Function for division
2024-10-14 12:11:16 +05:30
if ( b = = 0 ) {
printf ( " Error: Division by zero. \n " ) ;
return 0 ; // Return 0 or handle error appropriately
}
jint result = a / b ;
printf ( " \n %d / %d = %d \n " , a , b , result ) ;
return result ; // Return the result
}