## Posts

Showing posts with the label number

### convert string value into fractional in ruby on rails

Convert string value into fractional self.try(:shipping).fractional.to_f   // this will convert string value to fractional example- if  self.try(:shipping)  =>   #<1500 Euro shiiping> then   self.try(:shipping).fractional.to_f will return 1500

### Rational Number or Rational Mothod in ruby or rational operation

Rational Number or Rational Mothod in ruby or Rational operation Rational Number is always comes with paired integer Number(1 ,2 ,3 .... && -1, -2, .....) x/y (where y>0). Rational (1) => (1/1) Rational (2, 5) =>(2/5) Rational(4, -8) => (-1/2) 5.to_r =>(5/1) 2/3r => (2/3) Rational into Numeric rational*numeric -> numeric (perfoms multiplecation) Rational(1, 3)  * Rational(2, 3)   => (2/9) Rational(200)   * Rational(1)      => (200/1) Rational(-5, 4) * Rational(-4, 5)  => (1/1) Rational(9, 4)  * 4                => (9/1) Rational(20, 9) * 9.8              => 21.77777777777778 rat ** numeric => numeric (Performs exponentiation) Rational(3)    ** Rational(3)    => (27/1) Rational(10)   ** -2             => (1/100) Rational(10)   ** -2.0           => 0.01 Rational(-4)   ** Rational(1,2)  => (1.2246063538223773e-16+2.0i) Rational(1, 2) ** 0              => (1/1) Rational(2,

### Types of constants in c

There are  two  types of constants available in c language. Primary constants  - intreger constants, real constants, character constants. Secondary constants - array, pointer, structure, union, enum. etc

### Fibonacci series without using recursion?

#include<stdio.h> #include<conio.h> void printFibonacci(int n){ static int n1=0,n2=1,n3; if(n>0){ n3 = n1 + n2; n1 = n2; n2 = n3; printf("%d ",n3); printFibonacci(n-1); } } void main(){ int n; clrscr(); printf("Enter the number of elements: "); scanf("%d",&n); printf("Fibonacci Series: "); printf("%d %d ",0,1); printFibonacci(n-2); //n-2 because 2 numbers are already printed getch(); } Enter the number of elements : 15 0 1 1 2 3 5 8 13 21 34 55 89 144 233 377

### Most efficient way to store flag values?

A flag is a value used to make a decision between two or more options in the execution of a program. For instance, the /w flag on the MS-DOS dir command causes the command to display filenames in several columns across the screen instead of displaying them one per line. In which a flag is used to indicate which of two possible types is held in a union. Because a flag has a small number of values (often only two), it is tempting to save memory space by not storing each flag in its own  int  or  char . Efficiency in this case is a tradeoff between size and speed. The most memory-space efficient way to store a flag value is as single bits or groups of bits just large enough to hold all the possible values. This is because most computers cannot address individual bits in memory, so the bit or bits of interest must be extracted from the bytes that contain it. The most time-efficient way to store flag values is to keep each in its own integer variable. Unfortunately, this method can w

### C program to print Armstrong numbers from 1 to 1000?

#include<stdio.h> #include<conio.h> void main() { int i=153,n,temp,num,r,sum=0; clrscr(); while(i<=1000) { n=i; temp=n; while(n>0) { r=n%10; sum=sum+(r*r*r); n=n/10; } if(temp==sum) { printf("the armstrong number is %d\n",sum); } i++; } getch(); }

### my input a=12, but how do I print this in 3 digits?

There are many ways to do this. I am using the simplest way to print two digit number in three digit number. import java . util . Scanner ; class Digit { public static void main ( String [] args ) { Scanner sc = new Scanner ( System . in ); System . out . println ( "please enter any two digit number:" ); int n = sc . nextInt (); int k = 0 ; if ( n > 9 && n < 100 ) { k = n * 10 ; } else { System . out . println ( "please enter any two digit number:" ); } System . out . println ( "you entered " + n + " and three digit output of this number is " + k ); } Read More