Dear,
I wreated a small program that make a linked list of
factorials of numbers, I don't have expirience with
templates so I will bee thankfull if anybody can make
the same with templates(change my small program),
becouse I don't understand a templates.
Program is commpilled with Visual C++ 6.0.
Thanks in advance !
Robert !
// fact.cpp : Defines the entry point for the console application.
//
#include "stdafx.h"
#include<stdio.h>
#include<malloc.h>
int fact(int);
int main(int argc, char* argv[])
{ struct number{
int broj;
struct number *next;
};
struct number *first, *temp;
int k, i;
char c;
first=(struct number *)malloc(sizeof(struct number));
first->broj=1;
temp=(struct number *)malloc(sizeof(struct number));
first->next=temp;
printf("\nUnesite broj:");
scanf("%d",&k);
for(i=1;i<k;i++){
temp->next=(struct number *)malloc(sizeof(struct number));
// temp->broj=fact(k);
temp->broj=fact(i);
temp=temp->next;
temp->next=NULL;
// printf("\n%d!=%d",k,fact(k));
}
i=1;
temp=first;
while(temp->next){
printf("\n%d!=%d",i,temp->broj);
i++;
temp=temp->next;
}
c=getchar();
return 0;
}
int fact(int n){
if(n==1){
return 1;
}else{
return(n*fact(n-1));
}
} 5 1401
Robert Bralic wrote: Dear, I wreated a small program that make a linked list of factorials of numbers, I don't have expirience with templates so I will bee thankfull if anybody can make the same with templates(change my small program), becouse I don't understand a templates. Program is commpilled with Visual C++ 6.0.
Thanks in advance ! Robert ! // fact.cpp : Defines the entry point for the console application. //
#include "stdafx.h" #include<stdio.h> #include<malloc.h> int fact(int);
int main(int argc, char* argv[]) { struct number{ int broj; struct number *next; }; struct number *first, *temp; int k, i; char c; first=(struct number *)malloc(sizeof(struct number)); first->broj=1; temp=(struct number *)malloc(sizeof(struct number)); first->next=temp; printf("\nUnesite broj:"); scanf("%d",&k); for(i=1;i<k;i++){ temp->next=(struct number *)malloc(sizeof(struct number)); // temp->broj=fact(k); temp->broj=fact(i); temp=temp->next; temp->next=NULL; // printf("\n%d!=%d",k,fact(k)); } i=1; temp=first; while(temp->next){ printf("\n%d!=%d",i,temp->broj); i++; temp=temp->next; } c=getchar(); return 0; }
int fact(int n){ if(n==1){ return 1; }else{ return(n*fact(n-1)); } }
#include <list>
#include <iostream>
#include <algorithm>
unsigned int factorial ( unsigned int n ) {
if ( n <= 1 ) {
return( 1 );
} else {
return( n * factorial(n-1) );
}
}
typedef std::list< unsigned int > UintList;
int main ( void ) {
UintList uint_list;
unsigned int k;
std::cout << "\nUnesite broj: ";
std::cin >> k;
for ( unsigned int i = 1; i < k; ++i ) {
uint_list.push_back( factorial(i) );
}
k = 1; // WARNING: [re-using k]
for ( UintList::const_iterator iter = uint_list.begin();
iter != uint_list.end(); ++k, ++iter ) {
std::cout << '\n' << k << "! = " << *iter;
}
// getchar part not implemented.
}
Best
Kai-Uwe Bux
"Kai-Uwe Bux" <jk********@gmx.net> wrote in message
news:de**********@murdoch.acc.Virginia.EDU... Robert Bralic wrote:
Dear, I wreated a small program that make a linked list of factorials of numbers, I don't have expirience with templates so I will bee thankfull if anybody can make the same with templates(change my small program), becouse I don't understand a templates. Program is commpilled with Visual C++ 6.0.
Thanks in advance ! Robert ! // fact.cpp : Defines the entry point for the console application. //
#include "stdafx.h" #include<stdio.h> #include<malloc.h> int fact(int);
int main(int argc, char* argv[]) { struct number{ int broj; struct number *next; }; struct number *first, *temp; int k, i; char c; first=(struct number *)malloc(sizeof(struct number)); first->broj=1; temp=(struct number *)malloc(sizeof(struct number)); first->next=temp; printf("\nUnesite broj:"); scanf("%d",&k); for(i=1;i<k;i++){ temp->next=(struct number *)malloc(sizeof(struct number)); // temp->broj=fact(k); temp->broj=fact(i); temp=temp->next; temp->next=NULL; // printf("\n%d!=%d",k,fact(k)); } i=1; temp=first; while(temp->next){ printf("\n%d!=%d",i,temp->broj); i++; temp=temp->next; } c=getchar(); return 0; }
int fact(int n){ if(n==1){ return 1; }else{ return(n*fact(n-1)); } }
#include <list> #include <iostream> #include <algorithm>
unsigned int factorial ( unsigned int n ) { if ( n <= 1 ) { return( 1 ); } else { return( n * factorial(n-1) ); } }
typedef std::list< unsigned int > UintList; int main ( void ) { UintList uint_list; unsigned int k; std::cout << "\nUnesite broj: "; std::cin >> k; for ( unsigned int i = 1; i < k; ++i ) { uint_list.push_back( factorial(i) ); } k = 1; // WARNING: [re-using k] for ( UintList::const_iterator iter = uint_list.begin(); iter != uint_list.end(); ++k, ++iter ) { std::cout << '\n' << k << "! = " << *iter; } // getchar part not implemented. }
Best
Kai-Uwe Bux
Dear,
Sory yours version when I try to compile with Visual C++ 6.0, returns:
__________________________________________________ _____________
Deleting intermediate files and output files for project 'fact2_wt - Win32
Debug'.
--------------------Configuration: fact2_wt - Win32
Debug--------------------
Compiling...
StdAfx.cpp
Compiling...
fact2_wt.cpp
d:\robert\c\fact2_wt\fact2_wt.cpp(35) : fatal error C1010: unexpected end of
file while looking for precompiled header directive
Error executing cl.exe.
fact2_wt.exe - 1 error(s), 0 warning(s)
Robert Bralic wrote: "Kai-Uwe Bux" <jk********@gmx.net> wrote in message news:de**********@murdoch.acc.Virginia.EDU... Robert Bralic wrote:
> Dear, > I wreated a small program that make a linked list of > factorials of numbers, I don't have expirience with > templates so I will bee thankfull if anybody can make > the same with templates(change my small program), > becouse I don't understand a templates. > Program is commpilled with Visual C++ 6.0. > > Thanks in advance ! > Robert ! > // fact.cpp : Defines the entry point for the console application. > // > > #include "stdafx.h" > #include<stdio.h> > #include<malloc.h> > int fact(int); > > > int main(int argc, char* argv[]) > { struct number{ > int broj; > struct number *next; > }; > struct number *first, *temp; > int k, i; > char c; > first=(struct number *)malloc(sizeof(struct number)); > first->broj=1; > temp=(struct number *)malloc(sizeof(struct number)); > first->next=temp; > printf("\nUnesite broj:"); > scanf("%d",&k); > for(i=1;i<k;i++){ > temp->next=(struct number *)malloc(sizeof(struct number)); > // temp->broj=fact(k); > temp->broj=fact(i); > temp=temp->next; > temp->next=NULL; > // printf("\n%d!=%d",k,fact(k)); > } > i=1; > temp=first; > while(temp->next){ > printf("\n%d!=%d",i,temp->broj); > i++; > temp=temp->next; > } > c=getchar(); > return 0; > } > > int fact(int n){ > if(n==1){ > return 1; > }else{ > return(n*fact(n-1)); > } > }
#include <list> #include <iostream> #include <algorithm>
unsigned int factorial ( unsigned int n ) { if ( n <= 1 ) { return( 1 ); } else { return( n * factorial(n-1) ); } }
typedef std::list< unsigned int > UintList; int main ( void ) { UintList uint_list; unsigned int k; std::cout << "\nUnesite broj: "; std::cin >> k; for ( unsigned int i = 1; i < k; ++i ) { uint_list.push_back( factorial(i) ); } k = 1; // WARNING: [re-using k] for ( UintList::const_iterator iter = uint_list.begin(); iter != uint_list.end(); ++k, ++iter ) { std::cout << '\n' << k << "! = " << *iter; } // getchar part not implemented. }
Best
Kai-Uwe Bux
Dear,
Sory yours version when I try to compile with Visual C++ 6.0, returns: __________________________________________________ _____________ Deleting intermediate files and output files for project 'fact2_wt - Win32 Debug'. --------------------Configuration: fact2_wt - Win32 Debug-------------------- Compiling... StdAfx.cpp Compiling... fact2_wt.cpp d:\robert\c\fact2_wt\fact2_wt.cpp(35) : fatal error C1010: unexpected end of file while looking for precompiled header directive Error executing cl.exe.
fact2_wt.exe - 1 error(s), 0 warning(s)
I am sorry, but your compiler is broken. The code I gave is standard c++ and
will compile on any standard conforming compiler. Feel free to try it out
on http://www.comeaucomputing.com/tryitout/
Best
Kai-Uwe Bux
Kai-Uwe Bux wrote: Robert Bralic wrote:
"Kai-Uwe Bux" <jk********@gmx.net> wrote in message news:de**********@murdoch.acc.Virginia.EDU...
Robert Bralic wrote:
Dear, I wreated a small program that make a linked list of factorials of numbers, I don't have expirience with templates so I will bee thankfull if anybody can make the same with templates(change my small program), becouse I don't understand a templates. Program is commpilled with Visual C++ 6.0.
Thanks in advance ! Robert ! // fact.cpp : Defines the entry point for the console application. //
#include "stdafx.h" #include<stdio.h> #include<malloc.h> int fact(int);
int main(int argc, char* argv[]) { struct number{ int broj; struct number *next; }; struct number *first, *temp; int k, i; char c; first=(struct number *)malloc(sizeof(struct number)); first->broj=1; temp=(struct number *)malloc(sizeof(struct number)); first->next=temp; printf("\nUnesite broj:"); scanf("%d",&k); for(i=1;i<k;i++){ temp->next=(struct number *)malloc(sizeof(struct number)); // temp->broj=fact(k); temp->broj=fact(i); temp=temp->next; temp->next=NULL; // printf("\n%d!=%d",k,fact(k)); } i=1; temp=first; while(temp->next){ printf("\n%d!=%d",i,temp->broj); i++; temp=temp->next; } c=getchar(); return 0; }
int fact(int n){ if(n==1){ return 1; }else{ return(n*fact(n-1)); } }
#include <list> #include <iostream> #include <algorithm>
unsigned int factorial ( unsigned int n ) { if ( n <= 1 ) { return( 1 ); } else { return( n * factorial(n-1) ); } }
typedef std::list< unsigned int > UintList; int main ( void ) { UintList uint_list; unsigned int k; std::cout << "\nUnesite broj: "; std::cin >> k; for ( unsigned int i = 1; i < k; ++i ) { uint_list.push_back( factorial(i) ); } k = 1; // WARNING: [re-using k] for ( UintList::const_iterator iter = uint_list.begin(); iter != uint_list.end(); ++k, ++iter ) { std::cout << '\n' << k << "! = " << *iter; } // getchar part not implemented. }
Best
Kai-Uwe Bux
Dear,
Sory yours version when I try to compile with Visual C++ 6.0, returns: ________________________________________________ _______________ Deleting intermediate files and output files for project 'fact2_wt - Win32 Debug'. --------------------Configuration: fact2_wt - Win32 Debug-------------------- Compiling... StdAfx.cpp Compiling... fact2_wt.cpp d:\robert\c\fact2_wt\fact2_wt.cpp(35) : fatal error C1010: unexpected end of file while looking for precompiled header directive Error executing cl.exe.
fact2_wt.exe - 1 error(s), 0 warning(s)
I am sorry, but your compiler is broken. The code I gave is standard c++ and will compile on any standard conforming compiler. Feel free to try it out on
http://www.comeaucomputing.com/tryitout/
Best
Kai-Uwe Bux
[bit off topic as this is vc specific]
actually its not (or you cant say so by this error message only) ...
you need to disable precompiled header feature
Project => Settings => C/C++ | Category - Precompiled Headers
select "Not using precompiled headers"
Kyle <in*****@e.mail.com> wrote in message
news:de**********@nemesis.news.tpi.pl... Kai-Uwe Bux wrote: Robert Bralic wrote:
"Kai-Uwe Bux" <jk********@gmx.net> wrote in message news:de**********@murdoch.acc.Virginia.EDU...
Robert Bralic wrote:
>Dear, >I wreated a small program that make a linked list of >factorials of numbers, I don't have expirience with >templates so I will bee thankfull if anybody can make >the same with templates(change my small program), >becouse I don't understand a templates. >Program is commpilled with Visual C++ 6.0. > > Thanks in advance ! > Robert ! >// fact.cpp : Defines the entry point for the console application. >// > >#include "stdafx.h" >#include<stdio.h> >#include<malloc.h> >int fact(int); > > >int main(int argc, char* argv[]) >{ struct number{ > int broj; > struct number *next; > }; > struct number *first, *temp; > int k, i; > char c; > first=(struct number *)malloc(sizeof(struct number)); > first->broj=1; > temp=(struct number *)malloc(sizeof(struct number)); > first->next=temp; > printf("\nUnesite broj:"); > scanf("%d",&k); > for(i=1;i<k;i++){ > temp->next=(struct number *)malloc(sizeof(struct number)); > // temp->broj=fact(k); > temp->broj=fact(i); > temp=temp->next; > temp->next=NULL; > // printf("\n%d!=%d",k,fact(k)); > } > i=1; > temp=first; > while(temp->next){ > printf("\n%d!=%d",i,temp->broj); > i++; > temp=temp->next; > } > c=getchar(); > return 0; >} > >int fact(int n){ > if(n==1){ > return 1; > }else{ > return(n*fact(n-1)); > } >}
#include <list> #include <iostream> #include <algorithm>
unsigned int factorial ( unsigned int n ) { if ( n <= 1 ) { return( 1 ); } else { return( n * factorial(n-1) ); } }
typedef std::list< unsigned int > UintList; int main ( void ) { UintList uint_list; unsigned int k; std::cout << "\nUnesite broj: "; std::cin >> k; for ( unsigned int i = 1; i < k; ++i ) { uint_list.push_back( factorial(i) ); } k = 1; // WARNING: [re-using k] for ( UintList::const_iterator iter = uint_list.begin(); iter != uint_list.end(); ++k, ++iter ) { std::cout << '\n' << k << "! = " << *iter; } // getchar part not implemented. }
Best
Kai-Uwe Bux
Dear,
Sory yours version when I try to compile with Visual C++ 6.0, returns: ________________________________________________ _______________ Deleting intermediate files and output files for project 'fact2_wt -
Win32Debug'. --------------------Configuration: fact2_wt - Win32 Debug-------------------- Compiling... StdAfx.cpp Compiling... fact2_wt.cpp d:\robert\c\fact2_wt\fact2_wt.cpp(35) : fatal error C1010: unexpected
endof file while looking for precompiled header directive Error executing cl.exe.
fact2_wt.exe - 1 error(s), 0 warning(s)
I am sorry, but your compiler is broken. The code I gave is standard c++
and will compile on any standard conforming compiler. Feel free to try it
out on
http://www.comeaucomputing.com/tryitout/
Best
Kai-Uwe Bux
[bit off topic as this is vc specific]
actually its not (or you cant say so by this error message only) ... you need to disable precompiled header feature
Project => Settings => C/C++ | Category - Precompiled Headers
select "Not using precompiled headers"
Dear,
I am sory but my Compiler wasn't setted correctly,
now it works....
Thanks, Robert !! This thread has been closed and replies have been disabled. Please start a new discussion. Similar topics
by: Woodster |
last post by:
Further to a question I posted here recently about coding an xml rpeort
parser, I need to use a list of name/value pairs, in this case, a list
property names and values for a given tag.
Rather...
|
by: Shea Martin |
last post by:
Solaris 9, Sun Workshop 5.0
I have ObjectA.o, ObjectB.o. ObjectA.o uses std::list.
I created a archive of the objects: ar cvr libAB.a *.o.
I have example.cc which I am trying to compile...
|
by: Robert Bralic |
last post by:
Dear,
I wreated a small program that make a linked list of
factorials of numbers, I don't have expirience with
templates so I will bee thankfull if anybody can make
the same with...
|
by: darrel |
last post by:
I'm new to ASP in general. Have been doing a bunch of stuff using classic
ASP and a bit of stuff with ASP.NET (all with VBscript).
The .NET stuff i've been doing has been fairly...
|
by: ogerchikov |
last post by:
I have 2 classes, A, B and B is a child of A.
and I have a function which processes a list of A.
void func(list<A> alist) {
// processing list of A
}
The problem is func() won't able to...
|
by: Mark Stijnman |
last post by:
I am trying to teach myself template metaprogramming and I have been
trying to create lists of related types. I am however stuck when I want
to make a template that gives me the last type in a...
|
by: Philip Mueller |
last post by:
Hi,
I am using multiple stl::list s of different types.
Now I want to write a function
list<type>::iterator s_erase(list<typel, list<type>::iterator it)
that takes an iterator and deletes...
|
by: isliguezze |
last post by:
template <class T>
class List {
public:
List();
List(const List&);
List(int, const T&);
void push_back(const T &);
void push_front(const T &);
void pop_back();
|
by: QiongZ |
last post by:
Hi, I just recently started studying C++ and basically copied an example in the textbook into VS2008, but it doesn't compile. I tried to modify the code by eliminating all the templates then it...
|
by: Charles Arthur |
last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
|
by: emmanuelkatto |
last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud.
Please let me know.
Thanks!
Emmanuel
|
by: Sonnysonu |
last post by:
This is the data of csv file
1 2 3
1 2 3
1 2 3
1 2 3
2 3
2 3
3
the lengths should be different i have to store the data by column-wise with in the specific length.
suppose the i have to...
|
by: Hystou |
last post by:
There are some requirements for setting up RAID:
1. The motherboard and BIOS support RAID configuration.
2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
|
by: Hystou |
last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
|
by: jinu1996 |
last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
|
by: tracyyun |
last post by:
Dear forum friends,
With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
|
by: agi2029 |
last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
|
by: isladogs |
last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM).
In this session, we are pleased to welcome a new...
| |