Sie sind auf Seite 1von 6

UMANG JAIN

04216403216
1. AIM :- To implement an array and find minimum element

ALGORITHM : -
Input: an array
output: minimum element of that array and its location
Steps : 1. Start
2. Declare integer variables min, loc and an array a[10]
3. Input elements of the array.
4. Assign a[0] as minimum value
5. if(a[i]<min)
Then min=a[i]
Loc=i
6. display minimum number as a[i]
7. End

PROGRAM :-
#include<stdio.h>
#include<conio.h>
Void main()
{
Int a[10],min,loc,i;
for(i=0;i<10;i++)
{
Printf(Enter the %d element of the array :,i);
Scanf(%d,&a[i]);
}
min=a[0];
loc=0;
for(i=1;i<10;i++)
{
If(a[i]<min)
{
min=a[i];
loc=i;
}
}
Printf(min element is %d at %d,min,loc);
getch();
}

OUTPUT :-
UMANG JAIN
04216403216

2. AIM: - To store useful elements from a sparse array


ALGORITHM: -
Input: A Sparse array
Output: useful elements of that array and their positions
Steps: 1. Start
2. Define an array of structure which contains row, column and position to store
values.
3. Count = L /* initialise counter by assigning lower bound
value of structure array*/
4. traverse the array untill it reaches the last element
5. /*search the elements */
if (arr[i][j]!=0)
{store value of i, j and value in the structure}
6. End

PROGRAM : -
#include <stdio.h>
#include <stdlib.h>
int main()
{
struct Sparse
{
int r,c;
int value;
} S[100];
int a[4][4];
int i, j,k = 0,x= 0;
printf ("Enter the elements in the array : \n");
for (i = 0; i < 3; i++)
{
for (j = 0; j < 3; j++)
{
printf ("Enter a[%d][%d] element : ",i,j);
scanf ("%d", &a[i][j]);
}
}
for(i = 0; i < 3; i++)
{
for (j = 0; j < 3; j++)
{
if (a[i][j]!=0)
{
S[k].r= i;
S[k].c= j;
S[k].value = a[i][j];
k++;
}
}
}
printf ("row column value\n");
while (x< k)
{
printf ("%d %d %d\n", S[x].r+1, S[x].c+1, S[x].value);
x++;
}
return 0;
}

OUTPUT : -
UMANG JAIN
04216403216

3. AIM :- To implement a push and pop function in a stack


ALGORITHM :-
For push function
1: if TOP >= SIZE -1 then
Write Stack is Overflow
2: TOP = TOP+1
3: STACK[TOP] = X
For pop function
1: if TOP = -1 then
Write Stack is Underflow
2: Return STACK[TOP]
3: TOP =TOP-1
PROGRAM :-
#include<stdio.h>
#include<ctype.h>
#define MAX 50
int Top = -1;
void push(int* s, int n){
if(Top==MAX-1){
printf("Error:Stack overloading");
return;
}
else{
Top++;
s[Top] = n;
}
}
int pop(int* s){
if(Top==-1){
printf("Error:Cannot pop from an empty stack\n");
return;
}
else{ return s[Top--]; }
}
void main(){
int ch,x,n; int s[MAX]; char ch1 ='y';
do{
char ch1;

printf("Enter the choice\n");


printf("1:Push\n2:Pop\n");
scanf("%d",&ch);
switch(ch);
case 1:
printf("Enter the value:");
scanf("%d",&n);
push(s, n);
break;
case 2:
x=pop(s);
printf("The deleted element is%d",x);
break;
default: printf("Enter a valid number!");
}
printf("Do you want to continue(Y/n):");
getche(ch1); printf("\n");
}while(tolower(ch1)=='y');
}

OUTPUT :-

Das könnte Ihnen auch gefallen