Friday, September 23, 2011

Mini project “Calendar Application” Using C/C++ – Free download.

Mini project “Calendar Application” is also a simple project made using C. It uses many windows properties to make it colorful, for example, to indicate the vacation, it uses the red foreground color.The calendar can be used for two purposes. First to  see the date and month as usual calendars and second to find out the day corresponding to given date. Some of the silent features of the project are
  • It uses various windows properties to make the program colorful although it has lack of graphics
  • It entirely uses C codes, code is written in simple manner with lots of comments
  • Important notes can be added. The date with such notes appears different than others with red background color.
  • The months can be navigated using arrows key
Some of the screen shots of the program are:
Enter date (DD MM YYYY) : 10 03 1991 Day is : Sunday Press any key to continue......

Calendar1
Calendar2

DOWNLOAD CALENDAR APPLICATION 

Thursday, September 22, 2011

Mini project “Library management system” using C/C++ – Free download

Mini project Library management system is simple project on C made using file handling. Database of the project is simple C files. This project is very useful for those who are stepping in creating a project using C. Especially the whole project is based on file handling. Adding record, view saved record, modify record and deleting record are core part of the project. Besides the program is password protected. So to change the content of the project you need password.

Tuesday, September 20, 2011

Mini project “Quiz (Who will be the millionaire)” Using C/C++ – Free download

Mini project “Quiz” is a simple project made using C. It is most useful for those who are new to C and don’t know how to start to make a mini project on C. The source code of the project is divided in many header files so as to make it more manageable. The whole project is divided into two parts: administrator mode and player mode. The questions can be added, modified or deleted via administrator mode and one can play the Quiz game via player mode. Although no graphics is included, the project uses some functions of windows.h to make it colorful. Some screen shots of the project are given below:
Quiz1
Quiz2
To download the project with source code and executable file Click Here. If you have any problem regarding this project, you can mail me : subedishankar2011@gmail.com.

Sunday, September 18, 2011

Numerical Methods: Condition number and ill condition checking using C

Source Code:

#include<stdio.h>
#include<math.h>
void inverse(float matrix[6][6], int n){
    int i,j, k;
    float ratio,a;
    for(i = 0; i < n; i++){
        for(j = n; j < 2*n; j++){
            if(i==(j-n))
                matrix[i][j] = 1.0;
            else
                matrix[i][j] = 0.0;
        }
    }
    for(i = 0; i < n; i++){
        for(j = 0; j < n; j++){
            if(i!=j){
                ratio = matrix[j][i]/matrix[i][i];
                for(k = 0; k < 2*n; k++){
                    matrix[j][k] -= ratio * matrix[i][k];
                }
            }
        }
    }
    for(i = 0; i < n; i++){
        a = matrix[i][i];
        for(j = 0; j < 2*n; j++){
            matrix[i][j] /= a;
        }
    }
    for(i = 0; i < n; i++){
        for(j = n; j < 2*n; j++){
            matrix[i][j-n] = matrix[i][j];
        }
    }
}
float norms(float matrix[][6],int n){
    int i,j;
    float sum = 0;
    for(i = 0; i < n; i++){
        for(j = 0; j < n; j++){
            sum += pow(matrix[i][j], 2);
        }
    }
    return sqrt(sum);
}
int main(){
    float matrix[6][6], cond_no, norm1, norm2, det;
    int i,j,n;
    printf("Enter order of matrix: ");
    scanf("%d",&n);
    printf("Enter the matrix: \n");
    for(i = 0; i < n; i++){
        for(j = 0; j < n; j++){
            scanf("%f",&matrix[i][j]);
        }
    }
    norm1 = norms(matrix,n);
    inverse(matrix,n);
    norm2 = norms(matrix,n);
    cond_no = norm1*norm2;
    printf("\nCondition No: %.2f\n", cond_no);
    return 0;
}

Numerical Methods: Greatest Eigen value and corresponding Eigen vector using power method in C

Source Code:

#include<stdio.h>
#include<math.h>
#include<stdlib.h>
void matrix_mul(float matrix1[3][3],float matrix2[3][1],float matrix3[3][1]){
    int i,j,k;
    for(i = 0; i < 3; i++){
        for(j = 0; j < 1; j++){
            matrix3[i][j] = 0;
            for(k = 0; k < 3; k++){
                matrix3[i][j] += matrix1[i][k]*matrix2[k][j];
            }
        }
    }
}
float findmax(float array[3][1]){
    int i;
    float  maximum;
    maximum = array[0][0];
    for(i = 0; i < 3; i++){
        if(maximum < array[i][0])
            maximum = array[i][0];
    }
    return maximum;
}
int isEqual(float matrix1[3][1], float matrix2[3][1]){
    if(matrix1[0][0] == matrix2[0][0]
    && matrix1[1][0] == matrix2[1][0]
    && matrix1[2][0] == matrix2[2][0])
        return 1;
    return 0;
}
int main(){
    float matrix1[3][3], matrix2[3][1],result[3][1];
    float eigenValue;
    int i,j,k;
    printf("Enter 3x3 matrix:\n");
    for(i = 0; i < 3; i++){
        for(j = 0; j < 3; j++){
            scanf("%f",&matrix1[i][j]);
        }
    }
    for(i = 0; i < 3; i++){
        for(j = 0; j < 1; j++){
            matrix2[i][j] = 1.0;
        }
    }
    while(1){
        matrix_mul(matrix1,matrix2,result);
        eigenValue = findmax(result);
        for(i = 0; i < 3; i++){
            result[i][0]/=eigenValue;
        }
        if(isEqual(matrix2,result)==1){
            break;
        }
        for(i = 0; i < 3; i++){
            matrix2[i][0] = result[i][0];
        }
    }
    printf("Greatest Eigen Value = %f", eigenValue);
    printf("\nAny one of Eigen Vector: \n");
    for(i = 0; i < 3; i++){
        for(j = 0; j < 1; j++){
            printf("%.2f",result[i][j]);
            printf("\t");
        }
        printf("\n");
    }
    return 0;
}

Numerical Methods: Integration of given function using Simpson’s 1/3 rule in C

Source Code:

///integration of given function using Simpson's 1/3 rule
#include<stdio.h>
float y(float x){
    return 1/(1+x*x);
}
int main(){
    float x0,xn,h,s;
    int i,n;
    printf("Enter x0, xn, no. of subintervals: ");
    scanf("%f%f%d",&x0,&xn,&n);
    h = (xn - x0)/n;
    s = y(x0)+y(xn)+4*y(x0+h);
    for(i = 3; i<=n-1; i+=2){
        s += 4*y(x0+i*h) + 2*y(x0+(i-1)*h);
    }
    printf("Value of integral is %6.4f\n",(h/3)*s);
    return 0;
}

Numerical Methods: Integration of given function using Simpson’s 3/8 rule in C

Source Code:

//integration of given function using Simpson's 3/8 rule
#include<stdio.h>
float y(float x){
    return 1/(1+x*x); //function of which integration is to be calculated
}
int main(){
    float x0,xn,h,s;
    int i,n,j,flag;
    printf("Enter x0, xn, no. of subintervals: ");
    scanf("%f%f%d",&x0,&xn,&n);
    h = (xn-x0)/n;
    s = y(x0)+y(xn);
    for(i = 1; i<=n-1;i++){
        for(j=1;j<=n-1;j++){
            if(i==3*j){
                flag = 1;
                break;
            }
            else
                flag = 0;
        }
        if(flag==0)
            s += 3*y(x0+i*h);
        else
            s += 2*y(x0+i*h);
    }
    printf("Value of integral is %6.4f\n",(3*h/8)*s);
    return 0;
}

Numerical Methods: Integration of given function using Trapezoidal rule in C

Source Code:

///integration of given function using Trapezoidal rule
#include<stdio.h>
float y(float x){
    return 1/(1+x*x);
}
int main(){
    float x0,xn,h,s;
    int i,n;
    printf("Enter x0, xn, no. of subintervals: ");
    scanf("%f%f%d",&x0,&xn,&n);
    h = (xn-x0)/n;
    s = y(x0) + y(xn);
    for(i = 1; i < n; i++){
        s += 2*y(x0+i*h);
    }
    printf("Value of integral is %6.4f\n",(h/2)*s);
    return 0;
}

Numerical Methods: Parabolic curve fitting using C

Source Code:

#include<stdio.h>
#include<math.h>
int main(){
    float xy[20][20], matrix[3][4], ratio, a;
    float sum_x = 0, sum_y = 0, sum_x2 = 0, sum_x3 = 0, sum_x4 = 0, sum_xy = 0, sum_x2y = 0;
    int i, j , k, n;
    printf("Enter no of data: ");
    scanf("%d", &n);
    printf("Enter the data: \n");
    for(i = 0; i < 2; i++){
        for(j = 0; j < n; j++){
            scanf("%f", &xy[i][j]);
        }
    }
    for(i = 0; i < n; i++){
        sum_x += xy[0][i];
        sum_y += xy[1][i];
        sum_x2 += pow(xy[0][i], 2);
        sum_x3 += pow(xy[0][i], 3);
        sum_x4 += pow(xy[0][i], 4);
        sum_xy += xy[0][i]*xy[1][i];
        sum_x2y += pow(xy[0][i], 2) * xy[1][i];
    }
    matrix[0][0] = n;
    matrix[0][1] = sum_x;
    matrix[0][2] = sum_x2;
    matrix[0][3] = sum_y;
    matrix[1][0] = sum_x;
    matrix[1][1] = sum_x2;
    matrix[1][2] = sum_x3;
    matrix[1][3] = sum_xy;
    matrix[2][0] = sum_x2;
    matrix[2][1] = sum_x3;
    matrix[2][2] = sum_x4;
    matrix[2][3] = sum_x2y;
    for(i = 0; i < 3; i++){
        for(j = 0; j < 3; j++){
            if(i!=j){
                ratio = matrix[j][i]/matrix[i][i];
                for(k = 0; k < 4; k++){
                    matrix[j][k] -= ratio * matrix[i][k];
                }
            }
        }
    }
    for(i = 0; i < 3; i++){
        a = matrix[i][i];
        for(j = 0; j < 4; j++){
            matrix[i][j] /= a;
        }
    }
    for(i = 0; i < 3; i++){
        printf("\n%c => %.2f", 97+i, matrix[i][3]);
    }
}

Numerical Methods: Inverse of nxn matrix using C

Source Code:

#include<stdio.h>
int main(){
    float matrix[10][10], ratio,a;
    int i, j, k, n;
    printf("Enter order of matrix: ");
    scanf("%d", &n);
    printf("Enter the matrix: \n");
    for(i = 0; i < n; i++){
        for(j = 0; j < n; j++){
            scanf("%f", &matrix[i][j]);
        }
    }
    for(i = 0; i < n; i++){
        for(j = n; j < 2*n; j++){
            if(i==(j-n))
                matrix[i][j] = 1.0;
            else
                matrix[i][j] = 0.0;
        }
    }
    for(i = 0; i < n; i++){
        for(j = 0; j < n; j++){
            if(i!=j){
                ratio = matrix[j][i]/matrix[i][i];
                for(k = 0; k < 2*n; k++){
                    matrix[j][k] -= ratio * matrix[i][k];
                }
            }
        }
    }
    for(i = 0; i < n; i++){
        a = matrix[i][i];
        for(j = 0; j < 2*n; j++){
            matrix[i][j] /= a;
        }
    }
    printf("The inverse matrix is: \n");
    for(i = 0; i < n; i++){
        for(j = n; j < 2*n; j++){
            printf("%.2f", matrix[i][j]);
            printf("\t");
        }
        printf("\n");
    }
    return 0;
}

Numerical Methods: Determinant of nxn matrix using C

Source Code:

#include<stdio.h>
int main(){
    float  matrix[10][10], ratio, det;
    int i, j, k, n;
    printf("Enter order of matrix: ");
    scanf("%d", &n);
    printf("Enter the matrix: \n");
    for(i = 0; i < n; i++){
        for(j = 0; j < n; j++){
            scanf("%f", &matrix[i][j]);
        }
    }
    /* Conversion of matrix to upper triangular */
    for(i = 0; i < n; i++){
        for(j = 0; j < n; j++){
            if(j>i){
                ratio = matrix[j][i]/matrix[i][i];
                for(k = 0; k < n; k++){
                    matrix[j][k] -= ratio * matrix[i][k];
                }
            }
        }
    }
    det = 1; //storage for determinant
    for(i = 0; i < n; i++)
        det *= matrix[i][i];
    printf("The determinant of matrix is: %.2f\n\n", det);
    return 0;
}

Numerical Methods: Solution of simultaneous algebraic equations using Gauss Jordan method in C

Source Code:

/*****************************************************
    Program: solution of linear algebraic equations
    using Gauss Jordan Method
    Language used: C
    Program written by Bibek Subedi
    July 2, 2011
    Tribhuvan University
*****************************************************/
#include<stdio.h>
int main()
{
    double matrix[10][10],a,b;
    int  i, j, k, n;
    printf("Enter the no of variables: ");
    scanf("%d", &n);
    printf("Enter the agumented matrix:\n");
    for(i = 0; i < n ; i++){
        for(j = 0; j < (n+1); j++){
            scanf("%lf", &matrix[i][j]);
        }
    }
    for(i = 0; i < n; i++){
       for(j = 0; j < n; j++){
            if(i != j){
                a = matrix[j][i];
                b = matrix[i][i];
                for(k = 0; k < n+1; k++){
                    matrix[j][k] = matrix[j][k] - (a/b) * matrix[i][k];
                }
            }
        }
    }
    for(i = 0; i < n; i++){
         a = matrix[i][i];
        for(j = 0; j < n+1; j++){
            matrix[i][j] /= a;
        }
    }
    printf("The required solution is: \n\n");
    for(i = 0; i < n ; i++){
        printf("%c => %.2f", i+97, matrix[i][n]);
        printf("\n");
    }
    return 0;
}

Numerical Methods: Solution of simultaneous algebraic equations using Gauss Elimination method in C

Source Code:

/*****************************************************
    Program: Solution of Linear algebraic equations
    using Gauss Elimination method
    Language used: C
    Program written by Bibek Subedi
*****************************************************/
#include<stdio.h>
int main()
{
    double matrix[10][10],a,b, temp[10];
    int  i, j, k, n;
    printf("Enter the no of variables: ");
    scanf("%d", &n);
    printf("Enter the agumented matrix:\n");
    for(i = 0; i < n ; i++){
        for(j = 0; j < (n+1); j++){
            scanf("%lf", &matrix[i][j]);
        }
    }
    for(i = 0; i < n; i++){
       for(j = 0; j < n; j++){
           if(j>i){
                a = matrix[j][i];
                b = matrix[i][i];
                for(k = 0; k < n+1; k++){
                    matrix[j][k] = matrix[j][k] - (a/b) * matrix[i][k];
                }
            }
       }
    }
    printf("The Upper triangular matrix is: \n");
    for( i = 0; i < n; i++){
        for(j = 0; j < n+1; j++){
            printf("%.2f", matrix[i][j]);
            printf("\t");
        }
        printf("\n");
    }
    printf("\nThe required result is: ");
    for(i = n-1; i>=0; i--){
        b = matrix[i][n];
        for(j = n-1 ; j > i; j--){
            b -= temp[n-j]*matrix[i][j];
        }
        temp[n-i] = b/matrix[i][i];
        printf("\n%c => %.2f",97+i, temp[n-i]);
    }
}