Showing posts with label Array. Show all posts
Showing posts with label Array. Show all posts
Hello Here is a C program for matrix multiplication of  size 3*3. This is the easiest process. From this code concept you can make multiplication of any size of matrix too. Just need to add some tmp locations.

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
#include <stdio.h>
#include <stdlib.h>
//Program for Multiplication of matrix 3*3 Time and Update
int main()
{
    int a[3][3],b[3][3],c[3][3];
    int i,j,k,tmp1=0,tmp2=0,tmp3=0;
    printf("Enter value of matrix A \n");
    for(i=0;i<3;i++)
    {
        for(j=0;j<3;j++)
            scanf("%d",&a[i][j]);
        printf("\n");
    }
    printf("Enter value of matrix B \n");
    for(i=0;i<3;i++)
    {
        for(j=0;j<3;j++)
            scanf("%d",&b[i][j]);
        printf("\n");
    }
    for(i=0;i<3;i++)
    {
        for(j=0;j<3;j++)
        {
            tmp1=a[i][j]*b[j][0]+tmp1;
            tmp2=a[i][j]*b[j][1]+tmp2;
            tmp3=a[i][j]*b[j][2]+tmp3;
        }
        c[i][0]=tmp1;
        c[i][1]=tmp2;
        c[i][2]=tmp3;

    }
    printf("https://timeandupdate.com \n");
    printf("The Multiplication is :-\n");
    for(i=0;i<3;i++)
    {
        for(j=0;j<3;j++)
            printf("%d\t",c[i][j]);
        printf("\n");
    }
    return 0;
}

Here is the Output:
I did not check all but looks its correct.


The above program is compiled and successfully run on Code::Block 13.12.
This is easy program but you just need to focus. If you cant understand how this program flow don't forget to comment we will be back to help you.
Hello Here is A c program to arrange numerical data in array in ascending order (1 3 8..). Input N numbers means you need to ask users how much numbers to be inserted. Here we are using max 10 Numbers if you need more you can from Changing the value a[10]. what ever you need. And you should change it in Called function too.

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
#include<stdio.h>
#include<conio.h>
void asce(int[],int);
void main()
 {
    int a[10],n,i;
      printf("Enter total no of array to be inserted in array:- ");
      scanf("%d",&n);
      printf("Enter value to be inserted in array");
      for(i=0;i<n;i++)
         scanf("%d",&a[i]);
      asce(a,n);
      printf("After arrranging in ascending order:- \n");
      for(i=0;i<n;i++)
         printf("%d\t",a[i]);
      getche();
   }
void asce(int a[10],int y)
 {
    int i,j,tmp;
      for (i=0;i<y;i++)
      {
       for(j=0;j<y-1;j++)
          {
             if(a[j]>a[j+1])
                {
                   tmp=a[j+1];
                   a[j+1]=a[j];
                   a[j]=tmp;
                  }
            }
      }
   }

The main concept is the nested for loop. There are 100s ways to perform a program. The return type of called function is void as value is passed by reference.
The Question is Read 10 numbers in array and print Reverse Order. To Print in Reverse Order we can run the loop from highest point with decrements But thee we Reverse the Array. Lets begun.
Codes Goes Here
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
#include<stdio.h>
#include<conio.h>
main()
 {
  int a[10],i,n,tmp;
  printf("How many Values you want to insert in the array\?");
  scanf("%d",&n);
  printf("Enter the values in the array");
  for(i=0;i<n;i++)
   scanf("%d".&a[i]);
  for(i=0;i<n/2;i++)
   {
    tmp=a[i];
    a[i]=a[n-i];
    a[n-i]=tmp;
   }
  printf("Now The Reverse is:- \n);
  for(i=;i<n;i++)
   printf("%d \t",i);
  getche();
 }

for(i=0;i<n/2;i++)
Here this Loop Swap the values. So we need to run the program for just half time of total values in Array. If the loops runs for n times it will swap values back. As we define n as int. so n/2 will always be int. If you need more explanation don't forget to ask through comment.