❓ Help Help! C to C++ conversion.

Status
Not open for further replies.

joshiee15

Grasshopper
Patulong po pa-convert po nitong C language program sa C++ language. TIA
C:
#include <stdio.h>

void SortArray(int Size, int *parr)
{
    int i, j, temp;
    i = 0;

    while (i < Size)
    {
        j = i + 1;
        while (j < Size)
        {
            if (*(parr + j) < *(parr + i))
            {
                temp = *(parr + i);
                *(parr + i) = *(parr + j);
                *(parr + j) = temp;
            }
            j++;
        }
        i++;
    }
    printf("\nSorted Array Elements using Pointer = ");
    i = 0;
    while (i < Size)
    {
        printf("%d  ", *(parr + i));
        i++;
    }
}
void acceptArrayItems(int Size, int *parr)
{
    printf("\nPlease Enter %d elements of an Array = ", Size);

    int i = 0;
    while (i < Size)
    {
        scanf("%d", parr + i);
        i++;
    }
}
int main()
{
    int Size;

    printf("\nEnter Array Size to Sort using Pointers = ");
    scanf("%d", &Size);

    int arr[Size];
    acceptArrayItems(Size, arr);

    SortArray(Size, arr);
    printf("\n");
}
 
kung assignment lang use std namespace after include:

Code:
using namespace std;

then:
'scanf' to 'cin >>' (dont reference w/ '&')
'printf' to 'cout <<' (remove fmt specifier to printf)
 
Status
Not open for further replies.

About this Thread

  • 2
    Replies
  • 722
    Views
  • 3
    Participants
Last reply from:
fireclouu

Trending Topics

Online now

Members online
1,059
Guests online
1,021
Total visitors
2,080

Forum statistics

Threads
2,274,732
Posts
28,957,871
Members
1,233,410
Latest member
glennmart0525
Back
Top