Temperature Conversion from Farenheit to Celcius :
T(in F) = (9/5) T (in C) + 32
T(in F) = (9/5) T (in C) + 32
- int main()
- {
- float T_C,T_F;
- printf ("Enter temperature in celsius: ");
- scanf("%f",&T_C);
- T_F=(1.8*T_C)+32;
- printf("\n\nTemperature in farenheit: %.2f",f);
- return 0;
- }
Factorial of a number, n = n! = n.(n-1).(n-2).(n-3)...3.2.1
This method is iterative(looping) method. Another method called recursive method
is shown in exponential series evaluation.
is shown in exponential series evaluation.
- int main()
- {
- int number,fac_num;
- printf ("Enter a number: ");
- scanf("%d",&number);
- int i;
- for( i = 1 ;i <= number ; i++ ){
- fac_num*=i;
- }
- printf("Factorial: %d",fac_num);
- return 0;
- }
Number Reversal :
If u give input = 123 , the output will be 321
123 = 1( 100)+2(10)+3(1)
321 = 3( 100)+2(10)+1(1)
- int main()
- {
- int digit,number,reversed;
- printf ("Enter a number: ");
- scanf ("%d",&number);
- reversed = 0;
- while(number>0) {
- digit = number % 10;
- reversed = ( reversed * 10 ) + digit;
- number /= 10;
- }
- printf ("The reverse of the number : %d ,reversed);
- return 0;
- }
- //function to calculate factorial (recursive )
- float fac(float i)
- {
- if( i == 1)
- return( 1 );
- else
- return( i * fac (i-1) );
- }
- int main()
- {
- float x, exp_x, numer , denom ;
- float n;
- printf ("\n Enter the value of x: ") ;
- scanf ("%f",&x) ;
- for(n = 0 ; n <= 50 ; i++ ){
- numer = pow (x,n);
- denom = fac ( n );
- exp_x = exp_x+numer/denom;
- }
- printf ("\n e^%f=%e",x,exp_x);
- return 0;
- }
Binary to Decimal Conversion:
For conversion from any number system to decimal system the formula is
Decimal Value = Dn( nth-Weight ) +. . . . .+ D1( 1st-Weight ) + D0(0th-Weight).
For 4 digit binary number
Decimal Value = D3 ( 8 ) + D2 ( 4 ) + D1 ( 2 ) + D0 ( 1 ).
For conversion from any number system to decimal system the formula is
Decimal Value = Dn( nth-Weight ) +. . . . .+ D1( 1st-Weight ) + D0(0th-Weight).
For 4 digit binary number
Decimal Value = D3 ( 8 ) + D2 ( 4 ) + D1 ( 2 ) + D0 ( 1 ).
- int main()
- {
- int decimal,binary;
- printf ("Enter the binary code:");
- scanf ( "%d",&binary);
- int temp, i;
- decimal = 0;
- while(binary > 0){
- temp = binary % 10 ;
- decimal += temp * pow(2,i);
- binray /= 10;
- i++;
- }
- printf("\n\nEquivalent decimal value: %d",decimal);
- return 0;
- }
No comments:
Post a Comment