What's new

C & C++ Patulong po (C program)

CeeDzii

Forum Veteran
Elite
Joined
Jun 30, 2016
Posts
1,412
Solutions
2
Reaction
537
Points
604
Baka may idea po kayo? Di ko alam anong mali eh

#include <stdio.h> int main() { int rows, columns; printf("Enter the number of rows: "); scanf("%d", &rows); printf("Enter the number of columns: "); scanf("%d", &columns); int arr[rows][columns]; for (int i = 0; i < rows; i++) { for (int j = 0; j < columns; j++) { scanf("%d", &arr[i][j]); } } if (rows == columns) printf("SPY"); else printf("NONE"); return 0; }

Capture.PNG R&C.PNG
 

Attachments

Hindi ako sure. Pero pasok to lahat sa test cases. Check mo paano ako nagname ng mga variables. Mas madali basahin ang code kapag may meaning yung variables mo.


C:
#include <stdio.h>
#include <stdlib.h>

const int X = 100;
const int Y = 100;

int isSpy(int personInQuestion, int people[X][Y], int row, int column)
{
    int counter = 0;
    for(int i = 0; i < row; i++)
    {
        for(int j = 0; j < column; j++)
        {
            if(people[i][j] == personInQuestion)
            {
                counter++;
            }
        }

        if(counter > 1)
        {
            return 0;
        }
    }

    return 1;
}
int main()
{
    int inputRow, inputColumn;
    int people[X][Y];
    int personInQuestion;

    printf("Enter the number of rows: ");
    scanf("%d", &inputRow);
    printf("Enter the number of columns: ");
    scanf("%d", &inputColumn);

    for(int i = 0; i < inputRow; i++)
    {
        for(int j = 0; j < inputColumn; j++)
        {
            scanf("%d", &people[i][j]);
            if(people[i][j] < 0 || people[i][j] > 10)
            {
                // Error
                return 0;
            }
        }
    }

    // Check if spy
    for(int i = 0; i < inputRow; i++)
    {
        for(int j = 0; j < inputColumn; j++)
        {
            personInQuestion = people[i][j];
            if(isSpy(personInQuestion, people, inputRow, inputColumn) == 1)
            {
                 printf("SPY");
                 return 0;
            }
        }
    }


    printf("NONE");
    return 0;
}
 
Hindi ako sure. Pero pasok to lahat sa test cases. Check mo paano ako nagname ng mga variables. Mas madali basahin ang code kapag may meaning yung variables mo.


C:
#include <stdio.h>
#include <stdlib.h>

const int X = 100;
const int Y = 100;

int isSpy(int personInQuestion, int people[X][Y], int row, int column)
{
    int counter = 0;
    for(int i = 0; i < row; i++)
    {
        for(int j = 0; j < column; j++)
        {
            if(people[i][j] == personInQuestion)
            {
                counter++;
            }
        }

        if(counter > 1)
        {
            return 0;
        }
    }

    return 1;
}
int main()
{
    int inputRow, inputColumn;
    int people[X][Y];
    int personInQuestion;

    printf("Enter the number of rows: ");
    scanf("%d", &inputRow);
    printf("Enter the number of columns: ");
    scanf("%d", &inputColumn);

    for(int i = 0; i < inputRow; i++)
    {
        for(int j = 0; j < inputColumn; j++)
        {
            scanf("%d", &people[i][j]);
            if(people[i][j] < 0 || people[i][j] > 10)
            {
                // Error
                return 0;
            }
        }
    }

    // Check if spy
    for(int i = 0; i < inputRow; i++)
    {
        for(int j = 0; j < inputColumn; j++)
        {
            personInQuestion = people[i][j];
            if(isSpy(personInQuestion, people, inputRow, inputColumn) == 1)
            {
                 printf("SPY");
                 return 0;
            }
        }
    }


    printf("NONE");
    return 0;
}
Salamat po, pag aaralan ko po ito. Pwede po pa request isa pa pong tulong? Last na po hehe
 
Salamat po, pag aaralan ko po ito. Pwede po pa request isa pa pong tulong? Last na po hehe
Gusto ko naman talaga tumulong sa mga tao dito sa programming forum dito. Yun lang gusto ko makita na nag effort muna sila. Basta nag effort ka muna.
 
Gusto ko naman talaga tumulong sa mga tao dito sa programming forum dito. Yun lang gusto ko makita na nag effort muna sila. Basta nag effort ka muna.
Eto po lods di ko alam san mali ko jan, after ko po kasi mag input ng numbers, ibang number lumalabas sa arranged section. ODDS AND EVENS po

#include <stdio.h> #define n 100 int main() { int num[n], elements, temp, j = n; printf("Enter the number of elements: "); scanf("%d", &elements); for (int i = 1; i <= elements; i++) { printf("Element #%d: ", i); scanf("%d", &num); } for(int i = 0; i <= j; i++) { if(num[i] % 2 != 0) { while(j > i) { j--; if(num[j] % 2 == 0) { temp = num[i]; num[i] = num[j]; num[j] = temp; break; } } } } printf("\nArranged Elements: "); for (int i = 1; i <= elements; i++) { printf("\nElement #%d: ", i); printf("%d", num); } return 0; }

Odds n Even.PNG

Gusto ko naman talaga tumulong sa mga tao dito sa programming forum dito. Yun lang gusto ko makita na nag effort muna sila. Basta nag effort ka muna.
Di naman po ako humihingi ng tulong dito kapag feel ko na kaya ko yung problems. Binibigyan ko ang sarili ko ng atleast 1 week na isolve ang problem at mag self learning or mag search sa google at YøùTùbé ng ibat ibang solutions bago ako hihingi ng tulong dito hehe
 

Attachments

Last edited:
Goodluck!

C:
#include <stdio.h>
#include <stdlib.h>

const size = 100;

int main()
{
    int oddNumbers[size];
    int evenNumbers[size];

    int oddCounter = 0;
    int evenCounter = 0;

    int inputElementSize = 0;
    int inputNumber;

    // Get number of elements
    printf("Enter the number of elements: ");
    scanf("%d", &inputElementSize);

    if(inputElementSize < 1)
    {
        // Error
        return 0;
    }

    // Get value for elements then determine of odd or even
    // Put to array of oddNumbers if odd otherwise to evenNumbers
    for (int i = 0; i < inputElementSize; i++)
    {
        printf("Element #%d: ", i + 1);
        scanf("%d", &inputNumber);

        if(inputNumber < 0 || inputNumber > 2147483647)
        {
            // Error
            return 0;
        }
        else if(inputNumber % 2 == 1)
        {
            oddNumbers[oddCounter] = inputNumber;
            oddCounter++;
        }
        else
        {
            evenNumbers[evenCounter] = inputNumber;
            evenCounter++;
        }
    }

    // Show arranged elements even first then odd
    printf("\nArranged Elements:");

    for (int i = 0; i < evenCounter; i++)
    {
        printf("\nElement #%d: ", i + 1);
        printf("%d", evenNumbers[i]);
    }
    for (int i = 0; i < oddCounter; i++)
    {
        printf("\nElement #%d: ", i + evenCounter + 1);
        printf("%d", oddNumbers[i]);
    }
}
 
Goodluck!

C:
#include <stdio.h>
#include <stdlib.h>

const size = 100;

int main()
{
    int oddNumbers[size];
    int evenNumbers[size];

    int oddCounter = 0;
    int evenCounter = 0;

    int inputElementSize = 0;
    int inputNumber;

    // Get number of elements
    printf("Enter the number of elements: ");
    scanf("%d", &inputElementSize);

    if(inputElementSize < 1)
    {
        // Error
        return 0;
    }

    // Get value for elements then determine of odd or even
    // Put to array of oddNumbers if odd otherwise to evenNumbers
    for (int i = 0; i < inputElementSize; i++)
    {
        printf("Element #%d: ", i + 1);
        scanf("%d", &inputNumber);

        if(inputNumber < 0 || inputNumber > 2147483647)
        {
            // Error
            return 0;
        }
        else if(inputNumber % 2 == 1)
        {
            oddNumbers[oddCounter] = inputNumber;
            oddCounter++;
        }
        else
        {
            evenNumbers[evenCounter] = inputNumber;
            evenCounter++;
        }
    }

    // Show arranged elements even first then odd
    printf("\nArranged Elements:");

    for (int i = 0; i < evenCounter; i++)
    {
        printf("\nElement #%d: ", i + 1);
        printf("%d", evenNumbers[i]);
    }
    for (int i = 0; i < oddCounter; i++)
    {
        printf("\nElement #%d: ", i + evenCounter + 1);
        printf("%d", oddNumbers[i]);
    }
}
Maraming salamat po
 
Hindi ako sure. Pero pasok to lahat sa test cases. Check mo paano ako nagname ng mga variables. Mas madali basahin ang code kapag may meaning yung variables mo.


C:
#include <stdio.h>
#include <stdlib.h>

const int X = 100;
const int Y = 100;

int isSpy(int personInQuestion, int people[X][Y], int row, int column)
{
    int counter = 0;
    for(int i = 0; i < row; i++)
    {
        for(int j = 0; j < column; j++)
        {
            if(people[i][j] == personInQuestion)
            {
                counter++;
            }
        }

        if(counter > 1)
        {
            return 0;
        }
    }

    return 1;
}
int main()
{
    int inputRow, inputColumn;
    int people[X][Y];
    int personInQuestion;

    printf("Enter the number of rows: ");
    scanf("%d", &inputRow);
    printf("Enter the number of columns: ");
    scanf("%d", &inputColumn);

    for(int i = 0; i < inputRow; i++)
    {
        for(int j = 0; j < inputColumn; j++)
        {
            scanf("%d", &people[i][j]);
            if(people[i][j] < 0 || people[i][j] > 10)
            {
                // Error
                return 0;
            }
        }
    }

    // Check if spy
    for(int i = 0; i < inputRow; i++)
    {
        for(int j = 0; j < inputColumn; j++)
        {
            personInQuestion = people[i][j];
            if(isSpy(personInQuestion, people, inputRow, inputColumn) == 1)
            {
                 printf("SPY");
                 return 0;
            }
        }
    }


    printf("NONE");
    return 0;
}
Paturo paps kung paano yung pagkuha ng output sa 2 dimensional array
 

Similar threads

Back
Top