Question

C# code required Write two code segments that print the integers 1 through 10. One segment...

C# code required

Write two code segments that print the integers 1 through 10. One segment should use a while loop and the other should use a for loop.

Homework Answers

Answer #1
using System;

class Program
{
    static void Main() {
        for(int i = 1;i<=10;i++)
            Console.WriteLine(i);
    }
}

///////////////////////////////////////////////////////////

using System;

class Program
{
    static void Main() {
        int i = 1;
        while(i<=10){
            Console.WriteLine(i);
            i++;
        }
    }
}

Know the answer?
Your Answer:

Post as a guest

Your Name:

What's your source?

Earn Coins

Coins can be redeemed for fabulous gifts.

Not the answer you're looking for?
Ask your own homework help question
Similar Questions
Write a code segment to print your name ten times on the screen using a while...
Write a code segment to print your name ten times on the screen using a while loop. Use one variable called count to act as a counter for the loop. Discuss how would you print your name 1000 times on the screen. NOTE: You can either type your code into the text box or upload a document to the discussion board by clicking the "attach" clip at the bottom left of the discussion box.
Write a Java code snippet with a nested for loop to print five rows of six...
Write a Java code snippet with a nested for loop to print five rows of six random integers between 5 and 10 inclusive.
CODE BLOCK C computer_num == 7 print("Guess a number form 1 to 10") # set users...
CODE BLOCK C computer_num == 7 print("Guess a number form 1 to 10") # set users guess value to zero so we enter the loop guess = 0 while guess == computer_num guess = input ("Enter a guess (1-10)") print("Correct the number is "+str(computer_num)) How many times will “Correct the number is…” print when this code block is executed?.
In Java programming language 11.Create the code for a for loop to print the numbers 1  through...
In Java programming language 11.Create the code for a for loop to print the numbers 1  through 5 inclusive vertically so the output is 1 2 3 4 5 11b What is the output of the following               OUTPUT int i=3; while(int i >0) { System.out.println(i); i--; } 11c What is the output of the following               OUTPUT for(int i=3;i<10;i++) System.out.println(3*i); 11d Create the line of code to print the numbers 10 through 1 decreasing by 1 each time 11e Create the line of code...
For Java programming code: Write methods to add and multiply 1) Two integers 2) Two decimals...
For Java programming code: Write methods to add and multiply 1) Two integers 2) Two decimals 3) One integer and one decimal
In C++ Please, Write a code fragment that uses a loop to calculate ln (i.e. natural...
In C++ Please, Write a code fragment that uses a loop to calculate ln (i.e. natural log), from values of ranging from ‘1’ through ‘10’ in steps of ‘1’. Print out in this format: Ln(1) = 0 Ln(2) = 0.6931 etc.
This code is in C++ Write a function named printMultTable that takes 2 integers, numValues and...
This code is in C++ Write a function named printMultTable that takes 2 integers, numValues and factor, and prints the first numValues greater than 0 that are multiples of  factor, separated by SPACE. It has no return value. printMultTable(5, 4) should print the first 5 multiples of 4, separated by a space, which is "4 8 12 16 20" printMultTable(3, 6) should print the first 3 multiples of 6, separated by a space, which is "6 12 18"   
Write a program on C++ to calculate and print the factorial of a number using a...
Write a program on C++ to calculate and print the factorial of a number using a for loop. The factorial of a number is the product of all integers up to and including that number, so the factorial of 4 is 4*3*2*1= 24.
IN JAVA 1. Write up a small program that accepts two integers from the user. Print...
IN JAVA 1. Write up a small program that accepts two integers from the user. Print which of the two values is bigger. If they are the same, print that they are the same. 2. Write a method that accepts three doubles. Calculate and return the average of the three passed double values. 3. Write up a method that accepts a score between 0-10. Print out a message according to the following table. You ay personally decide the boundaries. i.e.,...
Write a C++ Program to print the first letter of your first and last name using...
Write a C++ Program to print the first letter of your first and last name using stars. Note: 1) Using nested For Loop 2) The number of lines is given by user. 3) Using one Outer loop to print your letters. 4) Print the letters beside each other my name's Aya amro
ADVERTISEMENT
Need Online Homework Help?

Get Answers For Free
Most questions answered within 1 hours.

Ask a Question
ADVERTISEMENT