(a) Circulation
1. Print out 5 "Hello world!"
/// /output of 5 "Hello world!" for (int i = 0; i < 5; i++) { Console.WriteLine ("Hello world!"); }
2, an integer that prints out 1-100.
The integer for the PrintOut 1-100 for (int i = 1; i < 101; i++) { if (i%10==0) { Console.WriteLine (i); } }
3. The odd number in print output 1-100
// the odd number in print output 1-100 for (int1101; i++) { if (i%2! =0) { Console.WriteLine (i); } }
4. The number that can be divisible by 3 in print output 1-100
// number that can be divisible by 3 in print output 1-100 for (int1101; i++) { if (i%3= =0) { Console.WriteLine (i); } }
5.
///5. Calculate the sum of 1-100 integers intsum=0; for(inti =1; I <101; i++) {sum+=i; } Console.WriteLine ("The sum of integers is {0}", sum); ///6 Enter 5 integers from the keyboard, add the 5 integers in the input (the first method) intnum, sum =0, Count =0; Do{Console.Write ("Enter Number:"); Num=int. Parse (Console.ReadLine ()); Count++; Sum+=num; } while(Count <5); Console.WriteLine ("and for"+sum); ///7 Calculating the sum of the even numbers in 1-100 intsum =0; for(inti =1; I <101; i++) { ifI2==0) {sum+=i; }} Console.WriteLine ("The sum of the even numbers is {0}", sum); /*8 Write a program to print all the daffodils. The so-called Narcissus number, refers to a three-bit integer, the number of its members of the cubic and equal to the number itself, for example: 153 = 1*1*1 + 5*5*5 + 3*3*3*/ /*9 Enter a number less than 5 digits, judging by the number of digits, and reverse output, such as: 123, output--and input is 3 digits, the reverse output of the result is 321. */Console.Write ("Please enter:"); intnum =int. Parse (Console.ReadLine ()); //Judging is a number of digits if(Num <10000) { if(Num >999) Console.WriteLine ("{0} is a 4-digit number", num); Else if(Num > About) Console.WriteLine ("{0} is a 3-digit number", num); Else if(Num >9) Console.WriteLine ("{0} is a 2-digit number", num); Else if(Num >0) Console.WriteLine ("{0} is a 1-digit number", num); } ElseConsole.WriteLine ("Please enter the number to be less than 5 bits, please reenter"); //Invert output Char[] arr =Num. ToString (). ToCharArray (); Array.reverse (arr); foreach(varItemincharr) {Console.Write (item); } Console.WriteLine (); ///10,hundred money to buy white chicken. //A is a hen, B is a rooster, and C is a chicken. for(intA =1; A <= -; a++) { for(intb =1; b <= -; b++) { for(intc =1; c<= -; C++) { if(a+b+c== -&& A *5+b*3+c*1/3== -&& c%3==0) {Console.WriteLine ("The hen is {0} only, the rooster is {1} only, the chick is {2} only", A,b,c); } } } }
Friends in the atom, feel the problem, please point out, we learn from each other and progress together!
C # Basics Exercises