practical 1
practical 1
#include<stdio.h>
int main()
int i,t,a[10],n,m,s,j=0,b[10];
scanf("%d",&n);
for(i=0;i<n;i++)
scanf("%d",&a[i]);
for(i=0;i<n;i++)
printf("\na[%d]=%d",i,a[i]);
scanf("%d",&t);
scanf("%d",&s);
for(i=0;i<n;i++)
if(i==t)
a[i]=s;
for(i=0;i<n;i++)
{
printf("\na[%d]=%d",i,a[i]);
return 0;
}
Increase The Size Of An Array In C
#include<stdio.h>
#include<stdlib.h>
int main(){
int *p;
int *q;
p = (int *)malloc(5*sizeof(int));
p[0]=1;
p[1]=3;
p[2]=5;
p[3]=7;
p[4]=9;
printf("Array p: \n");
for(int i=0;i<5;i++){
printf("%d \n",p[i]);
q=(int *)malloc(7*sizeof(int));
for(int i=0;i<5;i++){
q[i]=p[i];//assigning elements of p to q
for(int i=0;i<7;i++){
printf("%d \n",p[i]);
return 0;
int main ()
int arr[5]={34,65,78,23,52};
int i;
int *pr;
pr=&arr[i];
pr++;
return 0;
Subarray/Substring
A subarray is a contiguous part of the array. An array that is inside another array. For example, consider
the array [1, 2, 3, 4], There are 10 non-empty sub-arrays. The subarrays are (1), (2), (3), (4), (1,2), (2,3),
(3,4), (1,2,3), (2,3,4) and (1,2,3,4). In general, for an array/string of size n, there are n*(n+1)/2 non-
empty subarrays/substrings.
• A subarray must be contiguous, meaning there can't be any gaps between its elements.
• You can access elements of a subarray using the same indexing as the original array.
• You can often iterate over subarrays using loops, adjusting the starting and ending indices to
define the desired subarray.
Write a c program on 2D array to Increase & Decrease No of subarrays
#include <stdio.h>
#include <stdlib.h>
printf("\n");
printf("\n");
int main() {
int value = 1;
array[i][j] = value++;
}
}
int newRows = 5;
rows = newRows;
newRows = 2;
rows = newRows;
free(array[i]);
free(array);
return 0;
}
Write a c program on 2D array to Increase & Decrease elements in the subarrays
#include <stdio.h>
#define ROWS 3
#define COLS 4
printf("\n");
printf("\n");
void modifySubarray(int arr[ROWS][COLS], int startRow, int endRow, int startCol, int endCol, int
value) {
int main() {
int array[ROWS][COLS] = {
{1, 2, 3, 4},
{5, 6, 7, 8},
};
printf("Original Array:\n");
printArray(array);
modifySubarray(array, 0, 1, 1, 2, 5);
printArray(array);
modifySubarray(array, 1, 2, 2, 3, -3);
printArray(array);
return 0;