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.
(Escouse mee first version of program was
incorect becouse variable :"i" was seted to 1,
a true value is 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("\nEnter a number:");
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=0; //HERE WAS A ERROR
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));
}
}