lundi 4 octobre 2021

Is there a way to display "number not found" after the forloop ends?

#include <stdio.h>
void main()
{
    int n,i;
    int arr[5]={5,4,3,2,1};
    int *ptr;
    printf("input the number you want to find:\n");
    scanf("%d",&n);
    for(i=0;i<5;i++)
        if(arr[i]==n)
        {
            ptr=&arr[i];
        printf("number '%d' is present in the array and it is the %d st/nd/rd/th term in the array.\n its address is: %d",n,i+1,ptr);
        }
}

**>i added else printf("number not found"); here but its also looping and printing a lot **

Aucun commentaire:

Enregistrer un commentaire