0% found this document useful (0 votes)
23 views6 pages

Nomor 1: Using Using Using Using Using Namespace Class Static Void String

This document contains 6 code examples in C# that demonstrate different uses of for loops: 1) printing 25 asterisks, 2) printing numbers 1 to 25, 3) printing odd numbers from 1 to a user-input N, 4) determining if a number is prime, 5) calculating the factorial of a user-input number, and 6) calculating a number to a power. Each example contains a for loop, outputs a header with the author's name, and demonstrates a simple numerical or logical operation.

Uploaded by

Ini Rizal
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
23 views6 pages

Nomor 1: Using Using Using Using Using Namespace Class Static Void String

This document contains 6 code examples in C# that demonstrate different uses of for loops: 1) printing 25 asterisks, 2) printing numbers 1 to 25, 3) printing odd numbers from 1 to a user-input N, 4) determining if a number is prime, 5) calculating the factorial of a user-input number, and 6) calculating a number to a power. Each example contains a for loop, outputs a header with the author's name, and demonstrates a simple numerical or logical operation.

Uploaded by

Ini Rizal
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 6

Nomor 1

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace Menampilkan_25_Bintang
{
class Program
{
static void Main(string[] args)
{

Console.WriteLine("NAMA: Redempia Kornea Gomes");


Console.WriteLine();

for (int i = 1; i <= 25; i++)


{
Console.Write("*");
}
Console.WriteLine();
}
}
}

Nomor 2

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace Menampilkan_Angka_1_Sampai_25
{
class Program
{
static void Main(string[] args)
{
Console.WriteLine("NAMA: Redempia Kornea Gomes");
Console.WriteLine();

for (int i = 1; i <= 25; i++)


{
Console.Write("{0} ", i);
}
Console.WriteLine();
}
}
}
Nomor 3

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace Menampilkan_Bilangan_Ganjil_1_Sampai_N
{
class Program
{
static void Main(string[] args)
{
int n;

Console.WriteLine("NAMA: Redempia Kornea Gomes");


Console.WriteLine();

Console.WriteLine("Masukan nilai N: ");


n = int.Parse(Console.ReadLine());

for (int i = 1; i <= n; i+=2)


{
Console.Write("{0} ", i);
}
Console.WriteLine();
}
}
}
Nomor 4

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace Algo5___Menentukan_Bilangan_Prima
{
class Program
{
static void Main(string[] args)
{
int bilangan, prima, sisa, hasil;
string keterangan;

Console.WriteLine("NAMA: Redempia Kornea Gomes");


Console.WriteLine();

Console.WriteLine("Silahkan masukan sebuah bilangan: ");


Console.WriteLine();
bilangan = int.Parse(Console.ReadLine());
Console.WriteLine();

hasil = 0;

for (prima = 1; prima <= bilangan; prima++)


{
sisa = bilangan % prima;

if (sisa == 0)
hasil = hasil + 1;

else
hasil = hasil + 0;
}

if (hasil > 2 || bilangan < 2)


keterangan = "BUKAN";

else
keterangan = "TERMASUK";

Console.WriteLine("Jadi Bilangan {0} {1} Bilangan Prima", bilangan,


keterangan);
Console.WriteLine();
}
}
}
Nomor 5

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace Algo5___Menentukan_Faktorial_Sebuah_Bil
{
class Program
{
static void Main(string[] args)
{
int bilangan, rumus, faktorial;

Console.WriteLine("NAMA: Redempia Kornea Gomes");


Console.WriteLine();

Console.WriteLine("Silahkan masukan sebuah bilangan: ");


Console.WriteLine();
bilangan = int.Parse(Console.ReadLine());
Console.WriteLine();

rumus = 1;

for (faktorial = bilangan; faktorial >= 1; faktorial--)


{
rumus = rumus * faktorial;
}

Console.WriteLine("Jadi, nilai dari {0}! adalah = {1} ",bilangan, rumus);


Console.WriteLine();
}
}
}
Nomor 6

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace ConsoleApplication14
{
class Program
{
static void Main(string[] args)
{

int asli;
int pangkat;
int hasil;

Console.WriteLine("Silahkan masukan sebuah nilai:");


asli = int.Parse(Console.ReadLine());
Console.WriteLine();

Console.WriteLine("Silahkan masukan nilai pangkat:");


pangkat = int.Parse(Console.ReadLine());
Console.WriteLine();

hasil = 1;

for (int i = 0; i < pangkat; i++)


{
hasil = hasil * asli;
}

Console.WriteLine("Hasil pangkat adalah = {0}", hasil);


Console.WriteLine();
}
}
}
Copyright (c) BRAND Technologies

You might also like