Advertisement

(TCO 2) Although the following code compiles and runs- the programmer.docx

pjoseph6
Jan. 30, 2023
(TCO 2) Although the following code compiles and runs- the programmer.docx
(TCO 2) Although the following code compiles and runs- the programmer.docx
(TCO 2) Although the following code compiles and runs- the programmer.docx
Upcoming SlideShare
System programmin practical fileSystem programmin practical file
Loading in ... 3
1 of 3
Advertisement

More Related Content

More from pjoseph6(20)

Advertisement

(TCO 2) Although the following code compiles and runs- the programmer.docx

  1. (TCO 2) Although the following code compiles and runs, the programmer broke some major readability rules. Describe at least three changes that would make it easier for other programmers to read and understand the code. class Program { static void Main() //main { int a; int Floater = 10; // ints for(int i = 0;i < Floater;i++) /* loop */{ a=function(i); Console.WriteLine(a); } Console.Read(); //read } public static int function(int a) /*function*/ { return (int)(Math.Pow((double)a,2.0)); } } (Points : 20)
  2. Solution using System; namespace Application { class Program { public static int function(int a) /*function*/ { return (int)(Math.Pow((double)a,2.0)); } static void Main() //main { int a; int Floater = 10; // ints for(int i = 0;i < Floater;i++) /* loop */{ a=function(i); Console.WriteLine(a); } Console.Read(); //read
  3. } } } Output:
Advertisement