Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using System;
- using System.Collections.Generic;
- using System.Linq;
- using System.Text;
- namespace ConsoleApplication1
- {
- class Program
- {
- static void Main(string[] args)
- {
- Console.Write("Enter i: ");
- int i = int.Parse(Console.ReadLine());
- Console.Write("Enter j: ");
- int j = int.Parse(Console.ReadLine());
- int cycle = 0;
- int temp;
- for (int n = j; n >= i; n = n - 1)
- {
- temp = cycles(n);
- if (temp > cycle)
- {
- cycle = temp;
- }
- }
- Console.Write("i = {0}, j = {1}, cycle = {2}", i, j, cycle);
- Console.ReadKey();
- }
- static int cycles(int n)
- {
- int temp = 1;
- while (n != 1)
- {
- if (n % 2 == 0)
- {
- n = n / 2;
- }
- else
- {
- n = n * 3 + 1;
- }
- temp++;
- }
- return temp;
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement