Testing.

Sunday, 29 January 2017

C programming langauge: C program to count number of digits.

---------------------------------------------------------------------------------------------------------------
#include<stdio.h>
#include<conio.h>
void main()
{
int count=0,rem,num,n;
printf("\nEnter Numbers: ");
scanf("%d",&num);
n=num;
while(num)
{
rem=num%10;
count=count+1;
num=num/10;
}
printf("\nIn %d Having %d Digits...",n,count);
getch();
}


C programming language: C program to check given number is strong number or not.

Strong Number:-
A number is said to be STRONG if the sum of the factorials of its digits is equal to number itself.
   Example:- 145. 1!+4!+5!=1+24+120=125=145.
----------------------------------------------------------------------------------------------------------------
#include<stdio.h>
#include<conio.h>
void main()
{
int n,res=0,i,n1,rem;
int fct;
printf("\nEnter Number: ");
scanf("%d",&n);
n1=n;
while(n)
{
rem=n%10;
fct=1;
for(i=rem;i>=1;i--)
fct=fct*i;
res=res+fct;
n=n/10;
}
if(res==n1)
printf("\n %d Is A Strong Number... ",n1);
else
printf("\n %d Is Not A Strong Number...",n1);
getch();

Sunday, 22 January 2017

C programming language: C program to find Fibonacci sequence/series using recursion


#include<stdio.h>
#include<conio.h>
void FiboScrs(int);

int main()
{
    int n;
    printf("\nEnter Range of Fibonacci Series: ");
    scanf("%d",&n);

    printf("\nFibonacci Series: ");
    printf("%d %d ",0,1);
    FiboScrs(n);

    return 0;
}

void FiboScrs(int n)
{
    static long int fst=0,scnd=1,sum;

    if(n>0){
         sum = fst + scnd;
         fst = scnd;
         scnd = sum;
         printf("%ld ",sum);
         FiboScrs(n-1);
    }
getch();
}

C programming language: C program to find first ten Fibonacci sequence/series.

For Example:- 0 1 1 2 3 5 8 13 21 34
----------------------
#include<stdio.h>
#include<conio.h>
void main()
{
int n,i,a,b,c;
    printf("\nEnter a number: ");
    scanf("%d",&n);
    i=1;
    a=0;
    b=1;
    while(i<=n)
    {
        printf(" %d  ",a);
        c = a + b;
        a = b;
        b = c;
        i++;
    }
getch();
}

C programming language: C program to print list of palindrome numbers from the given range.


#include<stdio.h>
#include<conio.h>
void main()
{
int rem,revNum=0,num,start,end,temp;
printf("\nEnter Two Numbers : ");
scanf("%d%d",&start,&end);
for(num=start;num<=end;num++)
{
temp=num;
revNum=0;
       while(temp)
       {
         rem=temp%10;
         revNum=revNum*10+rem;
         temp=temp/10;
         if(num==revNum)
 printf("\nPALINDROME NUMBER: %d ",num);
       }
}
getch();
}

C programming language: C program to check given number is palindrome number or not.


#include<stdio.h>
#include<conio.h>
void main()
{
int num,rem,sum=0,n;
printf("\nEnter Number To Check: ");
scanf("%d",&num);
n=num;
   while(num)
   {
     rem=num%10;
     sum=sum*10+rem;
     num=num/10;
   }
if(n==sum)
printf("\n%d Is Palindrome: ",n);
else
printf("\n%d Is Not palindrome:",n);
getch();
}

C programming language: Write a prime number program in c.


#include<stdio.h>
#include<conio.h>
void main()
{
int n,n1,n2,t,cnt=0,flag;
printf("\nEnter Two Values: ");
scanf("%d%d",&n1,&n2);
for(n=n1;n<=n2;n++)
{
flag=0;
for(t=2;t<n/2;t++)
{
if(n%t==0)
{
flag=1;
break;
}
}
if(flag==0)
printf("\n%d. Prime Number: %d",++cnt,n);
}
getch();
}

Saturday, 21 January 2017

C programming language: C program to print list of Armstrong numbers.


#include<stdio.h>
#include<conio.h>
void main()
{
int n,num,j,sum=0,rem,cnt=0;
printf("\nEnter Value: ");
scanf("%d",&n);
for(num=153;num<=n;num++) //Here have initialize num by 153 because, 153 is the smallest                                                                   armstrong number. 
{
sum=0;
for(j=num;j!=0;)
{
rem=j%10;
sum=sum+rem*rem*rem;
j=j/10;
}

if(num==sum)
printf("\n%d Armstrong Number: %d ",++cnt,num);
if(cnt==4)
break;
}
getch();
}

C programming language: C program to check given number is Armstrong number or not.

 Armstrong number means :-
             Sum of every individual digit's cube value should be equal to that number.
Example:
           153=1^3 + 5^3+ 3^3.
                 =1+125+27
                 =153
-------------------------------------------------------------------------------------------------------------------
#include<stdio.h>
#include<conio.h>
void main()
{
int n,num,i,sum=0,rem;
printf("\nEnter Number To Check: ");
scanf("%d",&num);
n=num;
while(num)
{
rem=num%10;
sum=sum+rem*rem*rem;
num =num/10;
}
if(n==sum)
printf("\n%d Is An Armstrong...",n);
else
printf("\n%d Is Not An Armstrong...",n);
getch();
}

C programming langauge: C program to print list of perfect numbers up to given range.

Because  6 is the smallest perfect number in number system, so we will find list of perfect numbers   from 6 to 10000.
------------------------------------------------------------------------------------------------------------------
#include<stdio.h>
#include<conio.h>
void main()
{
int num,i,sum,n,cnt=0;
printf("\nEnter number:");
scanf("%d",&n);
     for(num=6;num<=n;num++)
     {
sum=0;
for(i=1;i<=num/2;i++)
{
if(num%i==0)
sum=sum+i;
}
if(sum==num)
printf("\n%d. PERFERCT NUMBER %d. ",++cnt,num);
if(cnt==4)
break;
}
getch();
}


C programming language: C program to check given number is perfect number or not.

Perfect number is a positive integer number  that is equal to the sum of its divisors.
Example: 6 is the smallest perfect number in number system.
                Here divisors of 6 is 1,2 and 3.
                Here 1+2+3=6 is a perfect number.
-------------------------------------------------------------------------------------------------------------------------
#include<stdio.h>
#include<conio.h>
void main()
{
int num,i,sum=0;
printf("\nEnter Number To Check :");
scanf("%d",&num);
     for(i=1;i<=num/2;i++)
     {
       if(num%i==0)
  sum=sum+i;
     }
   if(num==sum)
     printf("\n %d Is a Perfect Number...",num);
else
printf("\n %d Is Not a Perfect Number...",num);
getch();
}



Tuesday, 3 January 2017

C programming language: Prime number program in c.


// simple code but not optimized much.
#include<stdio.h>
#include<conio.h>
void main()
{
int i,n,flag=0;
printf("\nEnter Number to Check Prime: ");
scanf("%d",&n);
for(i=2;i<n/2;i++)
{
if(n%i==0)
{
flag=1;
        break;
}

else
flag=0;
}
if(flag==0)
printf("\nGiven Number is prime:");
else
    printf("\nGiven Number is Not prime: ");
getch();
}




// simple and optimized code. 
#include<stdio.h>
#include<conio.h>
void main()
{
int p=2;
int n,num;
printf("\nEnter Number to Check Prime: ");
scanf("%d",&num);
n=num;
while(num%p++!=0);  // dummy while loop 
if(p>num)
printf("\nGiven Number is prime:");
else
printf("\nGiven Number is Not prime:");
getch();
}




C programming language: C program to calculate/ find sum of super digits using recursion.

For Example:- 
                 super digit of 9875 will be calculated as:
super-digit(9875) = super-digit(9+8+7+5) 
                  = super-digit(29) 
                  = super-digit(2+9)
                  = super-digit(11)
                  = super-digit(1+1)
                  = super-digit(2)
                  = 2.
-----------------------------------------------------------------------------------------------------------------------
#include<stdio.h>
#include<conio.h>
int recSum(int n);
void main()
{
int n,ans;
printf("\n Enter number: ");
scanf("\n%d",&n);
ans=recSum(n);
printf("\n Sum:=%d",ans);
getch();
}

int recSum(int n1)
{
int rem,sum=0;
if(n1==0)
return 0;
else
{
rem=n1%10;
sum=rem+recSum(n1/10);
}

if(sum>9)
{
n1=sum;
sum=recSum(n1);
}
return sum;
}


Monday, 2 January 2017

C programming language: C program for sum of digits.


#include<stdio.h>
#include<conio.h>
void main()
{
int n,sum=0;
int rem;
printf("\nEnter Number: ");
scanf("%d",&n);
 while(n)
  {
   rem=n%10;
   sum=sum+rem;
   n=n/10;
   }
              printf("Sum of Digits: %d",sum);
      getch();
}



Sunday, 1 January 2017

C programming language: Factorial program in c using recursion.

Example: 5!=5*4*3*2*1=120
---------------
#include<stdio.h>
#include<conio.h>

int factorial(int n)
{
if(n<0)
return 0;
else if(n<=1)
return 1;
else
return (n*factorial(n-1));
}
void main()
{
int fact,n;
printf("\nEnter number:");
scanf("%d",&n);
fact=factorial(n);
printf("\nFactorial of %d is :%d ",n,fact);
getch();
}


C programming language: Factorial program in c without using recursion.

Example: 5!=5*4*3*2*1=120
--------------
#include<stdio.h>
#include<conio.h>

int factorial(int n)
{
int f=1,i;
for(i=1;i<=n;i++)
{
f=f*i;
}
return f;
}
void main()
{
int fact,n;
printf("\nEnter number:");
scanf("%d",&n);
fact=factorial(n);
printf("\nFactorial of %d is :%d ",n,fact);
getch();
}


C programming language: write a C program to count number of digits of given integer.




#include<stdio.h>
#include<conio.h>
void main()
{
int count=0,rem,num,n;
printf("\nEnter Numbers: ");
scanf("%d",&num);
n=num;
while(num)
{
rem=num%10;
count=count+1;
num=num/10;
}
printf("\nIn %d Having %d Digits...",n,count);
getch();
}


C progamming language: C program to check whether given number is even number or odd odd number.


#include<stdio.h>
#include<conio.h>
void main()
{
int num;
printf("\n Enter Number to check Even or odd: ");

scanf("%d",&num);
if (num %2 == 0)
printf("\n %d Is An Even Number..! ",num);
else
printf("\n %d Is An odd Number..! ",num);
getch();
}


C programming language : Write a Menu-driven program using Switch-case in C to perform mathematics operations Adition,Subtraction,Multiplication and Division.


    Write a menu driven program to perform following operations in C:
       i) Addition
      ii) Subtraction
     iii) Multiplication and
     iv) Division.

#include<stdio.h>
#include<conio.h>
#include<process.h>
void main()
{
int optn,a,b;
float c;
printf("\n1.Add: ");
printf("\n2.Subtract: ");
printf("\n3.Multiply: ");
printf("\n4.Divide: ");
printf("\n5.Exit: ");
printf("\nWhat u want to do?: ");
scanf("%d",&optn);
switch(optn)
do
{
case 1: printf("\nEnter Numbers to Add: ");
scanf("%d %d",&a,&b);
c=a+b;
printf("Addition's Result Is= %f",c);
break;

case 2: printf("\nEnter Numbers to Subtract: ");
   scanf("%d %d",&a,&b);
c=a-b;
printf("Subtraction's Result Is= %f",c);
   break;

case 3: printf("\nEnter Numbers to Multiply: ");
   scanf("%d %d",&a,&b);
c=a*b;
printf("Multiplication's Result Is= %f",c);
break;

case 4: printf("\nEnter Numbers to Divide: ");
   scanf("%d %d",&a,&b);
c=a/b;
printf("Dividion's Result Is= %f",c);
break;

case 5: exit(0);
default :printf("\n Invalid option...");

}while(optn!=0);
getch();
}