to make function

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • PINKA
    New Member
    • Oct 2006
    • 7

    to make function

    can any one make two different function that can be call in main for code which is writed in bold


    #include<conio. h>
    #include<stdio. h>
    void main()
    {
    int c[100][100], a[100][100], b[100][100];
    int m,n,o,p,i,j,k,r ,t;
    printf("\n Enter the no. of rows and columns of matrix: \n");
    scanf(" %d %d",&m,&n);
    printf("\nEnter the matrix elements: \n");
    for(i=0;i<m;i++ )
    {
    for(j=0;j<n;j++ )
    scanf("%d",&a[i][j]);
    }
    printf("Enter the no of rows and columns of Another matrix : ");
    scanf("%d%d",&o ,&p);

    printf("Enter the second matrix elements : \n");
    for(i=0;i<o;i++ )
    {
    for(j=0;j<p;j++ )
    scanf("%d",&b[i][j]);
    }

    printf("\nThe matrix you entered is : \n");
    for(i=0;i<o;i++ )
    {
    for(j=0;j<p;j++ )
    printf(" %d \t",b[i][j]);
    printf("\n");
    }

    printf("\n\t ADDITION of MATRIX you entered\n");

    if(m>o)
    {
    r=m;
    for(i=o;i<m;i++ )
    {
    for(j=0;j<p;j++ )
    {
    b[i][j]=0;
    }
    }
    }
    else if(m<=o)
    {
    r=o;
    for(i=m;i<o;i++ )
    {
    for(j=0;j<n;j++ )
    a[i][j]=0;

    }
    }
    if(n>p)
    {
    t=n;
    for(i=0;i<o;i++ )
    {
    for(j=p;j<n;j++ )
    b[i][j]=0;
    }
    }
    else if(n<=p)
    {
    t=p;
    for(i=0;i<m;i++ )
    {
    for(j=n;j<p;j++ )
    a[i][j]=0;
    }
    }
    for(i=0;i<r;i++ )
    {
    for(j=0;j<t;j++ )
    c[i][j]=0;

    }

    for(i=0;i<r;i++ )
    {
    for(j=0;j<t;j++ )
    c[i][j]=a[i][j]+b[i][j];
    }
    for(i=0;i<r;i++ )
    {
    for(j=0;j<t;j++ )
    printf(" %d \t",c[i][j]);
    printf("\n");
    }
    getch();
    }
  • PINKA
    New Member
    • Oct 2006
    • 7

    #2
    yaar koi to help karo plz
    Originally posted by PINKA
    can any one make two different function that can be call in main for code which is writed in bold


    #include<conio. h>
    #include<stdio. h>
    void main()
    {
    int c[100][100], a[100][100], b[100][100];
    int m,n,o,p,i,j,k,r ,t;
    printf("\n Enter the no. of rows and columns of matrix: \n");
    scanf(" %d %d",&m,&n);
    printf("\nEnter the matrix elements: \n");
    for(i=0;i<m;i++ )
    {
    for(j=0;j<n;j++ )
    scanf("%d",&a[i][j]);
    }
    printf("Enter the no of rows and columns of Another matrix : ");
    scanf("%d%d",&o ,&p);

    printf("Enter the second matrix elements : \n");
    for(i=0;i<o;i++ )
    {
    for(j=0;j<p;j++ )
    scanf("%d",&b[i][j]);
    }

    printf("\nThe matrix you entered is : \n");
    for(i=0;i<o;i++ )
    {
    for(j=0;j<p;j++ )
    printf(" %d \t",b[i][j]);
    printf("\n");
    }

    printf("\n\t ADDITION of MATRIX you entered\n");

    if(m>o)
    {
    r=m;
    for(i=o;i<m;i++ )
    {
    for(j=0;j<p;j++ )
    {
    b[i][j]=0;
    }
    }
    }
    else if(m<=o)
    {
    r=o;
    for(i=m;i<o;i++ )
    {
    for(j=0;j<n;j++ )
    a[i][j]=0;

    }
    }
    if(n>p)
    {
    t=n;
    for(i=0;i<o;i++ )
    {
    for(j=p;j<n;j++ )
    b[i][j]=0;
    }
    }
    else if(n<=p)
    {
    t=p;
    for(i=0;i<m;i++ )
    {
    for(j=n;j<p;j++ )
    a[i][j]=0;
    }
    }
    for(i=0;i<r;i++ )
    {
    for(j=0;j<t;j++ )
    c[i][j]=0;

    }

    for(i=0;i<r;i++ )
    {
    for(j=0;j<t;j++ )
    c[i][j]=a[i][j]+b[i][j];
    }
    for(i=0;i<r;i++ )
    {
    for(j=0;j<t;j++ )
    printf(" %d \t",c[i][j]);
    printf("\n");
    }
    getch();
    }

    Comment

    • vermarajeev
      New Member
      • Aug 2006
      • 180

      #3
      What is that you are trying to tell??Please be clear about what to want to change in your code...

      Thankx

      Comment

      Working...