Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

16521369_Ahmad Rizki #13

Open
wants to merge 2 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
58 changes: 58 additions & 0 deletions 16521369_Ahmad Rizki/uro.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,58 @@
#include <stdio.h>
#include <stdbool.h>
# include <math.h>

float fPlus(float a, float b) {
return a + b;
}

void pPlus(float *a, float b) {
*a += b;
}

float fMin(float a, float b) {
return a - b;
}

void pMin(float *a, float b) {
*a -= b;
}

float fTimes(float a, float b) {
return a * b;
}

void pTimes(float *a, float b) {
*a *= b;
}

float fDivide(float a, float b) {
return a / b;
}

void pDivide(float *a, float b) {
*a /= b;
}

float fPower(float a, float b) {
return pow(a, b);
}

void pPower(float *a, float b) {
*a = pow(*a, b);
}

int main() {
float a = 0, b = 0, step = 0;
int n = 0, i = 0;
float sum = 0;
printf("Integral calculator with riemann sum with input from user\n");
printf("Input a, b, n, and step: ");
scanf("%f %f %d %f", &a, &b, &n, &step);
for (i = 0; i < n; i++) {
sum += fPlus(a, step * i) * fPlus(a, step * (i + 1));
}
printf("Sum = %f\n", sum * step / 2);
return 0;

}
Binary file added 16521369_Ahmad Rizki/uro.exe
Binary file not shown.
66 changes: 34 additions & 32 deletions Misi 2 Programming - SEKURO 2022.c
Original file line number Diff line number Diff line change
Expand Up @@ -2,67 +2,69 @@
#include <stdbool.h>

float fPlus(float a, float b) {
/* Function tambah */
/* Mengembalikan value a + b */
return a + b;
}

void pPlus(float *a, float b) {
/* Procedure tambah */
/* I.S. a dan b terdefinisi dan tidak sembarang */
/* F.S. a menjadi a + b */
*a += b;
}

float fMin(float a, float b) {
/* Function kurang */
/* Mengembalikan value a + b */
return a - b;
}

void pMin(float *a, float b) {
/* Procedure kurang */
/* I.S. a dan b terdefinisi dan tidak sembarang */
/* F.S. a menjadi a - b */
*a -= b;
}

float fTimes(float a, float b) {
/* Function kali */
/* Mengembalikan value a * b */
return a * b;
}

void pTimes(float *a, float b) {
/* Procedure kali */
/* I.S. a dan b terdefinisi dan tidak sembarang */
/* F.S. a menjadi a * b */
*a *= b;
}

float fDivide(float a, float b) {
/* Function bagi */
/* Mengembalikan value a / b */
return a / b;
}

void pDivide(float *a, float b) {
/* Procedure bagi */
/* I.S. a dan b terdefinisi dan tidak sembarang */
/* F.S. a menjadi a * b */
*a /= b;
}

float fPower(float a, float b) {
/* Function pangkat */
/* Asumsi b adalah int */
/* Mengembalikan value a ^ b */
// power function
float result = 1;
for (int i = 0; i < b; i++) {
result *= a;
}
return result;
}

void pPower(float *a, float b) {
/* Procedure pangkat */
/* Asumsi b adalah int */
/* I.S. a dan b terdefinisi dan tidak sembarang */
/* F.S. a menjadi a ^ b */
// power prosedure
float result = 1;
for (int i = 0; i < b; i++) {
result *= *a;
}
*a = result;
}

int main() {
/* Buatlah kalkulator integral menggunakan konsep Integral Riemann */
/* Notes: Penggunaan operator aritmatika harus menggunakan fungsi dan
prosedur yang telah didefinisikan dan diimplementasi sebelumnya */
/* Input dan output dibebaskan kepada Cakru URO 14 */
/* Batasan: Derajat dari koefisien adalah whole number {0, 1, 2, ...} */
// integral calculator with riemann sum
float a, b, n, h, sum;
printf("Enter a: ");
scanf("%f", &a);
printf("Enter b: ");
scanf("%f", &b);
printf("Enter n: ");
scanf("%f", &n);
h = (b - a) / n;
sum = 0;
for (int i = 1; i <= n; i++) {
sum += fPlus(a, i * h);
}
printf("The result is: %f\n", sum * h);
return 0;
}