Write a program in C# Sharp to convert a decimal number into octal without using an array

  • برمجة سي شارب
  • برمجة

Write a program in C# Sharp to convert a decimal number into octal without using an array

Sample Output:

Convert decimal number to octal without using array:                                                        
------------------------------------------------------                                                      
Enter a number to convert : 6                                                                               
The Octal of 6 is 6.

الأجوبة

using System;  
public class Exercise50
{  
    public static void Main()
     {
     int n, i, j, ocno=0,dn;
	 
	Console.Write("\n\n");
    Console.Write("Convert decimal number to octal without using array:\n");
    Console.Write("------------------------------------------------------");
    Console.Write("\n\n");	 


     Console.Write("Enter a number to convert : ");
    n = Convert.ToInt32(Console.ReadLine());
     dn=n;
     i=1;

      for(j=n;j>0;j=j/8)
       {
        ocno=ocno+(j % 8)*i;
        i=i*10;
        n=n/8;
       }
     
     Console.Write("\nThe Octal of {0} is {1}.\n\n",dn,ocno);
}
}
هل كان المحتوى مفيد؟

تبحث عن مدرس اونلاين؟

محتاج مساعدة باختيار المدرس الافضل؟ تواصل مع فريقنا الان لمساعدتك بتأمين افضل مدرس
ماهو التخصص الذي تبحث عنه؟
اكتب هنا...