A very simple looping program for beginners as well as for QAs who are into script writing for Automation. I have created in dot net fiddle. Please find the link as well. This is a simple program which loops through from 1 to 100 and dispays out put as:
Processing 1 ...
1 is a prime Number
1 is an odd number
Processing 2 ...
2 is a prime Number
2 is an even number
Processing 3 ...
3 is a prime Number
3 is an odd number ...
And so on.
So the code goes as below:
- using System;
-
- public class Program
- {
- public static void Main()
- {
- for(int i=1;i<=100;i++){
-
- Console.WriteLine("Processing {0} ...",i);
-
- var primeCheckFlag = true;
- for(int primeCheker = 2; primeCheker<= i/2;++primeCheker){
- if(i%primeCheker==0){
- primeCheckFlag = false;
- break;
- }
- }
- if(primeCheckFlag==true){
- Console.WriteLine("{0} is a prime Number", i);
- }
- else{
- Console.WriteLine("{0} is not a prime Number", i);
- }
-
- var zeroCheck = i/5;
- if(i%5 == 0 && zeroCheck % 2 ==0) {
- Console.WriteLine("{0} has zero in it", i);
- }
-
-
- if(i % 2 == 0){
- Console.WriteLine("{0} is an even number \n", i );
- }
- else{
- Console.WriteLine("{0} is an odd number \n", i);
- }
-
-
- }
- }
- }
This was a question asked by a QAanalyst. This seems easy for developers but for begineers, it would be really handy. Hope you like it and learn atleast something.
Running Fiddle: https://dotnetfiddle.net/1o7riM