You are on page 1of 7

ASSIGNMENT 4

1. Write a program in C to store elements in an array and print it.


#include<stdio.h>
#include<conio.h>
void main()
{
clrscr();
int i,a[5];
printf("enter the stored elements");
for(i=0;i<5;i++)
{
scanf("%d",&a[i]);
}
printf("numbers stored in array = ");
for(i=0;i<5;i++)
{
printf("%d",a[i]);
}
getch();
}
OUTPUT

VARIABLE LIST
VARIABLE-NAME DATA-TYPE DESCRIPTION

i Integer type Stores the looping variable

a[] Integer type Stores the array element

2. Write a program in C to read n number of values in an array and display


it in reverse order.
#include<stdio.h>
#include<conio.h>
void main()
{
clrscr();
int i,a[10],n;
printf("enter the number of values less than 10 in an array"); scanf("%d",&n);
printf("enter the elements in an array");
for(i=0;i<=n-1;i++)
{
scanf("%d",&a[i]);
}
printf("the reversed elements = ");
for(i=n-1;i>=0;i--)
{
printf("%d",a[i]);
}
getch();
}

OUTPUT

VARIABLE LIST
VARIABLE-NAME DATA-TYPE DESCRIPTION

i Integer type Stores the looping variable

a[] Integer type Stores the array element

n Integer type Number of elements

3. Write a program in C to find the sum of all elements of the array.


#include<stdio.h>
#include<conio.h>
void main()
{
clrscr();
int i,a[50],n,s=0;
printf("enter the number of values less than 50 in an array"); scanf("%d",&n);
printf("enter the elements in an array");
for(i=0;i<=n-1;i++)
{
scanf("%d",&a[i]);
}
for(i=0;i<=n-1;i++)
{
s=s+a[i];
}
printf("the sum is = %d ",s);
getch();
}

OUTPUT

VARIABLE LIST
VARIABLE-NAME DATA-TYPE DESCRIPTION

i Integer type Stores the looping variable

a[] Integer type Stores the array element

n Integer type Number of elements

s Integer type Use to add variables

4. Write a program in C to find the minimum value from all elements of the
array.
#include<stdio.h>
#include<conio.h>
void main()
{
clrscr();
int i,a[50],n,min=0;
printf("enter the number of values less than 50 in an array"); scanf("%d",&n);
printf("enter the elements in an array");
for(i=0;i<=n;i++)
{
scanf("%d",&a[i]);
}
min=a[0];
for(i=0;i<=n-1;i++)
{
if(min>a[i])
min=a[i];
}
printf("the minimum value in array is = %d ",min);
getch();
}

OUTPUT

VARIABLE LIST
VARIABLE-NAME DATA-TYPE DESCRIPTION

i Integer type Stores the looping variable

a[] Integer type Stores the array element

n Integer type Number of elements

min Integer type Use to find minimum number


ASSIGNMENT 5
1) Input a 2D Array from user and Display it. Test Case:

#include<stdio.h>
#include<conio.h>
void main()
{
clrscr();
int i,j,ary[2][4];
for(i=0;i<2;i++)
{
for(j=0;j<4;j++)
{
printf ("ENTER EIGHT ELEMENTS IN THE ARRAY [%d][%d]:",i,j);
scanf("%d",&ary[i][j]);
}
}
printf ("TWO DIMENSIONAL ARRAY ELEMENTS:\n");
for(i=0;i<2;i++)
{
for(j=0;j<4;j++)
{
printf("%d,",ary[i][j]);
}
printf("\n");
}
getch();
}

OUTPUT
VARIABLE LIST
VARIABLE NAME DATA TYPE DESCRIPTION

i Integer type Stores the row value

j Integer type Stores the column value

ary[][] Integer type Stores the elements in two dimensions

2) Now take this matrix (initialize it) and increment each element with 10. 4 5 11 23
6 3 71 22
After increment
14 15 21 33
16 13 81 32

#include<stdio.h>
#include<conio.h>
void main()
{
clrscr();
int i,j,ary[2][4]=
{
{4,5,11,23},
{6,3,71,22}
};
printf("after increment\n");
for(i=0;i<2;i++)
{
for(j=0;j<4;j++)
{
printf("%d,",ary[i][j]+10);
}
printf("\n");
}
getch();
}

OUTPUT

VARIABLE LIST
VARIABLE NAME DATA TYPE DESCRIPTION

i Integer type Stores the row value

j Integer type Stores the column value

ary[][] Integer type Stores the elements in two dimensions

You might also like