Sunday, February 24, 2013

Find Factorial of number using recursion in C

#include<stdio.h>
int factorial(int n)
{
    if(n == 0 || n == 1)
         return 1;
    else
        return n*factorial(n-1);

int main(void)
{
   int n;
   printf("Enter Number to Find Factorial : ");
   scanf("%d", &n);
   printf("Factorial of %d is %d",n,factorial(n));
}


Sample Input and Output:-

Enter Number to Find Factorial : 5
Factorial of 5 is 120


This program works fine to find factorial upto 13. Although thts very small number. To find out factorial of some bigger numbers, keep updated. Will be uploaded soon.



Monday, October 22, 2012

How to see a code of a program without using a dedicated software

From last two days, We got some queries about how to know the coding of a program as they dont have the software installed for the same right now..


The answer of the same question is very simple and clear.

Actually,
When we code for a problem statement in any language like C, C++, Embedded C, Assembly, java, php, html, a special file of dedicated extension is created.

like
for C -.c
for C++ - .cc or .cpp
for Java - .java
for html - .html
for Assembly - .asm
and much more...

These special files are known as compiled files...

in this the code for the program is present.
That code is known as source code.

Compiled files or source files can be opened in any editor, e.g. Notepad......




Monday, October 1, 2012

LCD Circuit


To distinguish whether the number is alphabet, number or special character


#include<stdio.h>
#include<conio.h>
int main(void)
{
    unsigned char a;
    printf("Enter Character : ");
    a = getche();
    if((a>64 && a<91) || (a>96 && a<123))
    {
        printf("Alphabet");
    }
    else if(a>47 && a<58)
    {
        printf("Number");
    }
    else
    {
        printf("Special Character");
    }
    return 0;
}

C++ - To distinguish whether the character is a alphabet or Number or special character.

#include<iostream.h>
#include<conio.h>
int main(void)
{
    unsigned char a;
    cout<<"Enter Character : ";
    a = getche();
    if((a>64 && a<91) || (a>96 && a<123))
    {
        cout<<"Alphabet";
    }
    else if(a>47 && a<58)
    {
        cout<<"Number";
    }
    else
    {
        cout<<"Special Character";
    }
    return 0;
}

C++ - To Print first 100 natural numbers

#include<iostream.h>
#include<conio.h>
int main(void)
{
  int i;
  cout<<"First 100 natural numbers are : \t";
for(i=1; i<=100; i++)
{
            cout<<i<<",\t";
}
getch();
return 0;
}

C++ - To print first 100 even numbers

#include<iostream.h>
#include<conio.h>
int main(void)
{
  int i;
  cout<<"First 100 natural even numbers are : \t";
for(i=1; i<200; i++)
{
      if(i%2==0)
cout<<i<<"\t";
}
getch();
return 0;
}