Simple Triangle.. But 4 diff approach….

A program to draw like this….

*
**
***
****
*****
******

first:

#include<stdio.h>

int main()
{
int i, j, base = 10;

clrscr();

for(i = 0; i < base / 2; i++)
{
for(j = 0; j < base / 2 – i; j++)
printf(” “);
printf(“*”);
for(j = 0; j < i * 2 – 1; j++)
printf(” “);
if(i > 0)
printf(“*”);
printf(“\n”);
}

for(i = 0; i < base + 1; i++)
printf(“*”);

return 0;
}

 

second: 

#include<iostream.h>
#include<conio.h>
main()
{

int i,j,k;
for (i=0;i<6;i++)
{
for(j=0;j<i;j++)

cout<<”*”<<endl;

}
getch();
}

third:

void main()
{
int i, j, k, n;
clrscr();
printf(“\n enter the value of n:”);
scanf(“%d”,&n);

for(i=1;i<=n;++i)
{
for(j=1;j<=n-i;++j)
{
printf(” “);
}
for(k=1;k<=i;++k)
{
printf(“* “);
}
printf(“\n”);
}
getch();
}

four: 

int comb(int n,int r)
{
int C;
C=fact(n)/(fact(r) * fact(n-r));
return C;
}

C++ Online Test…

Test ur Knowledge of C++   Online Test……

Free online test of C++  www.itworld2.com   try it………..

What is Memory Leak???

When memory is allocated using malloc() in any function ,it returns a pointer to the start of the data………and again we free the memory using free() wit the help of pointer.but it should be used b4 we leave the function.n if it’s not used the pointer is lost and there is no way to clr the memory and it can never be used.
tis is called MEMORY LEAK………

For example:

#include<stdio.h>
#include<string.h>
int main()
{
char *ptr;
ptr = NULL;
ptr = strdup(“HI”);
printf(“\n%s”,ptr);
// free(ptr);
// ptr = NULL;
return 0;
}

It will show memory leak of 3 bytes.
now Uncomment the commented lines, no memory leak will be there.