RosettaCodeData/Task/A+B/Zig/a+b.zig

19 lines
582 B
Zig
Raw Permalink Normal View History

2024-07-13 15:19:22 -07:00
const std = @import("std");
pub fn main() !void {
var buf: [1024]u8 = undefined;
const reader = std.io.getStdIn().reader();
2025-02-27 18:35:13 -05:00
const stdout = std.io.getStdOut().writer();
try stdout.writeAll("Enter two integers separated by a space: ");
2024-07-13 15:19:22 -07:00
const input = try reader.readUntilDelimiter(&buf, '\n');
2025-02-27 18:35:13 -05:00
const text = std.mem.trimRight(u8, input, "\r\n");
var it = std.mem.tokenizeScalar(u8, text, ' ');
2024-07-13 15:19:22 -07:00
2025-02-27 18:35:13 -05:00
const a = try std.fmt.parseInt(i64, it.next().?, 10);
const b = try std.fmt.parseInt(i64, it.next().?, 10);
2024-07-13 15:19:22 -07:00
try stdout.print("{d}\n", .{a + b});
}