Data update
This commit is contained in:
parent
4d5544505c
commit
4924dd0264
3073 changed files with 55820 additions and 4408 deletions
|
|
@ -1,23 +1,26 @@
|
|||
const std = @import("std");
|
||||
|
||||
pub fn main() !void {
|
||||
var buf: [1024]u8 = undefined;
|
||||
const reader = std.io.getStdIn().reader();
|
||||
const stdout = std.io.getStdOut().writer();
|
||||
try stdout.writeAll("Enter two integers separated by a space: ");
|
||||
const input = try reader.readUntilDelimiter(&buf, '\n');
|
||||
const text = std.mem.trimRight(u8, input, "\r\n");
|
||||
const stdin = std.io.getStdIn().reader();
|
||||
var buff = [_]u8{0} ** 1024;
|
||||
|
||||
var it = std.mem.tokenizeScalar(u8, text, ' ');
|
||||
try stdout.print("Value of a: ", .{});
|
||||
const input_a: ?[]u8 = try stdin.readUntilDelimiterOrEof(buff[0..], '\n');
|
||||
const trimmed_a = std.mem.trimEnd(u8, input_a.?, "\r"); // for Windows
|
||||
const a = try std.fmt.parseInt(i32, trimmed_a, 10);
|
||||
|
||||
const a = try std.fmt.parseInt(i64, it.next().?, 10);
|
||||
const b = try std.fmt.parseInt(i64, it.next().?, 10);
|
||||
try stdout.print("Value of b: ", .{});
|
||||
const input_b: ?[]u8 = try stdin.readUntilDelimiterOrEof(buff[0..], '\n');
|
||||
const trimmed_b = std.mem.trimEnd(u8, input_b.?, "\r"); // for Windows
|
||||
const b = try std.fmt.parseInt(i32, trimmed_b, 10);
|
||||
|
||||
try stdout.print("Values: a {d} b {d}\n", .{a, b});
|
||||
try stdout.print("Sum: a + b = {d}\n", .{a + b});
|
||||
try stdout.print("Difference: a - b = {d}\n", .{a - b});
|
||||
try stdout.print("Product: a * b = {d}\n", .{a * b});
|
||||
try stdout.print("Integer quotient: a / b = {d}\n", .{@divTrunc(a, b)}); //truncates towards 0
|
||||
try stdout.print("Remainder: a % b = {d}\n", .{@rem(a, b)}); // same sign as first operand
|
||||
try stdout.print("Exponentiation: math.pow = {d}\n", .{std.math.pow(i64, a, b)}); //no exponentiation operator
|
||||
try stdout.print("a + b = {d}\n", .{a + b});
|
||||
try stdout.print("a - b = {d}\n", .{a - b});
|
||||
try stdout.print("a * b = {d}\n", .{a * b});
|
||||
try stdout.print("a / b (floor) = {d}\n", .{@divFloor(a, b)});
|
||||
try stdout.print("a / b (trunk) = {d}\n", .{@divTrunc(a, b)});
|
||||
try stdout.print("a % b (mod) = {d}\n", .{@mod(a, b)});
|
||||
try stdout.print("a % b (rem) = {d}\n", .{@rem(a, b)});
|
||||
try stdout.print("a ^ b = {d}\n", .{std.math.pow(i32, a, b)});
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue