counter

Free Hit Counter
Showing posts with label Arrays. Show all posts
Showing posts with label Arrays. Show all posts

Counting of array elements

Q: nos are entered thru the keyboard and the no. of positive,negative and zero elements also the count of odd and even nos present in the array are displayed


#include
#include
void main()
{
int a[25],i,z=0,p=0,n=0,o=0,e=0;
clrscr();
for(i=0;i<5;i++)
{
printf("enter any no.:");
scanf("%d",&a[i]);
}

for(i=0;i<5;i++)
{

if(a[i]==0)
z++;
else if(a[i]>0)
p++;
else
n++;
}
for(i=0;i<5;i++)
{
if(a[i]%2==0)
e++;
else
o++;
}
printf("no of Zero elements:%d\n",z);
printf("no of positive nos:%d\n",p);
printf("no of negative nos:%d\n",n);
printf("no of odd nos:%d\n",o);
printf("no of even nos:%d\n",e);

getch();
}



Search no. in array

Q: nos are entered thru the keyboard and the no. searched by the user is displayed if it is present in the array


#include
#include
void main()
{
int a[25],i,n,c=0;
clrscr();
for(i=0;i<5;i++)
{
printf("enter any no.:");
scanf("%d",&a[i]);
}
printf("Enter the no. to be searched:");
scanf("%d",&n);
for(i=0;i<=5;i++)
{

if(n==a[i])
c++;
}
if(c>0)
{
printf("%d\n",n);
printf("the no is present %d times",c);
}
else
printf("no. not present in array");
getch();
}



Addition of two matrices

Publish Post
#include
#include
void main()
{
int a[10][10], b[10][10], c[10][10], i, j, row, col;
clrscr();
printf("\nEnter number of rows and columns: ");
scanf("%d %d", &row, &col);
printf("\nEnter elements of Array A:\n");
for (i=0; i
{
for (j=0; j
{
scanf("%d", &a[i][j]);
printf("\nEnter elements of Array B:\n");
}
for (i=0; i
{
for (j=0; j
{

scanf("%d", &b[i][j]);
printf("\nElements of Matrix A:\n\n");
}
for (i=0; i
{
for (j=0; j
{

printf("\t%d", a[i][j]);
}
printf("\n\n");
}

}
printf("\nMatrix B:\n\n");
for (i=0; i
{
for (j=0; j
{
printf("\t%d", b[i][j]);
}
printf("\n\n");
}
for (i=0; i
{
for (j=0; j
{
c[i][j] = a[i][j] + b[i][j];
}
printf("\nAddition is:\n\n");
}
for (i=0; i
{
for (j=0; j
{
printf("\t%d", c[i][j]);
}
printf("\n");
}
getch();
}
}