ابدأ بالتواصل مع الأشخاص وتبادل معارفك المهنية

أنشئ حسابًا أو سجّل الدخول للانضمام إلى مجتمعك المهني.

متابعة

Select the output for the following set of code?

  1. static void Main(string[] args)
  2. {
  3. int i, s = 0;
  4. for (i = 1; i <= ; s = s + i, i++);
  5. {
  6. Console.WriteLine(s);
  7. }
  8. Console.ReadLine();
  9. }

 

a) Code report errorb) Code runs in infinite loop conditionc) Code gives output asd) Code give output as

user-image
تم إضافة السؤال من قبل Mohannad Bakbouk , Full Stack Web Developer , Almohtaseb
تاريخ النشر: 2016/10/20
Amit Sharma
من قبل Amit Sharma , Systems Analyst , TCS

In the below for loop statement 

for (i = 1; i <= ; s = s + i, i++) ;

{

     Console.WriteLine(s);

}

You will get compile time on the code: i <= ;

Because at the right-hand side of the condition you forgot to write any value.

Ubaid sayeed Mohd abdul sayeed
من قبل Ubaid sayeed Mohd abdul sayeed , Senior Programmer , Moksha solutions

error saying incorrect loop condition.

Pathan Zarrar Khadar Khan
من قبل Pathan Zarrar Khadar Khan , Windows System Administrator , Dyce Tech Pvt Ltd

a) Code report error

  1. for (i = 1; i <= ; s = s + i, i++);
  2.  no chance of it code doesn't work 
  3.  your for loop having a wrong statement  its compile time error 
  4. for loop needs three type of statements first one initialization second Condition or third is Increment 
  5. your code having more statements and in the end after the loop its ; its not valid expression 

Hassan Elsherbiny
من قبل Hassan Elsherbiny , .Net Developer , Al-dar international

error ; i <= ; this is not valid condition 

Mohammad Nadir Roshan
من قبل Mohammad Nadir Roshan , Technical Support Specialist , FreeBalance Co

a) Code report error:

In the condition statement of the for loop the i is not given a value to compare against so it throws error "invalid expression term".

Igor Polischuk
من قبل Igor Polischuk , Software Engineer , EPAM

It will display 0.

 

That is everything.

Mohannad Bakbouk
من قبل Mohannad Bakbouk , Full Stack Web Developer , Almohtaseb

No The code Working

  1. for (i = 1; i <= 10; s = s + i, i++);

المزيد من الأسئلة المماثلة