Quantcast
Channel: C#タグが付けられた新着記事 - Qiita
Viewing all articles
Browse latest Browse all 9509

🔰【C#】演算と変数(解答2-1)

$
0
0

この記事の注意事項

この記事に記載の内容(解答)が模範解答というわけではありません。
あくまで自身の学習の過程での足跡的な内容で記載するものです。
そのため、記述が汚い箇所もあるかと思いますので悪しからず。

開発環境

OS:Windows10 Pro 64bit
IDE:VisualStudio Community 2015


問題

以下のプログラムを実行すると、二つの整数値の足し算の結果が画面に出力される。
このプログラムをもとにして、2つの整数型変数、a,bの和、差、積、商、および剰余(割り算の余り)を求めるプログラムを作りなさい。

Pro2_1/Program.cs
usingSystem;usingSystem.Collections.Generic;usingSystem.Linq;usingSystem.Text;usingSystem.Threading.Tasks;namespaceProblem2_2{classProgram{staticvoidMain(string[]args){Console.WriteLine("{0} + {1} = {2}",5,3,5+3);}}}
コンソール
5 + 3 = 8

解答

Ex2_1/Program.cs
usingSystem;usingSystem.Collections.Generic;usingSystem.Linq;usingSystem.Text;usingSystem.Threading.Tasks;namespaceEx2_1{classProgram{staticvoidMain(string[]args){Console.WriteLine("{0} + {1} = {2}",5,3,5+3);Console.WriteLine("{0} - {1} = {2}",5,2,5-2);Console.WriteLine("{0} * {1} = {2}",5,2,5*2);Console.WriteLine("{0} / {1} = {2}",5,2,5/2);Console.WriteLine("{0} % {1} = {2}",5,2,5%2);}}}
コンソール
5 + 3 = 8
5 - 2 = 3
5 * 2 = 10
5 / 2 = 2
5 % 2 = 1
続行するには何かキーを押してください . . .

参考記事

1週間で身につくC#言語の基本


Viewing all articles
Browse latest Browse all 9509

Trending Articles