0% found this document useful (0 votes)
2 views2 pages

Modulus Operator

The document contains four console applications that perform different conversions. The first converts total seconds into hours, minutes, and seconds; the second extracts thousands, hundreds, tens, and units from a 4-digit number; the third converts total days into years, weeks, and days; and the fourth converts a 4-bit binary number to decimal. Each application prompts the user for input and displays the results accordingly.
Copyright
© All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
2 views2 pages

Modulus Operator

The document contains four console applications that perform different conversions. The first converts total seconds into hours, minutes, and seconds; the second extracts thousands, hundreds, tens, and units from a 4-digit number; the third converts total days into years, weeks, and days; and the fourth converts a 4-bit binary number to decimal. Each application prompts the user for input and displays the results accordingly.
Copyright
© All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd

1.

Time converter
[Link]("Enter total seconds: ");
int totalseconds = [Link]([Link]());

//convert seconds into hours


int hours = totalseconds / 3600;
//convert seconds into minutes by using %:modulus operator we also want to
convert remaining seconds.
int minutes = (totalseconds % 3600) / 60;
//find remaining seconds
int seconds = totalseconds % 60;

//print
[Link]($"{[Link]("D2")}:{[Link]("D2")}:
{[Link]("D2")}");

[Link]("\nPress any key to exit...");


[Link]();

2. Extract Digits
Extract thousands, hundreds, tens, and units from a number.

[Link]("Enter a 4-digit number: ");


int num = [Link]([Link]());

int thousands = num / 1000;


int hundreds = (num / 100) % 10;
int tens = (num / 10) % 10;
int units = num % 10;

[Link]($"Thousands: {thousands}");
[Link]($"Hundreds: {hundreds}");
[Link]($"Tens: {tens}");
[Link]($"Units: {units}");

[Link]("\nPress any key to exit...");


[Link]();

3. Convert Days → Years, Weeks, Days


[Link]("Enter total days: ");
int days = [Link]([Link]());

int years = days / 365;


int remainingDays = days % 365;

int weeks = remainingDays / 7;


int finalDays = remainingDays % 7;

[Link]($"{years} years, {weeks} weeks, {finalDays} days");


4. 4-bit Binary to Decimal
[Link]("Enter 4-bit binary: ");
int binary = [Link]([Link]());

int d1 = binary / 1000;


int d2 = (binary / 100) % 10;
int d3 = (binary / 10) % 10;
int d4 = binary % 10;

int result = d1 * 8 + d2 * 4 + d3 * 2 + d4;

[Link]("Decimal: " + result);

You might also like