What's new

Closed Hi guys need ko lang po tulong nyo about dito sa problem C++ yung problem po nasa picture

Status
Not open for further replies.

Social12

Honorary Poster
Joined
Feb 26, 2018
Posts
322
Reaction
22
Points
188
ito po yung code ko hindi ko na po alam kung paano yung last part

#include<stdio.h>
#include<conio.h>
int main()
{
int num[10]={0};
int ctr=0;

for(ctr=0; ctr<10; ctr++)
{
printf("Enter element of num[%d]:", ctr);
scanf("%d", &num[ctr]);
}

printf("\n*********Printing all the contents of the array\n");
for(ctr=0; ctr<10; ctr++)
{
printf("num[%d]=%d", ctr, num[ctr]);
printf("\n");
}

printf("*********Printing the contents excluding the highest number\n");
for(ctr=0; ctr<10; ctr++)
{
printf("num[%d]=%d", ctr, num[ctr]);
printf("\n");
}
if (ctr!=90){
printf("num[%d]=%d", ctr, num[ctr]);
}
return 0;
}
 

Attachments

dapat meron kang lagayan ng highest number (tempNum)
tapos check saan array yung highest number then
swap ang lamang sa array next.
 
Last edited:
simple, eto. Pero it contains questionable practices eg, not using functions, using scanf (scanf should be avoided at all cost), not using pointers, etc.

For demo lang ito,

C:
#include <stdio.h>
#define SIZE 10

struct st_index {
    int in;
    int value;
};

int main(int argc, char* argv[]) {
    int temp = 0;
    int index = 0;
    int arr[SIZE];
    for (int i=0; i<SIZE; i++) {
        arr[i] = 0;
    }

    printf("\nInitializing all array members to 0\n");
    for (int i=0; i<SIZE; i++) {
        arr[i] = 0;
    }
    printf("\n");

    printf("Now enter the array elements\n");
    for (int i=0; i<SIZE; i++) {
        int temp;
        printf("Enter num %d:  ", i+1);
        scanf("%d", &temp);
        arr[i] = temp;
    }

    for (int i=0; i<SIZE; i++) {
        if (arr[i] > arr[index]) {
            index = i;
        }
    }
    struct st_index myindex;
    myindex.in = index;
    myindex.value = arr[myindex.in];

    printf("\nKick the biggest number out and shift the numbers towards the left.\nThen filled the last element with 0\n\n");
    for (int i=0; i<SIZE; i++) {
        if (i==SIZE-1) {
            arr[i] = 0;
        } else if (i>=index) {
            arr[i] = arr[i+1];
        }
        printf("%d ", arr[i]);
    }
    printf("\n\nThe number %d at previous index %d has been kicked out\n\n", myindex.value, myindex.in);

    return 0;
}
 

Attachments

Last edited:
Status
Not open for further replies.

Similar threads

Back
Top