Showing posts with label Fundamental of Programming. Show all posts
Showing posts with label Fundamental of Programming. Show all posts

Wednesday, April 3, 2013

C Language Example # 50 Series Example # 02 Display Odd numbers Series

C Language Example # 50 Series Example # 02 Display Odd numbers Series.

* This program is example of simple odd number series and even number series.

//Written by : Latest Technology Guide
//Title : C Language Example # 50 Series Example # 02 Display Odd numbers Series.

 
#include <stdio.h>
#include <conio.h>
void main()
{
clrscr();
int sum=1,n,i;

printf("Enter Number of Terms :");
scanf("%d",&n);

printf("\n\n ****** 1st Method  **********\n\n");
for(i=1;i<=n;i=i+2)
{
printf(" %3d ",i);
}
printf("\n\n ****** 2nd Method  **********\n\n");
for(i=1;i<=n;i++)
{
    sum = sum + 2;
    printf(" %3d ",sum);
}


getch();
}
Output:




--------------------------------------------------------------------------------
Explanation of C Programming Language Example # 50 Series Example # 02 Display Odd numbers Series.

*  Program will display odd number series.


Note: All programs are developed and tested using Turbo C++ 3.0 under Windows XP. We just want to provide guidelines to the users. If you are using any other Compiler or other operating system they you need to modify this program as per your requirements.

Tuesday, April 2, 2013

C Language Example # 49 Series Example # 01

C Language Example # 49 Series Example # 01.

* This program is example of simple series.
* Program will display 1 to 10.

//Written by : Latest Technology Guide
//Title : C Language Example #   49 Series Example # 01.

 
#include <stdio.h>
#include <conio.h>
void main()
{
clrscr();
int sum=0,n,i;

printf("Enter Number of Terms :");
scanf("%d",&n);

for(i=1;i<=n;i++)
{
printf(" %3d ",i);
}


getch();
}
Output:



--------------------------------------------------------------------------------
Explanation of C Programming Language Example # 49 Series Example # 01.

*  Program will display simple series from 1 to 10.


Note: All programs are developed and tested using Turbo C++ 3.0 under Windows XP. We just want to provide guidelines to the users. If you are using any other Compiler or other operating system they you need to modify this program as per your requirements.

Monday, April 1, 2013

C Language Example # 48 Recursive Function Call Example # 02 Find out Factorial Using Recursive Function

C Language Example # 48 Recursive Function Call Example # 02 Find out Factorial Using Recursive Function.

* This program is example of recursive call of function.
* Program will calculate .

//Written by : Latest Technology Guide
//Title : C Language Example #   48 Recursive Function Call Example # 02 Find out Factorial Using Recursive Function.

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

void main()
{
    clrscr();
    long int ans;
    int n;

    long int fac(int,int,int);

    printf("How Many Elements are there :  ");
    scanf("%d",&n);

    ans=fac(1,1,n);

    printf("Factorial is : %ld",ans);

    getch();

}
long int fac(int no,int fact,int n)
{


    if(no>=n)
        return(no);
    else

        fact = no *  (fac(no+1,fact,n));

    return(fact);

}
Output:



--------------------------------------------------------------------------------
Explanation of C Programming Language Example # 48 Recursive Function Call Example # 02 Find out Factorial Using Recursive Function.

*  Program will call function itself (recursive call) to display factorial of given number.


Note: All programs are developed and tested using Turbo C++ 3.0 under Windows XP. We just want to provide guidelines to the users. If you are using any other Compiler or other operating system they you need to modify this program as per your requirements.

Sunday, March 31, 2013

C Language Example # 47 Recursive Function Call Example # 01

C Language Example #  47 Recursive Function Call Example # 01.

* This program is example of recursive call of function.
* Program calls function named series. then this function call itself.

//Written by : Latest Technology Guide
//Title : C Language Example #   47 Recursive Function Call Example # 01.

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

void main()
{
    clrscr();
    int n;

    void series(int,int);

    printf("How Many Elements are there :  ");
    scanf("%d",&n);

    series(1,n);

    getch();
}
void series(int start,int n)
{
    if(start>n)
        return;
    else
    {
        printf("%3d",start);
    }
    series(start+1,n);
}
Output:




--------------------------------------------------------------------------------
Explanation of C Programming Language Example #  47 Recursive Function Call Example # 01.

*  Program will call function itself (recursive call) to display series.


Note: All programs are developed and tested using Turbo C++ 3.0 under Windows XP. We just want to provide guidelines to the users. If you are using any other Compiler or other operating system they you need to modify this program as per your requirements.

Tuesday, March 26, 2013

C Language Example # 46 2D Array Find Sum of All Element of Array

C Language Example # 46 2D Array Find Sum of All Element of Array.

* This program calculates sum of all elements of array.

//Written by : Latest Technology Guide
//Title : C Language Example #  46 2D Array Find Sum of All Element of Array.

 
#include <stdio.h>
#include <conio.h>
void main()
{
    clrscr();
    int a[3][3],i,j,sum=0;

    printf("\n\t : Enter the value in 3 x 3 Array : \n");

    for(i=0;i<3;i++)
    {
        for(j=0;j<3;j++)
        {
            printf("Enter Value of A[%d][%d] = ",i,j);
            scanf("%d",&a[i][j]);

        }

    }
    printf("\n\t :  Sum of 3 x 3 array is  : \n");

    for(i=0;i<3;i++)
    {
        for(j=0;j<3;j++)
        {
            sum=sum+a[i][j];
        }
    }

    printf("\n\t Sum : %5d",sum);

    getch();
}


Output:



--------------------------------------------------------------------------------
Explanation of C Programming Language Example # 46 2D Array Find Sum of All Element of Array.

*  Program will find sum of all elements.


Note: All programs are developed and tested using Turbo C++ 3.0 under Windows XP. We just want to provide guidelines to the users. If you are using any other Compiler or other operating system they you need to modify this program as per your requirements.

Monday, March 25, 2013

C Language Example # 45 2D Array Simple Example

C Language Example # 45 2D Array Simple Example.

* This program demonstrate 2D Array Simple Example. Program will scan 3x3 values from user and will display the same value as output.

//Written by : Latest Technology Guide
//Title : C Language Example #  45 2D Array Simple Example.

 
#include <stdio.h>
#include <conio.h>
void main()
{
    clrscr();
    int a[3][3],i,j;

    printf("\n\t : Enter the value in 3 x 3 Array : \n");

    for(i=0;i<3;i++)
    {
        for(j=0;j<3;j++)
        {
            printf("Enter Value of A[%d][%d] = ",i,j);
            scanf("%d",&a[i][j]);

        }

    }
    printf("\n\t :  Now see the Entered Array in A : \n");

    for(i=0;i<3;i++)
    {
        for(j=0;j<3;j++)
        {
            printf("%3d",a[i][j]);
        }
        printf("\n");

    }

    getch();
}


Output:



--------------------------------------------------------------------------------
Explanation of C Programming Language Example # 45 2D Array Simple Example.

* You need to value of 3x3 matrix and program will display this value.


Note: All programs are developed and tested using Turbo C++ 3.0 under Windows XP. We just want to provide guidelines to the users. If you are using any other Compiler or other operating system they you need to modify this program as per your requirements.

Saturday, March 23, 2013

C Language Example # 44 Merge String at nth position of main string (Method 2)

C Language Example # 44 Merge String at nth position of main string (Method 2).

* This program demonstrate addition of one string into another one at specific position.

//Written by : Latest Technology Guide
//Title : C Language Example # 44 Merge String at nth position of main string (Method 2)..

 
#include <stdio.h>
#include <conio.h>
#include <string.h>
void main()
{
    clrscr();
    int i,n,j=0;
    char str[70],addstr[50];

    printf("Enter the String :");
    gets(str);

    printf("Enter New String to Enter : ");
    gets(addstr);

    printf("Enter Position At : ");
    scanf("%d",&n);

    j=strlen(addstr);

    for(i=n;i<strlen(str)-j;i++)
    {
        str[i]=str[i+j];
    }
    str[i]=NULL;

    puts(str);
    printf("New Strlen() is : %3d",strlen(str));

    getch();
}


Output:
* Program will merge string and will display the new string.


--------------------------------------------------------------------------------
Explanation of C Programming Language Example # 44 Merge String at nth position of main string (Method 2).

* You need to enter 3 input. input 1 main string, input 2 : sub string and input 3 : value of n where you want to copy your sub string into main string.
* Program will find that nth position and will copy sub string into main one.


Note: All programs are developed and tested using Turbo C++ 3.0 under Windows XP. We just want to provide guidelines to the users. If you are using any other Compiler or other operating system they you need to modify this program as per your requirements.

C Language Example # 43 Merge String at nth position of main string

C Language Example # 43 Merge String at nth position of main string.

* This program demonstrate addition of one string into another one at specific position.

//Written by : Latest Technology Guide
//Title : C Language Example # 43 Merge String at nth position of main string..
#include <stdio.h>
#include <conio.h>
#include <string.h>
void main()
{
    clrscr();
    int i,n,j=0;
    char str[70],addstr[50];

    printf("Enter the String :");
    gets(str);

    printf("Enter New String to Enter : ");
    gets(addstr);

    printf("Enter Position At : ");
    scanf("%d",&n);

    j=strlen(addstr);

    for(i=strlen(str);i>=n;i--)
    {
        str[i+j]=str[i];
    }

    for(i=0;i<strlen(addstr);i++)
    {
        str[i+n]=addstr[i];
    }
    puts(str);
    printf("New Strlen() is : %3d",strlen(str));

    getch();
}

Output:
* Program will merge string and will display the new string.


--------------------------------------------------------------------------------
Explanation of C Programming Language Example # 43 Merge String at nth position of main string.

* You need to enter 3 input. input 1 main string, input 2 : sub string and input 3 : value of n where you want to copy your sub string into main string.
* Program will find that nth position and will copy sub string into main one.


Note: All programs are developed and tested using Turbo C++ 3.0 under Windows XP. We just want to provide guidelines to the users. If you are using any other Compiler or other operating system they you need to modify this program as per your requirements.

Friday, March 22, 2013

C Language Example # 42 Find Maximum and Minimum from Array and Find Sum of Digit of Maximum Number

C Language Example # 42 Find Maximum and Minimum from Array and Find Sum of Digit of Maximum Number.

* First Program will find out maximum and minimum from array elements.
* Then it will find maximum and minimum value from array.

//Written by : Latest Technology Guide
//Title : C Language Example # 42 Find Maximum and Minimum from Array and Find Sum of Digit of Maximum Number..

#include <stdio.h>
#include <conio.h>
void main()
{
    clrscr();
    int arr[70],i,n,j,temp,mul=1,sum=0,digit;

    printf("Enter the number of elements :");
    scanf("%d",&n);

    for(i=0;i<n;i++)
    {
        printf("Enter Element arr[%d] =",i);
        scanf("%d",&arr[i]);
    }

    for(i=0;i<n;i++)
    {
        for(j=i+1;j<n;j++)
        {
            if(arr[i]<arr[j])    //change < sign to descinding
            {
             //    temp=arr[i];
                arr[i]=arr[i]+arr[j];
              //    arr[i]=arr[j];
                arr[j]=arr[i]-arr[j];
              //    arr[j]=temp;
                arr[i]=arr[i]-arr[j];
            }

        }
    }

    temp=arr[0];

    while(temp>0)
    {
        digit=temp%10;
        sum=sum+digit;
        temp=temp/10;
    }

    temp=arr[n-1];

    while(temp>0)
    {
        digit=temp%10;
        mul=mul*digit;
        temp=temp/10;
    }

    printf("\n\n\tSum of Maximum %3d Number is          : %3d",arr[0],sum);
    printf("\n\tMultiplication of Minimum %3d Number is : %3d",arr[n-1],mul);

    getch();
}

Output:
* Program will display sum of all digits from maximum element from array.
* Program will display multiplication of all digit from minimum element from array. 


--------------------------------------------------------------------------------
Explanation of C Programming Language Example # 42 Find Maximum and Minimum from Array and Find Sum of Digit of Maximum Number.

* You need to enter value of n.
* Enter Number of values.
* Program will find out maximum number from array.
* Program will find out minimum number from array.
* Program will sum all digits of maximum number.
* Program will multiply all digits of minimum number.


Note: All programs are developed and tested using Turbo C++ 3.0 under Windows XP. We just want to provide guidelines to the users. If you are using any other Compiler or other operating system they you need to modify this program as per your requirements.

Thursday, March 21, 2013

C Language Example # 41 (2D) Two Dimension Character Array Sorting

C Language Example # 41 (2D) Two Dimension Character Array Sorting..

* Program will Sort two dimension character array(2D)
.
* In program we have set some string, program will automatically sort this array.

//Written by : Latest Technology Guide
//Title : C Language Example # 41 (2D) Two Dimension Character Array Sorting.


#include <stdio.h>
#include <conio.h>
#include <string.h>
#define NAME 5
#define SIZE 10
void main()
{
    clrscr();
    char ch[NAME][SIZE]={"Ram","Sita","Lakhan","Ramji","Laxman"};
    int i,j;

    char dummy[SIZE];

    for(i=0;i<NAME;i++)
    {
        for(j=i+1;j<NAME;j++)
        {
            if(strcmp(ch[i],ch[j])>0)
            {
                strcpy(dummy,ch[j]);
                strcpy(ch[j],ch[i]);
                strcpy(ch[i],dummy);
            }
        }

    }

    for(i=0;i<NAME;i++)
        puts(ch[i]);

    getch();

}



Output:


--------------------------------------------------------------------------------
Explanation of C Programming Language Example # 41 (2D) Two Dimension Character Array Sorting.

* Program will sort two dimension character array.


Note: All programs are developed and tested using Turbo C++ 3.0 under Windows XP. We just want to provide guidelines to the users. If you are using any other Compiler or other operating system they you need to modify this program as per your requirements.

Wednesday, March 20, 2013

C Language Example # 40 Counter Space and Constant from Character Array

C Language Example # 40 Counter Space and Constant from Character Array..

* Program will count number of spaces and constant characters
.

//Written by : Latest Technology Guide
//Title : C Language Example # 40 Counter Space and Constant from Character Array..


#include <stdio.h>
#include <conio.h>
void main()
{
    clrscr();
    int  i,sp=0,co=0;
    char ch[30]={0};

    printf("\n Now Enter Text : ");
    gets(ch);

    i=0;

    do
    {
        if(ch[i]==32)
            sp=sp+1;
        else
            co=co+1;
        i++;
    }while(ch[i]!=NULL);

    printf("\n\t\t *****: Detail Description :***** ");

    printf("\n Constant = %3d",co);
    printf("\n Spaces   = %3d",sp);

    getch();
}

Output:
* We think there is no need of output. Output is very simple !

--------------------------------------------------------------------------------
Explanation of C Programming Language Example # 40 Counter Space and Constant from Character Array.

* You need to enter character array.
* This program will count number of space and constant.


Note: All programs are developed and tested using Turbo C++ 3.0 under Windows XP. We just want to provide guidelines to the users. If you are using any other Compiler or other operating system they you need to modify this program as per your requirements.

Tuesday, March 19, 2013

C Language Example # 39 Array element sorting without temporary array or variable.

C Language Example # 39 Array element sorting without temporary array or variable..

* Program will Sort array element without using any temporary variable or temporary array
.

//Written by : Latest Technology Guide
//Title : C Language Example # 39 Array element sorting without temporary array or variable..


#include <stdio.h>
#include <conio.h>
void main()
{
    clrscr();
    int arr[70],i,n,j,temp;

    printf("Enter the number of elements :");
    scanf("%d",&n);

    for(i=0;i<n;i++)
    {
        printf("Enter Element arr[%d] =",i);
        scanf("%d",&arr[i]);
    }

    for(i=0;i<n;i++)
    {
        for(j=i+1;j<n;j++)
        {
            if(arr[i]>arr[j])     //change < sign to descending
            {
             //    temp=arr[i];
                arr[i]=arr[i]+arr[j];
              //    arr[i]=arr[j];
                arr[j]=arr[i]-arr[j];
              //    arr[j]=temp;
                arr[i]=arr[i]-arr[j];
            }
        }
    }

        for(i=0;i<n;i++)
            printf("%3d",arr[i]);

    getch();
}


Output:




--------------------------------------------------------------------------------
Explanation of C Programming Language Example # 39 Array element sorting without temporary array or variable..

* You need to enter upper bound value of array for which you are going to enter value and want to sort this array.
* You need to enter array values up to array upper bound.
* This program will sort array elements.


Note: All programs are developed and tested using Turbo C++ 3.0 under Windows XP. We just want to provide guidelines to the users. If you are using any other Compiler or other operating system they you need to modify this program as per your requirements.

Friday, March 15, 2013

C Language Example # 38 Simple Array Multiplication

C Language Example # 38 Simple Array Multiplication.

* Program will simply multiply array elements into another one.
* This program is not a matrix multiplication, This program will simply multiply the array elements.

//Written by : Latest Technology Guide
//Title : C Language Example # 38 Simple Array Multiplication.



#include <stdio.h>
#include <conio.h>
void main()
{
clrscr();
int a[5]={0},b[5]={0},c[5]={0},i;
float d[5]={0};

printf("\n Now Enter Value for Array A : \n");

for(i=0;i<5;i++)
{
printf("a[%d] = ",i);
scanf("%d",&a[i]);
}

printf("\n Now Enter Value for Array B : \n");

for(i=0;i<5;i++)
{
printf("b[%d] = ",i);
scanf("%d",&b[i]);
}

printf("\n Now Enter Value for Array C : \n");

for(i=0;i<5;i++)
{
printf("c[%d] = ",i);
scanf("%d",&c[i]);
}


for(i=0;i<5;i++)
d[i]=a[i]*b[i]*c[i];

printf("\n\t : Multiplication of A * B  * C is Stored in D : ");
printf("\n\t\t\t : See All D element :");

for(i=0;i<5;i++)
printf("\nd[%d] = %5.2f",i,d[i]);


getch();
}


Output:





--------------------------------------------------------------------------------
Explanation of C Programming Language Example # 38 Simple Array Multiplication.

* You need to enter array values into 3 array for multiplication.
* Then program will multiply 3 array value into 3rd one.
* Don't confuse with matrix multiplication, this program is not for matrix multiplication.
* This program is not for row column multiplication.


Note: All programs are developed and tested using Turbo C++ 3.0 under Windows XP. We just want to provide guidelines to the users. If you are using any other Compiler or other operating system they you need to modify this program as per your requirements. 

Wednesday, March 13, 2013

C Language Example # 37 Convert sting to upper case without using toupper function

C Language Example # 37 Convert sting to upper case without using toupper function.

* Program will convert string to upper case without using toupper function.

//Written by : Latest Technology Guide
//Title : C Language Example # 37 Convert sting to upper case without using toupper function.

#include <stdio.h>
#include <conio.h>
#include <string.h>
void main()
{
clrscr();
int i;
char ch[30];

printf("\n Enter Lower Case Character : ");
gets(ch);


printf("\n ********** : Upper Case Character :**********\n\n");

i=0;
do
{
if(ch[i]>=97)
putchar(ch[i]-32);
else //if(ch[i]>=65 || ch[i]>=90)
{
putchar(ch[i]);
// printf("%c",ch[i]);
}
i++;
}while(ch[i]!=NULL);

getch();
}


Output:



--------------------------------------------------------------------------------
Explanation of C Programming Language Example # 37 Convert sting to upper case without using toupper function.

* You need to enter string in lower letters.
* Then program will convert string into upper letter without using toupper function.


Note: All programs are developed and tested using Turbo C++ 3.0 under Windows XP. We just want to provide guidelines to the users. If you are using any other Compiler or other operating system they you need to modify this program as per your requirements.