Because this c++ code is a complete solution to my problem .
Unfortunately i cant see the logic of it.
and there are too many commands which are needed to be replaced.
and i now very little c++.
This is a discussion on help in transfoming C++ code into regular ansi C.. within the C Programming forums, part of the General Programming Boards category; Because this c++ code is a complete solution to my problem . Unfortunately i cant see the logic of it. ...
Because this c++ code is a complete solution to my problem .
Unfortunately i cant see the logic of it.
and there are too many commands which are needed to be replaced.
and i now very little c++.
And now you have erased everything C++, and all that's left is C. Yet you still struggle.
I'm just saying - I don't think this is a good idea!
If you have an assignment, why should you hunt for solutions when you should write the code yourself?
For information on how to enable C++11 on your compiler, look here.
よく聞くがいい！私は天才だからね！ ^_^
So, you happened to find this C++ program somewhere, and basically want to copy it, but you have to hand in a C program compilable under C90.Originally Posted by transgalactic2
Clearly, your assignment is not about transforming a C++ program into a C program, which was what I thought you were trying to do. I believe others who contributed to this thread thought the same. Rather, the aim was for you to develop a solution to the problem and implement it in C.
What you should be asking for is help in understanding the solution that you have found so that you can re-implement it in C. Mechanically translating the solution from C++ to C is tantamount to plagarism, and arguably as bad as finding a solution in C and handing it up as your own work. You may even be guilty of copyright infringement if you do not have permission to copy and make a derivative work.
C + C++ Compiler: MinGW port of GCC
Version Control System: Bazaar
Look up a C++ Reference and learn How To Ask Questions The Smart Way
It was written in c++ specifically for my problem.
I did not steal it.
I have built some thing close.
But it gives me the right a right pair numbers many times .
for input 54 it gives me 12 42 12 42 12 42 (it should give me only one pair) 12 42
and it doesnt give me the result for 53 52 .. 1
(whether they are a sum of two abounded numbers)
i tried to trace with a debugger but i cant see the problem
??
Code:#include <stdio.h> //////////////////////////////////////////////////////////////00000000 int main(){ int num; int index,tndex,kndex,jndex; int flag_1,flag_2,same_num; int sum; int smallest,smallest_ever,smallest_ever_2; sum=0; same_num=-1; smallest=-1; printf("enter number\n"); scanf("%d",&num); for(index=1;index<num;index++){ //start for main number flag_1=0; sum=0; flag_2=0; tndex=index; kndex=num-tndex; sum=0; for(jndex=1;jndex<tndex;jndex++){//start abbondence check for first num (tndex) if (tndex%jndex==0){ sum=sum+jndex; } if (tndex<sum){ flag_1=1; } }//end abbondence check for first num sum=0; for(jndex=1;jndex<kndex;jndex++){//start abbondence check for second num (kndex) if (kndex%jndex==0){ sum=sum+jndex; } if (kndex<sum){ flag_2=1; } }//end abbondence check for first num if ((flag_2==1)&&(flag_1==1)){ //start flag check if (kndex>=tndex){ smallest=tndex; if ((smallest<smallest_ever)&&(smallest>1)){ smallest_ever=smallest; smallest_ever_2=kndex; } } else { smallest=kndex; if ((smallest<smallest_ever)&&(smallest>1)){ smallest_ever=smallest; smallest_ever_2=tndex; } } printf("%d %d\n",smallest_ever,smallest_ever_2); } }//end flag check return 0; }//end main
Last edited by transgalactic2; 12-08-2008 at 03:53 AM.