A Developer Gateway To IT World...

### Array: 1D and 2D with pattern in C programming

Array: 1D and 2D with pattern in C programming

# Array: 1D and 2D with pattern

## PROGRAM 1::-

```
```

#include
#include
void main()
{
//for single values store
int a=20;
//multiple values to store
int b[5]={10,20,30,40,50};
printf("%d\n",b[0]);
printf("%d\n",b[1]);
printf("%d\n",b[2]);
printf("%d\n",b[3]);
printf("%d\n",b[4]);
getch();
}

```
```

## Program 2 of static 1D-array:-

```
```

#include
#include
void main()
{
//for single values store
int a=20;
//multiple values to store
int b[5]={10,20,30,40,50};
int i;
//loop starts from index o to n-1
for(i=0; i<=4; i++)
{
printf("%d\n",b[i]);
}
getch();
}

```
```

## Program 3 of static 1D-array:-

```
```

#include
#include
void main()
{
//multiple values to store
int b[5]={10,20,30,40,50};
int i;
//loop starts from index 1 to n
for(i=1; i<=5; i++)
{
printf("%d\n",b[i]);
}
getch();
}

```
```

## Program 4: Dynamic 1D-array:-

```
```

#include
#include
void main()
{
//multiple values to store
int b[5];
int i;
//loop starts from index 0 to n-1
printf("Enter five element in array: ");
for(i=0; i<=4; i++)
{
scanf("%d",&b[i]);
}
//loop starts from index 0 to n-1
for(i=0; i<=4; i++)
{
printf("%d\n",b[i]);
}
getch();
}

```
```

## Program 5:-

```
```

#include
void main()
{
int m[5]={1,2,3,4,5};
//test 1 to n-1
int i, n=5;
//should for(i=0;i<=n-1;i++) but
for(i=1;i<=n-1;i++)
{
printf("%d",m[i]);
}
getch();
}

```
```

# Static 2D-array with pattern example

## Program 6:static 2D-array:-

```
```

#include
#include
void main()
{
int i,j;
//pattern in 2D array
/*
*

**

***

****

*****
*/
for(i=0; i<=4; i++)
{
for(j=0; j<=i; j++)
{
printf("*");
}
printf("\n");
}
getch();
}

```
```

# Static 2D-array without pattern

## Program 6:static 2D-array:-

```
```

#include
#include
void main()
{
//int b[3]={1,2,3};
//multiple array to store in an array
int b[3][3]={{4,2,4},{2,2,1},{5,2,3}};
int i,j;
//loop starts from index 0 to n-1
for(i=0; i<=2; i++)
{
for(j=0; j<=2; j++)
{
printf("%d",b[i][j]);
}
printf("\n");
}
getch();
}

```
```

# Static 2D-array without pattern example 2

## Program:static 2D-array:-

```
```

#include
#include
void main()
{
//int b[3]={1,2,3};
//multiple array to store in an array
int b[3][3];
int i,j;
printf("Enter nine values in array: ");
for(i=0; i<=2; i++)
{
for(j=0; j<=2; j++)
{
scanf("%d",&b[i][j]);
}
printf("\n");
}
printf("Array elements are: ");
//loop starts from index 0 to n-1
for(i=0; i<=2; i++)
{
for(j=0; j<=2; j++)
{
printf("%d",b[i][j]);
}
printf("\n");
}
getch();
}

```
```