What's new

C & C++ Help array

PHC-Eye

Elite
Joined
Jun 6, 2020
Posts
522
Reaction
145
ito po dapat maging output paayos po nong code ko🙏
IMG_20211201_120737.jpg

C:
#include <stdio.h>

int main()
{
    int i,ar[9];
    printf("Input 10 integers in the array:\n");
    
    for (i=0;i<10;i++)
    {
        printf("array[%i]: ", i);
        scanf ("%i",&ar[i]);
    }
    
    for (i=0;i<10;i++){
        if(ar[i]%2==0){
            printf("\nEven integers Found!\n");
            printf("The Even integers are: \n");
            for(i=0;i<10;i++){
                if(ar[i]%2==0){
                    printf("%i ",ar[i]);
                }
            }
        }
        else{
            printf("No Even integers Found!\n");
        }
        
        if(ar[i]%2==1){
            printf("\n\nOdd integers Found!\n");
            printf("The Odd integers are: \n");
            for(i=0;i<10;i++){
                if(ar[i]%2==1){
                    printf("%i ",ar[i]);
                }
            }
        }
        else{
            printf("\nNo Odd integers Found!");
        }
    }
    return 0;
}
 

Attachments

dee-u

Elite
Subukan mo ito. Pinagpraktisan ko lang.
C:
#include <stdio.h>

int main()
{
    int i,ar[9];
    printf("Input 10 integers in the array:\n");
    
    for (i=0;i<10;i++)
    {
        printf("array[%i]: ", i);
        scanf ("%i",&ar[i]);
    }
    
    bool withEvenNumbers = false;
    bool withOddNumbers = false;
    
    for (i=0;i<10;i++){
        if(ar[i]%2==0){
            withEvenNumbers = true;   
        }
        else{
            withOddNumbers = true;   
        }
    }
    
    if (withEvenNumbers == false){
        printf ("No even numbers found\n");
    }
    else{
        printf ("Even numbers found!\n");
        printf ("The even integers are \n" );
        for (i=0;i<10;i++){
            if(ar[i]%2==0){
                printf("%d ", ar[i] );
            }
        }   
    }


    printf("\n");


    if (withOddNumbers == false){
        printf("No odd numbers found\n");
    }
    else{
        printf("Odd numbers found!\n");
        printf("The odd integers are \n");
        for (i=0;i<10;i++){
            if(ar[i]%2 == 0){
                
            }
            else{
                printf("%d ", ar[i] );
            }
        }   
    }   
    
    
    return 0;
}
 
Top