C programming common bugs and solutions

You are given n people in a row, k of whom are infected with a disease, number of ways in which disease can spread to all n people considering At any point it only spreads from one person to one of its neighbour.

is this the complete question?

First try your code, if feel any issue/error - you’re free to ask

Write a function (using a pointer parameter) that reverses the elements of a given array.
Input: Input array elements: 10 20 30 40 50 60 70 80 90 100
Output: Reversed array: 100 90 80 70 60 50 40 30 20 10

#include <stdio.h>

int main()
{
    int i,n;
    scanf("%d",&n);
    int x[n];
    //int (*a)[n];
    int *p;
    p = x;
    //p = *a;
    for(i=0;i<n;i++)
    {
        scanf("%d",(p+i)); // This Shows Segmentation Fault* 
    }
    for(i=0;i<n;i++)
    {
        printf("%d ",*(p+i));
    }
    printf("\n");

    //reversing array
    // intialize the pointer with last element's address
    p = &x[n-1];
    // now print the array
    for(i=0;i<n;i++)
    {
        printf("%d ",*(p-i));
    }
    return 0;
}
1 Like

but we need to use user defined functions and pass pointer as parameter like this void reverese (int *). Help me solve using this .