i've written these codes to evaluate a total heat transfer.but there are some problem arrived
#include<stdio.h>
#include<conio.h>
#include<stdlib.h>
int main()
{
int *temp,*thick,*area,*cond,total_temp,n,i;
double q,total_other;
temp=(int *)malloc(20 * sizeof(int));
thick=(int *)malloc(20 * sizeof(int));
area=(int *)malloc(20 * sizeof(int));
cond=(int *)malloc(20 * sizeof(int));
printf("how many slabs?");
scanf("%d",&n);
for(i=0;i<=n;i++){
scanf("%d",&temp[i]);
}
for(i=0;i<n;i++){
scanf(" %d %d %d",&thick[i],&area[i],&cond[i]);
}
for(i=0;i<=n;i++){
printf("temp[%d]=%d",i,temp[i]);
}
for(i=0;i<n;i++){
printf(" thick[%d]=%d,area[%d]=%d,cond[%d]=%d",i,thick[i],i,area[i],i,cond[i]);
}
store_temp=0;
for(i=0;i<n;i++){
total_temp=store_temp+(temp[i]-temp[i+1]);
}
store_other=0;
for(i=0;i<n;i++){
total_other=store_other+(thick[i]/(cond[i] * area[i]));
}
q = (store_temp/store_other);
printf("transfered heat, q = %f",q);
getch();
}
my first question is here-
for(i=0;i<n;i++){
printf(" thick[%d]=%d,area[%d]=%d,cond[%d]=%d",i,thick[i],i,area[i],i,cond[i]);
}
i've to write 'i' one after another to print my values.this is annoying.is there any shorter form to perform this task?
and the final 'q' is a double value.but its showing some abnormal values during compilation.why is that happening?
thanks!!!!