TECHNOLOGIES
FORUMS
JOBS
BOOKS
EVENTS
INTERVIEWS
Live
MORE
LEARN
Training
CAREER
MEMBERS
VIDEOS
NEWS
BLOGS
Sign Up
Login
No unread comment.
View All Comments
No unread message.
View All Messages
No unread notification.
View All Notifications
Answers
Post
An Article
A Blog
A News
A Video
An EBook
An Interview Question
Ask Question
Forums
Monthly Leaders
Forum guidelines
Maha
NA
0
326k
/ and %
May 20 2012 10:38 AM
In this program inches is converted into yard, feet and inches. Even though "n" is in yard and divided by 12 inches, giving output similar to the manual arithmetic but there is no logic because yard is divided by inches. Please explain the reason.
Manual arithmetic
n = 67/36 = 1.
86
yard(36 inches = 1 yard)
Converting remainder 0.86 yard into feet & inches
feet = 36 x 0.86 inches (converting 0.86 yard into inches. 36 inches = 1 yard)
= 30.96 inches
= 2.58 feet
= 2feet 7inches
using System;
public class ConvertInches
{
public static void Main()
{
int inches = 67;
YardsFeetInches(inches);
Console.ReadKey();
}
public static void YardsFeetInches(int number)
{
int yard, n, feet, inches;
yard = number / 36;
n
= number % 36;
//n - is in yard, 36 inches = 1 yard
feet = n / 12; //n is not converted into inches before divided by 12 (12 inches = 1 feet)
inches = n % 12; //n is not converted into inches before applying remainder operator (12 inches = 1 feet)
Console.WriteLine("{0} yard {1} feet {2} inches", yard, feet, inches);
}
}
//1 yard 2 feet 7 inches
Reply
Answers (
3
)
C# winform - how to delete DataGridView Row on a child form?
ASP.Net Study