Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- /*
- task1_v1.c
- Version with double pointer (which is unnecessary).
- Task from Germin Chan
- https://web.facebook.com/germin.chan
- https://web.facebook.com/groups/543431102664524/?post_id=1174495746224720&comment_id=1174746769532951&reply_comment_id=1175294896144805¬if_id=1591153540531865¬if_t=group_comment&ref=notif
- You can find all my C programs at Dragan Milicev's pastebin:
- https://pastebin.com/u/dmilicev
- */
- #include<stdio.h>
- #include<stdlib.h>
- int values_under_100(int *values, int size, int **under_100_array){
- int i, j=0, sum=0;
- for(i=0;i<size;i++){ //for loop to get values under 100
- if ( *(values+i) < 100 ) {
- *(*under_100_array + j) = *(values + i);
- j++;
- sum++;
- }
- }
- return sum;
- }
- int main(void){
- int i, size;
- int *values;
- printf("\n How many inputs do you want to enter? ");
- scanf("%d", &size);
- values = malloc(size*sizeof(int)); //dynamic allocation
- for(i=0;i<size;i++){
- printf("\n Enter value: ");
- scanf("%d", values + i );
- }
- int *under_100_array = malloc(size*sizeof(int)); //dynamic allocation
- int count = values_under_100(values, size, &under_100_array); //call the function
- printf("\n Values under 100 are: ");
- for(i=0;i<count;i++){ //for loop to print array
- printf("%d ", *(under_100_array + i) );
- }
- printf("\n\n There are %d values under 100.\n", count);
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement