Cara membuat code program kelipatan 3,5 dan anatara 3 dan lime
Soal Cerita:
Tuliskan algoritma yang mencetak angka 1 hingga 100. Tetapi, khusus setiap angka kelipatan tiga, tulislah "THREE", bukan angka.
Dan jika setiap angka kelipatan lima, tulislah "FIVE", bukan angka. Dan jika setiap angka kelipatan tiga dan lima, tulislah "BINGO", bukan angkanya.
Jawaban:
int a;
string tampil = "";
for (a = 1; a <= 100; a++)
{
int tiga = a % 3;
int lima = a % 5;
if (a % 3 == 0 & a % 5 == 0)
{
tampil += "3 dan 5 \r\n";
Console.WriteLine(tampil);
}
else if (tiga == 0)
{
Console.WriteLine("THREE");
}
else if (lima == 0)
{
Console.WriteLine("FIVE");
}
//Console.WriteLine(a);
}
int a;
string tampil = "";
for (a = 1; a <= 100; a++)
{
int tiga = a % 3;
int lima = a % 5;
if (a % 3 == 0 & a % 5 == 0)
{
tampil += "3 dan 5 \r\n";
Console.WriteLine(tampil);
}
else if (tiga == 0)
{
Console.WriteLine("THREE");
}
else if (lima == 0)
{
Console.WriteLine("FIVE");
}
//Console.WriteLine(a);
}
1 Komentar
Harrah's Casino Tulsa Near Tulsa
BalasHapusHarrah's Casino 스피드 바카라 Tulsa is bet365 우회 주소 the ultimate 포커 페이스 뜻 destination for gaming 1xbetkorea and entertainment, 셉인소 featuring more than 2600 electronic games, a popular music venue,