a c program.. how to do it???

Status
Not open for further replies.

anubhav_har

In the zone
Today I got a program which I think maybe easy or maybe too difficult.. lets see can anyone help me...

If a student is asked what is the value of the fraction 26/65.. what he does is cuts the two 6s i.e. one in the numerator and one in the denominator... and says 2/5.. whereas the answer is actually also 2/5.. so the problem in now to find all fractions with numerator b/w 10-99 and denomitor also 10-99... i.e. both numerator and denominators and two digits... and then print it... you can only check and cut in a cross way i.e. in case of 11/21 you can cut the first 1 of 11 with teh second one of 21... ie. cross wise X.. u cannot cut 13/12 bcause 1 in numerator is below 1 in denomirnator...
Please somebody code it...
 

siriusb

Cyborg Agent
I.can.give.you.a.hint.though.
Just.do.a.itoa().on.each.number.and.put.each.number.into.a.string.buffer.
Check.if.strlen().is.2.
Next,just.check.the.zeroth.element.of.the.first.buffer.and.the.first.element.of.the.second.number.
If.they.are.equal.to.'one'.then.just.output.the.remaining.chars.of.the.array.
 
OP
A

anubhav_har

In the zone
1hey man i think you do not get the sum... the lengh of the nuimerator and denominator will always be two since you you are starting at 10 and ending at 99 always. Next if the numerator and denminator are equal crosswise then u have to check the remaining two characters when divided is equal to the actual answer i.e.
let the fraction be ab/cd then if a=d or b=c then we check that if b/c or a/d respectively whichever is not cut off or whichever is left is equal to ab/cd or not...
I have written the program today and want to share it my frenz here.. This program was a code segment to be written in a qualifying paper of an IT company's recruitment exam which wanted to check logical skills of the ppl sitting in the exam.
Code:
#include<conio.h>
#include<stdio.h>
void main()
{
	int i,j;
	double x,y;
	for(i=10;i<=99;i++)
	{
		for(j=10;j<=99;j++)
		{
			y=i*1.0/j;
			if((i/10)==(j%10))
			{
				x=(i%10)*1.0/(j/10);
				if(x/y==1.0)
				{
					printf(" %d",i);
					printf("---");
					printf("%d",j);
					printf("\t");
				}
			}
			else if((i%10)==(j/10))
			{
				x=(i/10)*1.0/(j%10);				
				if(x/y==1.0)
				{
					printf(" %d",i);
					printf("---");
					printf("%d",j);
					printf("\t");
				}
			}
		}
	}
}
 
Status
Not open for further replies.
Top Bottom