From C++ to C
Jun 2, 2017 at 12:29am UTC
Hello everyone I am really unexperienced with C and more unexperienced with C++ I know this is really simple but I need to convert theese programs into C from C++ and would be really grateful if anybody would spend a minute to help in any way possible.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35
#include <iostream>
#include <iomanip>
#include <iostream>
#include <fstream>
using namespace std;
int main()
{
int A[1000];
int kiekis = 0;
for (int i = 0; 1000 > i; i++)
{
cin >> A[i];
if (A[i] == 0)
{
break ;
}
else
{
kiekis++;
}
}
for (int i = 0; kiekis > i; i+=2)
{
if (A[i] % 10 == 1)
{
cout << A[i];
}
}
return 0;
}
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42
#include <iostream>
#include <iomanip>
#include <iostream>
#include <fstream>
using namespace std;
int main()
{
int A[1000];
int kiekis = 0;
int pora = 0;
for (int i = 0; 1000 > i; i++)
{
cin >> A[i];
if (cin.get() == '\n' )
{
break ;
}
else
{
kiekis++;
}
}
for (int i = 0; kiekis > i; i++)
{
for (int j = i+1; kiekis > j; j++)
{
if (A[i] > 0 && A[j] > 0)
{
pora++;
}
}
}
cout << pora;
return 0;
}
Last edited on Jun 2, 2017 at 12:39am UTC
Jun 2, 2017 at 1:49am UTC
Just convert the input and output to C's input and output..
Dont forget to include stdio and stdlib
Also...why are you including fstream when you are not using it ?
Jun 2, 2017 at 2:05am UTC
How should i change the 2nd's code if(cin.get() == '\n')?
Im really lost in C++ and C actually so please im sorry for my incompetence
Jun 2, 2017 at 2:10am UTC
How should i change the 2nd's code if (cin.get() == '\n' )
?
The equivalent C code would be
if (getc(stdin) == '\n' )
Topic archived. No new replies allowed.