🔒 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

Fanatic
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

  • 120552577_386420819192668_257053896760541964_n.webp
    120552577_386420819192668_257053896760541964_n.webp
    24.3 KB · Views: 10
dapat meron kang lagayan ng highest number (tempNum)
tapos check saan array yung highest number then
swap ang lamang sa array next.
 
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

  • Screenshot from 2020-10-07 00-04-59.webp
    Screenshot from 2020-10-07 00-04-59.webp
    22.3 KB · Views: 8
Status
Not open for further replies.

About this Thread

  • 2
    Replies
  • 245
    Views
  • 3
    Participants
Last reply from:
homer_simpson

Online now

Members online
938
Guests online
3,169
Total visitors
4,107

Forum statistics

Threads
2,276,136
Posts
28,967,815
Members
1,231,128
Latest member
Dedegodskga
Back
Top