Загрузка...

Convert code from C to C++

Thread in C/C++ created by CactusNode Nov 9, 2022. 171 view

  1. CactusNode
    CactusNode Topic starter Nov 9, 2022 Banned 4 Nov 2, 2022
    Code
    #include <stdio.h>

    void swap(float *x, float *y){
    *x=*x+*y;
    *y=*x-*y;
    *x=*x-*y;
    }

    void shiftright3(float *a, float *b, float *c){
    swap(a,b);
    swap(c,a);
    }

    int main(void)
    {
    int i;
    for (i=1;i<=2;++i){
    float a,b,c;
    printf("A:");
    scanf("%f", &a);
    printf("B:");
    scanf("%f", &b);
    printf("C:");
    scanf("%f", &c);

    shiftright3(&a,&b,&c);
    printf("A:%f; B:%f; C:%f\n",a,b,c);
    }
    return 0;
    }
     
  2. Celeste
    Celeste Nov 9, 2022 ♕Climbing for strawberries and finding myself...♕ 9694 Oct 26, 2021
    C
    #include <iostream>

    void shiftright3(float &a, float &b, float &c){
    std::swap(a, b);
    std::swap(c, a);
    }

    int main()
    {
    for (int i = 1; i <= 2; ++i)
    {
    float a, b, c;
    std::cout << "A:";
    std::cin >> a;
    std::cout << "B:";
    std::cin >> b;
    std::cout << "C:";
    std::cin >> c;
    shiftright3(a, b, c);
    std::cout << a << " " << b << " " << c << '\n';
    }
    return 0;
    }
     
    1. CactusNode Topic starter
Top
Loading...