Showing posts with label Array. Show all posts
Showing posts with label Array. Show all posts

09 February 2022

Print Address of Three Dimensional Array

 // Print the address of three dimesional array in increasing order


// Print the address of three dimesional array in increasing order

#include<stdio.h>
 
int main()
{
    int arr[2][3][4];
    for(int i=0; i<2; i++){
        for(int j=0; j<3; j++){    //Here I'm using nasted for loop
            for(int k=0; k<4; k++){
                printf("The address of arr[%d][%d][%d] is : %u\n",
i,j,k, &arr[i][j][k]);
            }
        }
    }

return 0;
}


OUTPUT--->

The address of arr[0][0][0] is : 6422116 The address of arr[0][0][1] is : 6422120 The address of arr[0][0][2] is : 6422124 The address of arr[0][0][3] is : 6422128 The address of arr[0][1][0] is : 6422132 The address of arr[0][1][1] is : 6422136 The address of arr[0][1][2] is : 6422140 The address of arr[0][1][3] is : 6422144 The address of arr[0][2][0] is : 6422148 The address of arr[0][2][1] is : 6422152 The address of arr[0][2][2] is : 6422156 The address of arr[0][2][3] is : 6422160 The address of arr[1][0][0] is : 6422164 The address of arr[1][0][1] is : 6422168 The address of arr[1][0][2] is : 6422172 The address of arr[1][0][3] is : 6422176 The address of arr[1][1][0] is : 6422180 The address of arr[1][1][1] is : 6422184 The address of arr[1][1][2] is : 6422188 The address of arr[1][1][3] is : 6422192 The address of arr[1][2][0] is : 6422196 The address of arr[1][2][1] is : 6422200 The address of arr[1][2][2] is : 6422204 The address of arr[1][2][3] is : 6422208

Array Multiple Table Using Functions.

 


// Creat an array of size 3 X 10 containing multiple table of the
number 2, 7, and 9 respectively Using function.

#include<stdio.h>

int printTable(int *mulTable, int num, int n){

  printf("The multip;ication table of %d is--->\n ", num);
    printf("\n");

for(int i=0; i<n; i++){
    mulTable[i] = num * (i + 1);
  }
  for(int i=0; i<n; i++){
    printf("%d X %d = %d\n", num, i+1, mulTable[i]);
  }
}
int main()
{
    int mulTable[3][10];
    printTable(mulTable[0], 2, 10);

    printf("****************************************\n");
    printTable(mulTable[1], 7, 10);

    printf("****************************************\n");
    printTable(mulTable[2], 9, 10);

return 0;
}

OUTPUT--->

The multip;ication table of 2 is---> 2 X 1 = 2 2 X 2 = 4 2 X 3 = 6 2 X 4 = 8 2 X 5 = 10 2 X 6 = 12 2 X 7 = 14 2 X 8 = 16 2 X 9 = 18 2 X 10 = 20 ************************************************************* The multip;ication table of 7 is---> 7 X 1 = 7 7 X 2 = 14 7 X 3 = 21 7 X 4 = 28 7 X 5 = 35 7 X 6 = 42 7 X 7 = 49 7 X 8 = 56 7 X 9 = 63 7 X 10 = 70 ************************************************************* The multip;ication table of 9 is---> 9 X 1 = 9 9 X 2 = 18 9 X 3 = 27 9 X 4 = 36 9 X 5 = 45 9 X 6 = 54 9 X 7 = 63 9 X 8 = 72 9 X 9 = 81 9 X 10 = 90

Array Of Multiple Table



// Creat an array of size 3X10 containing multiple table of the
number 2, 7, and 9 respectively.

#include<stdio.h>
 
int main()
{
    int mulTable[3][10];
    for(int i=0; i<10; i++){
        mulTable[0][i] = 2 * (i+1);
    }

    for(int i=0; i<10; i++){
        printf("2 X %d = %d\n", (i+1), mulTable[0][i]);
    }
    printf("\n");

    for(int i=0; i<10; i++){
        mulTable[0][i] = 7 * (i+1);
    }

    for(int i=0; i<10; i++){
        printf("7 X %d = %d\n", (i+1), mulTable[0][i]);
    }
    printf("\n");

    for(int i=0; i<10; i++){
        mulTable[0][i] = 9 * (i+1);
    }

    for(int i=0; i<10; i++){
        printf("9 X %d = %d\n", (i+1), mulTable[0][i]);
    }
return 0;
}

OUTPUT-->

2 X 1 = 2 2 X 2 = 4 2 X 3 = 6 2 X 4 = 8 2 X 5 = 10 2 X 6 = 12 2 X 7 = 14 2 X 8 = 16 2 X 9 = 18 2 X 10 = 20 7 X 1 = 7 7 X 2 = 14 7 X 3 = 21 7 X 4 = 28 7 X 5 = 35 7 X 6 = 42 7 X 7 = 49 7 X 8 = 56 7 X 9 = 63 7 X 10 = 70 9 X 1 = 9 9 X 2 = 18 9 X 3 = 27 9 X 4 = 36 9 X 5 = 45 9 X 6 = 54 9 X 7 = 63 9 X 8 = 72 9 X 9 = 81 9 X 10 = 90



08 February 2022

Table Of Numers Using Array

 QUESTION:

Print Number Table By Taking User Input.

#include<stdio.h>
 
int main()
{
    int n;
    printf("Enter a Number");
    scanf("%d", &n);

    int mult[10];
    for(int i=0; i<10; i++){
        mult[i] = n * (i+1);  
    }
   
    printf("The table of the number that you have entered is :\n");

    for(int i=0; i<10; i++){
        printf("%d x %d = %d\n", n, (i+1), mult[i]);  
    }
 
return 0;
}

OUTPUT-->

Enter a Number: 11 The table of the number that you have entered is : 11 x 1 = 11 11 x 2 = 22 11 x 3 = 33 11 x 4 = 44 11 x 5 = 55 11 x 6 = 66 11 x 7 = 77 11 x 8 = 88 11 x 9 = 99 11 x 10 = 110

05 February 2022

Multiplication Table Using Array

 QUESTION : 

Write a program to create an array of 10 integers and store a multiplication table of 5.

#include<stdio.h>
 
int main()
{
    int mult[10];
    for(int i=0; i<10; i++){
        mult[i] = 5 * (i+1);  
    }
 
    for(int i=0; i<10; i++){
        printf("5 x %d = %d\n", (i+1), mult[i]);  
    }
return 0;
}

OUTPUT-->

5 x 1 = 5 5 x 2 = 10 5 x 3 = 15
5 x 4 = 20 5 x 5 = 25 5 x 6 = 30 5 x 7 = 35 5 x 8 = 40 5 x 9 = 45 5 x 10 = 50

Multidimensional Array

QUESTION:

Write a program which takes the marks of five students for three subjects and Displays them on the screen.

 #include<stdio.h> 

int main()
{
    int student = 3;
    int subject = 5;

    int marks[3][5];
    for(int i=0; i<student; i++){
        for(int j=0; j<student; j++){
            printf("Enter the marks of student %d for subject %d\n", i+1, j+1);
            scanf("%d", &marks[i][j]);
        }
    }

     for(int i=0; i<student; i++){
        for(int j=0; j<student; j++){
            printf("The marks of student %d for subject %d is : %d\n" , i+1, j+1, marks[i][j]);
        }
     }
return 0;
}

OUTPUT--->

Enter the marks of student 1 for subject 1 58 Enter the marks of student 1 for subject 2 95 Enter the marks of student 1 for subject 3 69 Enter the marks of student 2 for subject 1 98 Enter the marks of student 2 for subject 2 96 Enter the marks of student 2 for subject 3 86 Enter the marks of student 3 for subject 1 98 Enter the marks of student 3 for subject 2 98 Enter the marks of student 3 for subject 3 96
The marks of student 1 for subject 1 is : 58 The marks of student 1 for subject 2 is : 95 The marks of student 1 for subject 3 is : 69 The marks of student 2 for subject 1 is : 98 The marks of student 2 for subject 2 is : 96 The marks of student 2 for subject 3 is : 86 The marks of student 3 for subject 1 is : 98 The marks of student 3 for subject 2 is : 98 The marks of student 3 for subject 3 is : 96


02 February 2022

Arryas With Pointers

Arrays Input With the Help Of  Pointers --->

#include<stdio.h>
 
int main()
{
    int marks[4];
    int *ptr;
    ptr = &marks[0];

    for(int i=0; i<4; i++){
        printf("Enter the marks for student %d :\n", i+1);
        scanf("%d", ptr);
        ptr++;
    }

    for(int i=0; i<4; i++){
        printf("The marks of student %d is : %d\n", i+1, marks[i]);
           
    }
 
return 0;
}

OUTPUT--->

Enter the marks for student 1 : 98 Enter the marks for student 2 : 69 Enter the marks for student 3 : 89 Enter the marks for student 4 : 97
The marks of student 1 is : 98 The marks of student 2 is : 69 The marks of student 3 is : 89 The marks of student 4 is : 97



01 February 2022

Array Input Using Loops

QUESTION:

Write a program to accept the marks of five students in an Array and print them to the screen.

#include<stdio.h>
 
int main()
{
    int marks[5];

    for(int i=0; i<5; i++){
        printf("Enter the marks for student %d :", i+1);
        scanf("%d", &marks[i]);
    }
    for(int i=0; i<5; i++){
        printf("The value of marks for student %d is : %d\n", i+1, marks[i]);
    }
 
return 0;
}

OUTPUT--->

Enter the marks for student 1 :56 Enter the marks for student 2 :98 Enter the marks for student 3 :69 Enter the marks for student 4 :98 Enter the marks for student 5 :99
The value of marks for student 1 is : 56 The value of marks for student 2 is : 98 The value of marks for student 3 is : 69 The value of marks for student 5 is : 99