IN the following code i have taken input and after that i will take the same number of length,width and height of rectangular. But If I take n=3 then the number 1st and last shows right. but the others shows false..what can be edited???
The problem is when i > 1 and you do v[i] this will access memory outside the array, so you might actually be overwriting memory that belongs to other variables. This might cause problems or it might just work. You shouldn't rely on luck so better fix the problem.
#include<stdio.h>
#define N 50
main()
{
int i,n;
scanf("%d",&n);
while(n>0&&n<=N)
{
printf("please give a number between 1 and 50
scanf("%d",&n);
}
int h,l,w;
int v[N]={0};
for(i=0;i<n;i++)
{
scanf("%d%d%d",&h,&l,&w);
v[i]=h*l*w;
}
printf("\n");
for(i=0;i<n;i++)
{
printf("%d",v[i]);
printf("\n");
}
}
because as I see you are writing C not C++
however if you know about malloc you could use it to dynamically allocate v
Wait, if that's C code, why are you using new and delete?
And if that's C++ code, why are you using scanf, printf, #include <stdio.h> (instead of at the very least #include <cstdio> ), declaring main as main() instead of int main(), and declaring all of your variables at the beginning of the scope instead of when you need them?
Quick fix (assuming C):
-- Add #include <stdlib.h>
-- Change v= newint[n]; to v = (int*)malloc(n*sizeof(int));
-- Change delete [] v; to free(v);.
(I think -- I'm not a C programmer, so....)