Testing.

Sunday, 5 February 2017

C programming language: C program to find minimum/smallest element from the given array in c

#include<conio.h>
#include<stdio.h>
void main()
{
int arr[10];
int i,m;
printf("\nEnter Array Element:\n");
for(i=0;i<10;i++)
scanf("%d",&arr[i]);

printf("\nEntered Array Elements Are:\n");
for(i=0;i<10;i++)
printf(" %d",arr[i]);

m=arr[0];
for(i=0;i<10;i++)
{
if(arr[i]<m)
m=arr[i];
}
printf("\n %d Is The Min Element In Array:\n",m);
getch();
}

C programming language: C program to find maximum/largest element from the given array in c


#include<conio.h>
#include<stdio.h>
void main()
{
int arr[10];
int i,m;
printf("\nEnter Array Element:\n");
for(i=0;i<10;i++)
scanf("%d",&arr[i]);

printf("\nEntered Array Elements Are:\n");
for(i=0;i<10;i++)
printf(" %d",arr[i]);

m=arr[0];
for(i=0;i<10;i++)
{
if(arr[i]>m)
m=arr[i];
}
printf("\n %d Is The Max Element In Array:\n",m);
getch();
}

C programming language: First Array program in c.


#include<stdio.h>
#include<conio.h>
void main()
{
int arr[5]={10,20,30,40,50};
printf("\nArray Elements Are: ");
printf("\n %d",arr[0]);
printf("\t %d",arr[1]);
printf("\t %d",arr[2]);
printf("\t %d",arr[3]);
printf("\t %d",arr[4]);
getch();
}

----------------------------------------------------------------------------------------------------------------
First Array program.
----------------------------------------------------------------------------------------------------------------
#include<stdio.h>
#include<conio.h>
void main()
{
int arr[5];
arr[0]=10;
        arr[1]=20;
arr[2]=30;
arr[3]=40;
arr[4]=50;
printf("\nArray Elements Are: ");
printf("\n %d",arr[0]);
printf("\t %d",arr[1]);
printf("\t %d",arr[2]);
printf("\t %d",arr[3]);
printf("\t %d",arr[4]);
getch();
}

----------------------------------------------------------------------------------------------------------------
First Array program.
----------------------------------------------------------------------------------------------------------------#include<stdio.h>
#include<conio.h>
     void main()
     {
       int arr[5],i;
printf("\nEnter Array Elements: ");
for(i=0;i<5;i++)
scanf("%d",&arr[i]);

printf("\nArray Elements Are: ");
for(i=0;i<5;i++)
printf(" %d",arr[i]);
getch();
     }

C programming language: What is an Array in C ?


An array is a derived data type in 'C' which is constructed from fundamental data types of 'C' programming language.

An array is a collection of same types of data elements in a single entity.

In implementation when we require 'n' numbers of values of same data type, then recommended to create an array.

When we are working with arrays always static memory allocation will happen i.e. compile time memory management.

When we are working with arrays, always  memory   is constructed in continuous memory location that's why it is possible to access the data randomly.

When we are working with arrays all values will share same name with unique  identification value called 'index'.

And this array index must be started with 0 (Zero) and ends with (size-1).

It is required to use subscript operator '[]' while working with arrays.

Subscript operator '[]' require one argument of type  Unsigned integer constant, and its value must be ' > 0'  (greater than)only.

Syntax to create an array:-
                             DataType ArrayName[size];
         Example:-
               int arr[10];
               char arr[10];

In general arrays are classified into two types:
1) Single -dimensional arrays.
2) Multi dimensional arrays.

1) Single-dimensional arrays:-
                A single dimensional array and one-dimensional array consist of a fixed number of elements of the same data organized as a simple linear sequence. The elements of a single-dimensional array can be accessed by using a single subscript operator, thus they are also known as single sub-scripted variable.and it is also known as linear arrays and vectors.
     Single dimensional array is shown as below:-



 Declaration of a single-dimensional array:-
                The general form of a single-dimensional array declaration is 
                                 DataType ArrayName[size];
Example of single-dimensional array:-
                   int arr[5]; //array of 5 integers.
                   float arr[5];  //array of 5 floats.
                   char[10]; //array of 10 characters.

2) Two-dimensional arrays:-

 In 2D array, elements are arranged in rows and column format.

When we are working with 2D array , we required to use 2 subscript operators which indicates row size and column size.

The main memory of 2D array is row size and elements are available in column.

On 2D array when we are applying one subscript operator then it gives row name, row name always provides corresponding row address.

From 2D array when we required to access the element then 2 subscript operators required to use.

Array name always provides main memory address of an array, 

  Two-dimensional array is shown as below:-

Declaration of a two-dimensional array:-
                The general form of a two-dimensional array declaration is 
                                 DataType ArrayName[Rsize][Csize];
               where Rsize indicates row size and Csize indicates column size.
Example of two-dimensional array:-
                   int arr[2][3]; // integer array of  2 rows and 3 columns.
                   float arr[5][1];  // float array of  5 rows and 1 columns.
                   char[3][3]; // character array of  3 rows and 3 columns.

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();
}