Hello, OnlineGDB Q&A section lets you put your programming query to fellow community users. Asking a solution for whole assignment is strictly not allowed. You may ask for help where you are stuck. Try to add as much information as possible so that fellow users can know about your problem statement easily.

How to fix this C

+4 votes
asked Dec 22, 2022 by Death Nam (160 points)
#include<conio.h>
#include<stdio.h>
#include<math.h>
void nhapmang(int a[], int n)
{
    for(int i=0; i<n; i++)
    {
        printf("nhap a[%d]",i);
        scanf("%d",&a[i]);
    }
}
void xuatmang(int a[], int n)
{
    for(int i=0; i<n; i++)
    {
        printf("%d",a[i]);
        printf("\n");
    }
}
int timvitringtulonhon23(int a[], int n)
{
    for(int i=0; i<n; i++)
    {
        if(a[i]<0)
        {
            printf("vi tri pt am dau tien : %d \n", a[i]);
        }
            else
                return -1;
    }
}
void main()
{
    int a[100];
    int n;
    int x;
    printf("nhap slpt : ");
    scanf("%d",&n);
    nhapmang(a, n);
    xuatmang(a, n);
    timvitrisoamdautien(a, n);
}

//i need help i dont know what to do the thing i was trying to do is find the number > 23

1 Answer

0 votes
answered Dec 22, 2022 by Peter Minarik (86,160 points)
  1. Use English identifiers please so others can have an idea of what your code is doing.
  2. User the right function names (the compiler tells you this error)
  3. I'm not sure what your last function is supposed to return. It only returns -1 if it does not find a negative number. What shall it return when every number was negative?
#include<conio.h>
#include<stdio.h>
#include<math.h>
void nhapmang(int a[], int n)
{
    for (int i = 0; i < n; i++)
    {
        printf("nhap a[%d]", i);
        scanf("%d", &a[i]);
    }
}

void xuatmang(int a[], int n)
{
    for (int i = 0; i < n; i++)
    {
        printf("%d", a[i]);
        printf("\n");
    }
}

int timvitringtulonhon23(int a[], int n)
{
    for (int i = 0; i < n; i++)
    {
        if (a[i] < 0)
        {
            printf("vi tri pt am dau tien : %d\n", a[i]);
        }
        else
        {
            return -1;
        }
    }
}

void main()
{
    int n;
    int x;
    printf("nhap slpt : ");
    scanf("%d",&n);
    int a[n];
    nhapmang(a, n);
    xuatmang(a, n);
    timvitringtulonhon23(a, n);
}
Welcome to OnlineGDB Q&A, where you can ask questions related to programming and OnlineGDB IDE and and receive answers from other members of the community.
...