+ Reply to Thread
Results 1 to 5 of 5

Thread: C Program

  1. #1
    sumitmehta is offline x10 Sophmore sumitmehta is an unknown quantity at this point
    Join Date
    Oct 2005
    Posts
    106

    C Program

    Hye Guys

    I developed some useful and very basic C programs. I would like to share them with you. Here I am posting the first program. Pls let me know if I continue. These programs won't make much sense for experienced C programmers but they will be very useful for the beginners and intermediate programmers in C.

    Pls. do rep me if you like my work.

    Thanks.

    Here is the first program on how to add two matrices using pointers.
    Code:
    include<stdio.h>
    
    struct node {
    
        int row;
        int col;
        int data;
        struct node *next;
    };
    typedef struct node* NODE;
    
    void add(NODE*,int,int,int);
    NODE getMatrix(int,int);
    NODE addMatrices(NODE*,NODE*);
    void display(NODE*,int);
    
    void add(NODE *n,int r,int c,int v) {
    
        NODE temp=*n,t=*n;
        NODE newN=(struct node *)malloc(sizeof(struct node));
        newN->data=v;
        newN->row=r;
        newN->col=c;
        newN->next=NULL;
    
        if(temp==NULL)
            temp=newN;
        else {
    
            while(t->next!=NULL)
                t=t->next;
            t->next=newN;
        }
        *n=temp;
    }
    NODE getMatrix(int r,int c) {
    
        int i,j;
        int data;
        NODE m=NULL;
    
        for(i=0;i<r;i++) {
    
            for(j=0;j<c;j++) {
    
                printf("\nEnter element for row %d & column %d : ",i+1,j+1);
                scanf("%d",&data);
                add(&m,i+1,j+1,data);
            }
        }
        return m;
    }
    NODE addMatrices(NODE *m1,NODE *m2) {
    
        NODE temp1=*m1;
        NODE temp2=*m2;
        NODE r=NULL;
        int data;
    
        while(temp1!=NULL)  {
    
            data=temp1->data + temp2->data;
            add(&r,temp1->row,temp1->col,data);
            temp1=temp1->next;
            temp2=temp2->next;
        }
        return r;
    }
    void display(NODE *matrix,int c) {
    
        NODE m=*matrix;
    
        printf("\n");
    
        while(m!=NULL) {
    
            printf("%d\t",m->data);
    
            if(m->col==c)
                printf("\n");
            m=m->next;
        }
    }
    void main() {
    
        int r,c;
        NODE m1=NULL,m2=NULL,m3=NULL;
    
        clrscr();
    
        printf("Enter number of total rows for both matrices: ");
        scanf("%d",&r);
    
        printf("Enter number of total columns for noth matrices: ");
        scanf("%d",&c);
    
        printf("\nDetails for Matrix 1: ");
        m1=getMatrix(r,c);
    
        printf("\nDetails for Matrix 2: ");
        m2=getMatrix(r,c);
    
        m3=addMatrices(&m1,&m2);
    
        printf("Matrix 1: ");
        display(&m1,c);
    
        printf("Matrix 2: ");
        display(&m2,c);
    
        printf("Resultant Matrix: ");
        display(&m3,c);
    
        getch();
    }
    Last edited by kajasweb; 03-02-2008 at 08:59 PM. Reason: Formatted

  2. #2
    sunils's Avatar
    sunils is offline x10 Spammer sunils is an unknown quantity at this point
    Join Date
    Jan 2008
    Location
    Chennai ,India
    Posts
    2,264

    Re: C Program

    nice job buddy carry on
    [LEFT][B]Sunil Sankar
    -------------------------------------------------------------------------

  3. #3
    sumitmehta is offline x10 Sophmore sumitmehta is an unknown quantity at this point
    Join Date
    Oct 2005
    Posts
    106

    Re: C Program

    Thanks for the encouragement. I am starting a new thread as 'Collection of C programs' because the name of this thread doesn't suit as I named it having in mind that I will post only one or two programs. But now I will make a dedicated thread for this category.

    Thanks.

  4. #4
    kajasweb's Avatar
    kajasweb is offline Lord Of The Keys kajasweb is an unknown quantity at this point
    Join Date
    Aug 2007
    Location
    Chennai, India
    Posts
    1,722

    Re: C Program

    Please use the BBCode (CODE) - () to format your programs. It'll give your programs, easy readability.
    R. Kaja Mohideen
    Start Your Own Blog... Start Making Money...
    http://www.MyiStop.com/
    CuteCom.Net - Low Cost International Internet Telephony (VoIP) Service

  5. #5
    sumitmehta is offline x10 Sophmore sumitmehta is an unknown quantity at this point
    Join Date
    Oct 2005
    Posts
    106

    Re: C Program

    I don't know how to use that but probably that must be some tag. I will find it and use it. Thanks.

+ Reply to Thread

Similar Threads

  1. What is the best FTP program?
    By Mitch in forum Computers & Technology
    Replies: 34
    Last Post: 03-10-2008, 12:41 AM
  2. Replies: 1
    Last Post: 10-21-2007, 12:42 AM
  3. ftp program config...
    By ymca in forum Free Hosting
    Replies: 3
    Last Post: 12-13-2005, 01:52 PM
  4. Want a program made for you?
    By dsfreak in forum Off Topic
    Replies: 25
    Last Post: 05-26-2005, 06:52 PM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
x10hosting free hosting for the masses
dedicated servers