Arrays Programs
Arrays Programs
#include<stdio.h>
using namespace std;
int main()
{
int i ,T,a[25];
for(i=0;i< 25;i++)
{
printf("Enter the numbers=");
scanf("%d",&a[i]);
}
printf("Enter the value to be searched :");
scanf("%d", &T);
for(i=0;i< 25;i++)
{
if(a[i] == T)
printf("Index Location ==> %d",i+1);
}
return(0);
}
#include<stdio.h>
using namespace std;
int main()
{
int i,j,A[3][3],B[3][3],C[3][3];
for(i=0;i<2;i++)
{
for(j=0;j<3;j++)
{
printf("Enter the Value Matrix A ="); scanf("%d",&A[i][j]);
printf("Enter the Value Matrix B ="); scanf("%d",&B[i][j]);
C[i][j]=A[i][j]+B[i][j];
}
}
for(i=0;i<3;i++)
for(j=0;j<3;j++)
printf(" C[%d][%d] = %d\n",i,j,C[i][j]);
return(0);
}
Q-48. Write a program which receive the data of two 3 x 2 matrix and 3
x 3 matrix from the user, then multiply them and store the result in a third
matrix of order 2 x 3.
for(i=0;i<3;i++)
for(j=0;j<3;j++)
{
printf("Enter Values for Matrix B=");
scanf("%d",&B[i][j]);
}
for(i=0;i<2;i++)
for(j=0;j<3;j++)
{
C[i][j]=0;
for(k=0;k<3;k++)
C[i][j]=C[i][j]+A[i][k]*B[k][j];
}
for(i=0;i<2;i++)
{
for(j=0;j<3;j++)
printf("%d\t",C[i][j]);
printf("\n");
}
return(0);
}
#include<iostream.h>
using namespace std;
int main()
{
System(“CLS”);
int K,A[15],N=15,TEMP,MIN,J,LOC;
for(K=0;K<15;K++)
{
printf(“Enter A[ %d ]=”,K);
scanf(“%d”, &A[K]);
}
for(K=0;K<15;K++)
{
MIN=A[K];
LOC=K;
for(J=K+1;J<N;J++)
{
if(MIN>A[J])
{
MIN=A[J];
LOC=J;
}
}
TEMP=A[K];
A[K]=A[LOC];
A[LOC]=TEMP;
}
for(K=0;K<=14;K++)
printf(“Enter A[ %d ]= %d\n”,K,A[K]);
retrun(0);
}
Q-50. Implement the Bubble Sort algorithms on a set of 15 numbers.
Week # 16
Strings
Q-52. Write a program that will accept two strings and store them into
two separate character arrays then copy a string into a third character
array using function strcpy() and concatenate the second string with the
third string using function strcat(). Display the third string.
#include <stdio.h>
#include <string.h>
using namespace std;
int main()
{
char N[20],T[20];
int C,L;
printf("Enter your name please : ");
scanf("%s",&N);
printf("N==%s\n\n",N);
strcpy(T,N);
printf("T==%s\n\n",T);
strcat(T," ");
strcat(T,"baloch");
printf("string contenation==%s\n\n",T);
return(0);
}
Q-53. Write a program that will input a string and store it into a
character array. Then find the length of that string using strlen() function
and display this length.
#include <stdio.h>
#include <string.h>
using namespace std;
int main()
{
char N[20],T[20];
int C,L;
printf("Enter your name please : ");
scanf("%s",&N);
printf("N==%s\n\n",N);
L=strlen(N);
printf("string length==%d\n\n",L);
return(0);
}
Q-54. Write a program that will input two string and store them into
two separate character array. Then compare these two strings using
function strcmp() and display the larger string.
#include <stdio.h>
#include <string.h>
using namespace std;
int main()
{
char N[20],T[20];
int C,L;
printf("Enter first string please : ");
scanf("%s",&N);
printf("Enter second string please : ");
scanf("%s",&T);
if (strcmp(N,T)>0);
printf("first string is larger==%s\n\n",N);
else
printf("Second string is larger==%s\n\n",T);
return(0);
}