# [SOLVED]Algorithm & Flowchart Design

#### click_here

Joined Sep 22, 2020
545
# Second flowchart to add and search number in list

View attachment 239900
Same i<N problem as above

You should be printing
Code:
"list[i]" not "list"

#### click_here

Joined Sep 22, 2020
545
That should be more than enough for you to start writing the code and debugging from there.

#### Pushkar1

Joined Apr 5, 2021
416
That should be more than enough for you to start writing the code and debugging from there.
Ok I've written code but its different from flowchart. I've verified code. It give exactly same result as I want

C:
/*
* Program:   Add and serach number in list
* Author:    Pushkar
* Created on May 5, 2021, 5:59 AM
*/

#include<stdio.h>

int main (void)
{
int i, N, X;

printf("How many numbers you want to add : " );
scanf("%d",&N);                                  // Get size of list

int List[N];                                     // declare array for list

for(i=0; i<N; i++)
{
printf("print List element : ", List[i]);
scanf("%d",&List[i]);                        // add numbers in list
}

printf("Which number you want to search : " );
scanf("%d",&X);                                 // Get number

for(i= 0; i<N; i++)
{
if (X == List[i])                           // Check if number match with list numbers
{
printf("Number Found in List \n");
break;
}

}

return 0;

}

How many numbers you want to add : 3
print List element : 1
print List element : 2
print List element : 3
Which number you want to search : 1
Number Found in List

How many numbers you want to add : 3
print List element : 1
print List element : 2
print List element : 3
Which number you want to search : 2
Number Found in List

How many numbers you want to add : 3
print List element : 1
print List element : 2
print List element : 3
Which number you want to search : 3
Number Found in List

@click_here I don't know how to delete any number in list. When we declare array we allocate fixed size of memory We can't add or delete allocated memory for array

#### MrChips

Joined Oct 2, 2009
27,723
Ok I've written code but its different from flowchart.
Then that defeats the whole purpose of flowcharting.

#### Pushkar1

Joined Apr 5, 2021
416
Then that defeats the whole purpose of flowcharting.
@MrChips

No doubt, flowchart help to get idea. I made it before to write code

I posted three flowchart but did not get any response. so i thought it better to post the code directly

#### click_here

Joined Sep 22, 2020
545
Ok I've written code but its different from flowchart. I've verified code. It give exactly same result as I want

C:
/*
* Program:   Add and serach number in list
* Author:    Pushkar
* Created on May 5, 2021, 5:59 AM
*/

#include<stdio.h>

int main (void)
{
int i, N, X;

printf("How many numbers you want to add : " );
scanf("%d",&N);                                  // Get size of list

int List[N];                                     // declare array for list

for(i=0; i<N; i++)
{
printf("print List element : ", List[i]);
scanf("%d",&List[i]);                        // add numbers in list
}

printf("Which number you want to search : " );
scanf("%d",&X);                                 // Get number

for(i= 0; i<N; i++)
{
if (X == List[i])                           // Check if number match with list numbers
{
printf("Number Found in List \n");
break;
}

}

return 0;

}

How many numbers you want to add : 3
print List element : 1
print List element : 2
print List element : 3
Which number you want to search : 1
Number Found in List

How many numbers you want to add : 3
print List element : 1
print List element : 2
print List element : 3
Which number you want to search : 2
Number Found in List

How many numbers you want to add : 3
print List element : 1
print List element : 2
print List element : 3
Which number you want to search : 3
Number Found in List

@click_here I don't know how to delete any number in list. When we declare array we allocate fixed size of memory We can't add or delete allocated memory for array
You could use a -1 as a place holder that you don't print, or use malloc to set up the array and realloc to resize it.

However, the best way would be to make a linked list: this is one of the cases where it is perfect for (regularly adding/deleting items in a list)

#### click_here

Joined Sep 22, 2020
545
You could also have a larger array and keep track of the length of how many elements you are using.

You'd have to do a quick check when adding numbers to say if there is not enough memory.

Here is a *very* basic bare bones way of using this method for a delete (after everything is already set up)
C:
#include <stdio.h>
#include <stdlib.h>

int main(void)
{
int numberSet[10] = {1,2,3,4,5,6};
int currentLength = 6;
int numberToRemove = 3;
int i, src, dest;

printf("Before: ");
for(i=0; i<currentLength; i++)
{
printf("%d ", numberSet[i]);
}
putchar('\n');

// Remove number
for(src=0, dest=0; src<currentLength; src++)
{
if(numberSet[src] == numberToRemove)
{
continue;
}

numberSet[dest++] = numberSet[src];
}
currentLength--;

printf("After: ");
for(i=0; i<currentLength; i++)
{
printf("%d ", numberSet[i]);
}
putchar('\n');

return EXIT_SUCCESS;
}