-->
Showing posts with label Array programs in C. Show all posts
Showing posts with label Array programs in C. Show all posts

Wednesday, June 4, 2025

c program to concatenate two strings | 2D strings examples in c | program without strcat()

Array and string programs in C

 // program to concatenate two strings without using strcat()

#include<stdio.h>

int main()

{

char string1[100],string2[100];

int i=0,j=0;

printf("enter first string");

gets(string1);

printf("enter second string");

gets(string2);

while(string1[i]!='\0')

{

i++;

}

while(string2[j]!='\0')

{

string1[i]=string2[j];

i++;

j++;

}

string1[i]='\0';

printf("the concatenated string=%s",string1);

return 0;

}


output:-

c program to concatenate two strings without strcat()







c program to count total characters present in a strings | 2D strings examples in c

Array program collection C 


/* program to store multiple strings and count  total their characters

*/

#include<stdio.h>

int main()

{

char string[5][100]={"c program","C++ code","JS code","php code","java code"};

int i,j,count;

for(i=0;i<=4;i++)

{

count=0;

for(j=0;string[i][j]!='\0';j++)

{

count++;

}

printf("the string is %s and its length is %d\n",string[i],count);

}

return 0;

}

Output:

c program to count total letters present in strings



Thursday, May 29, 2025

c program to print sum of two matrices of order mxn | 2D Array-matrix examples

Array programs in C 


/* to find sum of two matrix of order mxn

*/

#include<stdio.h>

int main()

{

int m,n,i,j;

printf("enter m as rows and n as columns\n");

scanf("%d%d",&m,&n);//if m=3 then the loop would run for 0,1,2

int m1[m][n],m2[m][n];

printf("enter elements for first matrix m1\n");

for(i=0;i<=m-1;i++)

{

for(j=0;j<=n-1;j++)

{

printf("enter element for location %d %d\n",i,j);

scanf("%d",&m1[i][j]);

}

}

printf("enter elements for second matrix m2\n");

for(i=0;i<=m-1;i++)

{

for(j=0;j<=n-1;j++)

{

printf("enter element for location %d %d\n",i,j);

scanf("%d",&m2[i][j]);

}

}

printf("the sum of two matrices is:\n");

for(i=0;i<=m-1;i++)

{

for(j=0;j<=n-1;j++)

{

printf("%d",m1[i][j]+m2[i][j]);

}

printf("\n");

}

return 0;

}


Output:-

c program to find sum of two matrices



Tuesday, May 27, 2025

c program to copy array elements to another | Array examples

Array programs in C


/* program to copy one array elements to another

*/
#include<stdio.h>
int main()
{
int a[5];
int b[5];
int i;
for(i=0;i<=4;i++)
{
printf("enter elment for %d location",i+1);
scanf("%d",&a[i]);
}
for(i=0;i<=4;i++)
{
b[i]=a[i];
}
printf("the copied elements are:\n");
for(i=0;i<=4;i++)
{
printf(" %d ",b[i]);
}
return 0;
}

Output:-

C program to copy array elements to another array



Tuesday, May 20, 2025

C program to copy one array element to another | Array examples

Array programs in C

C program to copy one array elements to another 

/* program to copy one array element to another
*/

#include<stdio.h>
int main()
{
int a[5];
int b[5];
int i;
for(i=0;i<=4;i++)
{
printf("enter elment for %d location",i+1);
scanf("%d",&a[i]);
}
for(i=0;i<=4;i++)
{
b[i]=a[i];
}
printf("the copied elements are:\n");
for(i=0;i<=4;i++)
{
printf(" %d ",b[i]);
}
return 0;
}


Output:-

c program to copy elements to another array