pages

Thursday, 2 September 2021

Insertion sorting in c-programming || sorting in c-language

 Insertion sorting

 Insertion sort algorithm picks elements one by one and places it to the right position where it belongs in the sorted list of elements. In the following C program we have implemented the same logic.


#include<stdio.h>
#include<conio.h>
void insertion_sort(int A[],int N);
void main()
{
    int A[10],i;
    printf("enter the 10 numbers:-");
    for(i=0;i<10;i++)
    {
        scanf("%d",&A[i]);
    }
    printf("\n the elements are :-");
    for(i=0;i<10;i++)
    {
        printf("%d ",A[i]);
    }
    printf("\n the sorted elements are *****************//////");
    insertion_sort(A,10);
    for(i=0;i<10;i++)
    {
        printf("%d ",A[i]);
    }
    getch();
}
void insertion_sort(int A[],int N)
{
    int j,i,temp;
    for(i=1;i<10;i++)
    {
        temp=A[i];
        for(j=i-1;j>=0 && temp<A[j];j--)
        {
            A[j+1]=A[j];
        }
        A[j+1]=temp;
    }
}















Wednesday, 18 August 2021

History of C LANGUAGE ?

1. WHAT IS C-LANGUAGE ?

C-language is a structure/procedural oriented , middle level  programming language developed at Bell laboratories in 1972 by Dennis Ritchie. It was mainly developed as a system programming language to write an operating system. The first time it was used on a Digital Equipment Corporation computer called PDP – 11 in 1972. 

C language was invented for implementing UNIX operating system.

In 1978,Denis Ritchie and Brian  Kernighan publish the first edition "The C Programming Language".

C-language is an ANSI/ISO standard and powerful programming language for developing real time applications.


2  WHO DEVELOPED C LANGAUGE ?

C programming language was developed at Bell Laboratories in 1972 by Dennis Ritchie.


3  HISTORY OF C LANGAUGE ?

  • C programming language is a structural oriented programming language, was developed at Bell Laboratories in 1972 by Dennis Ritchie . c languages features were derived from earlier language called "B" (Basic combined Programming Language- BCPL). which was derived from ALGOL. Similarly, BCPL influenced development of programming language called B by Ken Thompson in 1970.
  • The history of C language goes back to 1960’s, when a number of computer languages were being used for various purposes. COBOL (Common Business-Oriented Language) was being used for commercial purposes, FORTRAN (Formula Translation) was being used for scientific and engineering applications and so on. 
  • Many of the ideas of structure of C language were taken from BCPL and B. Ritchie has given an excellent exposition of the problems experienced during development of C in his lecture entitled “The Development of the C Language”. Although  C  was  designed  for  implementing  system  software,  it  is  also  widely used  for  developing  portable  application  software.  

  • The earlier C was also called B with types though many ideas were also borrowed from ALGOL 68. A second phase of developments in C came in during the years 1977-1979. C became popular because of the success of UNIX system which was largely written in C and which could be used on different types of computers. C is a structured high-level language. Programs written in C are easy to write and debug as well as portable. The programs written in C are quite efficient. However, the code written in C language needs a compiler to convert different instructions and data into machine language.
  • In 1978, Dennis Ritchie and Brian Kernighan published the  first edition ,"The C Programming language" and commonly known as k& R C;
  • In 1983, the American National Standard Institute (ANSI) established a committee to provide a modern , comprehensive definition of C, The resulting definition , the ANSI standard , or ANSI C" was completed late 1988.
     
           

ALGOL 60

1960

International Committee

Too general, too abstract

CPL

1963

Cambridge University

Hard to learn, difficult to

implement

BCPL

1967

Martin Richards,

Cambridge University

Too specific

B

1970

Ken Thompson, Bell

Labs

Too specific

C

1972

Dennis Ritchie, Bell

Labs

Features of BCPL and B, not general, not specific, and most powerful





















C's compactness and coherence is mainly due to the fact that it is one-man language. Mainly C was developed to write the UNIX operating system.



Sunday, 8 August 2021

program to find transpose of the matrix in c-programming language | c-tutorial

Transpose of the matrix 

This C program is to find transpose of a matrix.

The new matrix obtained by interchanging the rows and columns of the original 
matrix is called as the transpose of the matrix. If A = [aij] be an m × n matrix,
 then the matrix obtained by interchanging the rows and columns of A would be the 
transpose of A. of It is denoted by A′or (AT).  

]

#include<stdio.h>
#include<conio.h>
void main()
{
    int a[3][3],i,j;
    printf("enter the value of the matrix:-");
    for(i=0;i<3;i++)
    {
        for(j=0;j<3;j++)
        {
            scanf("%d",&a[i][j]);
        }
    }
    printf("\n****************\n");
    for(i=0;i<3;i++)
    {
        for(j=0;j<3;j++)
        {
            printf("%3d",a[i][j]);
        }
        printf("\n");
    }
    printf("\n the transpose of the matrix is :-\n");
    for(i=0;i<3;i++)
    {
        for(j=0;j<3;j++)
        {
            printf("%3d",a[j][i]);
        }
        printf("\n");
    }
    getch();
}


output:-






Thursday, 29 July 2021

Bubble sort in c-language | c-programming

Bubble sort in c language.

Bubble Sort is the simplest sorting algorithm that works by repeatedly swapping the adjacent elements if they are in wrong order.
The bubble sort algorithm isn't efficient as its both average-case as well as worst-case complexity are O(n2).
Bubble sort is a beginners sorting program, it is most learned, but not most used widely due to its time complexity.

Bubble sort algorithm

Start at index zero, compare the element with the next one (a[0] & a[1] (a is the name of the array)), and swap if a[0] > a[1]. Now compare a[1] & a[2] and swap if a[1] > a[2]. Repeat this process until the end of the array. After doing this, the largest element is present at the end. 


#include<stdio.h>
#include<conio.h>
void  bubble_sort(int A[],int N);
void main()
{
    int A[]={44,64,34,2,54};
    int i;
    bubble_sort(A,5);
    for(i=0;i<5;i++)
    {
        printf("%d ",A[i]);
    }
    getch();
}
void bubble_sort(int A[],int N)
{
    int round,j,temp;
    for(round=1;round<=N-1;round++)
    {
        for(j=0;j<=N-1-round;j++)
        {
            if(A[j]>A[j+1])
            {
                temp=A[j];
                A[j]=A[j+1];
                A[j+1]=temp;
            }
        }
    }
}


output:-





For more c-programming .....


Monday, 14 June 2021

c-program to add two number by using pointer | call by reference | c-programming

program to add two number by pointer in c language

In this program we will now takes two number and add them by using call by reference (pointer)
 Call by Reference :- when address are passed to the called function.


#include<stdio.h>
#include<conio.h>
int add(int *,int *);
void main()
{
         int a,b,sum=0;
         printf("enter the number:-");
         scanf("%d %d",&a,&b);
         sum=add(&a,&b);
         printf("\n the sum of the two number is %d",sum);
         getch();
}
int add(int *x,int *y)
{
         int s;
         s=*x+*y;
         return(s);
}

output :- 


















Wednesday, 9 June 2021

c-program to find the reverse of the number by using function | c-programming

Program to find the reverse of the number 

In this program we will now  find the  reverser of the number by using function by taking the values from the user in c-programming.

#include<stdio.h>
#include<stdio.h>
int reverse(int);
void main()
{
         int a,num;
         printf("enter the number:-");
         scanf("%d",&a);
         num=reverse(a);
         printf("\n the reverse of the number is %d",num);
         getch();
}
int reverse(int n)
{
         int rev=0,i,x;
         while(n!=0){
                  x=n%10;
                  rev=rev*10+x;
                  n=n/10;
         }
         return(rev);
}

Output:-



For more c-programming















c-program to find the factorial of the number using function | c-programming languages

Program to find the factorial of the number

In this program we will now find the factorial of the number by taking input form the number using function in c-programming.
 factorial of 5 is = 1*2*3*4*5= 120






#include<stdio.h>
#include<conio.h>
int factorial(int);
void main()
{
         int x,fact;
         printf("enter the number:-");
         scanf("%d",&x);
         fact=factorial(x);
         printf("\n the factorial of the number is %d",fact);
         getch();
}
int factorial(int a)
{
         int f=1,i;
         for(i=1;i<=a;i++){
                  f=f*i;
         }
         return(f);
}

output:-