C
Programming and Technical
Programming
Definition
through c programming ,take any real number and convert that number into fraction number
EX:input is 1.5
output is 3/2
Read Solution (Total 5)
-
- #include
main()
{
int i;
float in,ans;
scanf("%f",&in);
for(i=2;ans!=(int)ans;i++)
{
ans=in*i;
}
printf("%d/%d",(int)ans,i-1);
}
- 10 years agoHelpfull: Yes(3) No(2)
- Is there a limit on size of fractional number input?
- 10 years agoHelpfull: Yes(2) No(1)
- main()
{
float in,ans;
int i;
scanf("%f",&in);
for(i=2;ans!=(int)ans;i++)
{
ans=in*i;
}
printf("%d/%d",(int)ans,i);
} - 10 years agoHelpfull: Yes(2) No(6)
- void main(){
float n,k,i=1,j;
printf("Enter any real no:");
scanf("%f",&n);
while(1){
k = n*i;
j = k-(int)k;
if(j==0.0){
printf("%d/%d",(int)k,(int)i);
break;
}
else{
i++;
}
}
} - 10 years agoHelpfull: Yes(1) No(0)
- @SUBRAHMANYAM KELLA excellent
- 10 years agoHelpfull: Yes(0) No(0)
C Other Question
#include
int main()
{
void *ptr1, *ptr2;
int x,y;
x = 100;
y = 200;
ptr1 = &x;
ptr2 = &y;
printf("%d", *(int*)ptr1);
printf("n%d", *(int*)ptr2);
}
A rabbit walk is defined by a sequence of jumps which starts from a
location and returns back to the starting location. We can repesent such
a Rabbit walk by an array A of n numbers, where A[i] denotes the next
array index to which the rabbit should jumps from the location i.
For example, the sequence: 2 3 4 5 0 1 indicates that the Rabbit follows
the jump sequence: 0->2, 2->4, 4->0 and stops.
Your also given another array B of N numbers, such that
B[i] denotes the number of carrots available at location i.
Your task is to compute the number of carrots that a rabbit can collect
when it makes rabbit walk(s) from various start position(s).
A sample input is provided for more clarification(s).
Input:
The first line will contain a single integer N which is the size of the
array (2<= N <= 10000).
The next line contains a series of N integers which define the array A.
The next line contains a series of N integers which define the array B.
You can be assured that all the calculations fit into a 32 bit signed
integer type(int in C).
The input is given such that, a rabbit walk will always exist with
start position as 0.
Output:
It should contain the number of carrots collected
when 0 is treated as the start location.
Sample Input:
6
2 2 2 2 -4 -4
2 3 6 3 0 1
Sample Output:
8