Pages

Tampilkan postingan dengan label statement. Tampilkan semua postingan
Tampilkan postingan dengan label statement. Tampilkan semua postingan

Rabu, 25 Mei 2016

Convert C Coding into C Coding without using goto Statement

Convert C Coding into C# Coding without using goto Statement

Program Statement:
How many printf statements will be executed by this program and rewrite the following program without using goto statement.
void main( )
{
int i, j, k ;
for ( i = 1 ; i <= 3 ; i++ )
{
for ( j = 1 ; j <= 3 ; j++ )
{
for ( k = 1 ; k <= 3 ; k++ )
{
if ( i == 3 && j == 3 && k == 3 )
goto out ;
else
printf ( "%d %d %d ", i, j, k ) ;
}
}
}
out :
printf ( "Out of the loop at last!" ) ;
}

Solution:
 public class _check
{
int i, j, k, check=0;
public void c()
{
for (i = 1; i <= 3; i++)
{
for (j = 1; j <= 3; j++)
{
for (k = 1; k <= 3; k++)
{
if (i == 3 && j == 3 && k == 3)
{
Console.WriteLine(" Out of the loop at last ");
break;
}
else
{
Console.WriteLine(" {0},{1},{2}", i, j, k);
check = check + 1;
}

}
}
}
Console.WriteLine(" Loop iterated {0} times! ", check);
}
}


Read More..

Senin, 16 Mei 2016

C program to Check leap Year Using Conditional Statement

C# program to Check Year is leap or not Using Conditional Statement 

Program Statement: 
Write a program using conditional operators to determine whether a year entered through the keyboard is a leap year or not.

Solution:
static void Main(string[] args)
{
int year;
Console.WriteLine("Enter Year");
year = Convert.ToInt32(Console.ReadLine());
Console.WriteLine( year % 4 == 0 ? "Entered year is leap" : "Not leap year");
Console.ReadLine();}


Read More..

Sabtu, 07 Mei 2016

C program to Find Worker efficiency using if else statement

C# program to find Worker efficiency using if_else statement 

Program statement:
In a company, worker efficiency is determined on the basis of the time required for a worker to complete a particular job. If the time taken by the worker is between 2 – 3 hours, then the worker is said to be highly efficient. If the time required by the worker is between 3 – 4 hours, then the worker is ordered to improve speed. If the time taken is between 4 – 5 hours, the worker is given training to improve his speed, and if the time taken by the worker is more than 5 hours, then the worker has to leave the company. If the time taken by the worker is input through the keyboard, find the efficiency of the worker.

Solution:
static void Main(string[] args)
{
double time;
Console.WriteLine("Enter the Workers Time to complete Task:");
time = Convert.ToDouble(Console.ReadLine());
if (time >= 2 && time <=3)
Console.WriteLine("Good! Worked Efficiently");
else if(time>3 && time<=4)
Console.WriteLine("Improved Your working Speed");
else if(time>4 && time<=5)
Console.WriteLine("Required Tranning to improve Speed");
else if(time>5)
Console.WriteLine("Leave this company");
else
Console.WriteLine("No Result for this input");
Console.ReadLine();
}


Read More..