click_here
- Joined Sep 22, 2020
- 548
Same i<N problem as above
You should be printing
Code:
"list[i]" not "list"
Same i<N problem as above
"list[i]" not "list"
Ok I've written code but its different from flowchart. I've verified code. It give exactly same result as I wantThat should be more than enough for you to start writing the code and debugging from there.
/*
* 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;
}
Then that defeats the whole purpose of flowcharting.Ok I've written code but its different from flowchart.
@MrChipsThen that defeats the whole purpose of flowcharting.
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.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
#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;
}
by Duane Benson
by Aaron Carman
by Jake Hertz
by Jake Hertz