Calculate factorial of a Number without Recursion

Tuesday, 3 June 2014

This is a program for calculating factorial of a given number without any loop or using recursion. Lets look at the code below.




//  Simple Program Factorial Calculation


#include<conio.h>
#include<stdio.h>


int fact(int n)
{
if(n==1||n==0)
return 1;
else
return(fact(n-1)*n);
}

void main()
{
int n,t;
scanf("%d",&n);
printf("%d",fact(n));
getch();
}








Continue Reading | comments

comparison b/w integer and floating variables

Monday, 2 June 2014

I got a question in amdocs about comparison b/w different data types in C. Definitely some people thinks its too easy to judge the output. Bt when you will see same sort of options. You will humble there. Its gud to see the output.




int main()
  {
     int i=1;
     double j=1.00000;
     float k=1;
     if(i==j)
     printf("You r Same\n");
     if(i==k)
     printf("Again you r same\n");
  }

 
 
 
  // Comparing same values with different Data Types.

OUTPUT :


Continue Reading | comments

Convert integer to binary value program in C

Wednesday, 28 May 2014

Very easy implementation for convertion a integer value to a binary values. Let us see the program and output. How it performs, i used a string and append output after getting remainder (giving condition on that). Eventually ended up with reverse string which is actual binary value of given number.




#include<stdio.h>
#include<conio.h>
#include<string.h>



void convertToBytes(int a)
{
         int i=0;
        char b[10];
while(a>0)
{
     if(a%2==0)
    {
         b[i]='0';
         i++;
     }
     else
    {
        b[i]='1';
        i++;
     }
 a=a/2;
}

b[i]='\0';
strrev(b);
printf("%s\n",b);

}

void main()
{
   int n;
   printf("Enter Your Number\n");
   scanf("%d",&n);
   convertToBytes(n);
   getch();
}



// Output :



Continue Reading | comments
 
My Other Websites : Ad Networks | Games Copyright © 2014. Study Depth - All Rights Reserved