Friday 23 September 2016

ASCII Character Codes


DecHexOctCharDescription
00000null
11001start of heading
22002start of text
33003end of text
44004end of transmission
55005enquiry
66006acknowledge
77007bell
88010backspace
99011horizontal tab
10A012new line
11B013vertical tab
12C014new page
13D015carriage return
14E016shift out
15F017shift in
1610020data link escape
1711021device control 1
1812022device control 2
1913023device control 3
2014024device control 4
2115025negative acknowledge
2216026synchronous idle
2317027end of trans. block
2418030cancel
2519031end of medium
261A032substitute
271B033escape
281C034file separator
291D035group separator
301E036record separator
311F037unit separator
3220040space
3321041!
3422042"
3523043#
3624044$
3725045%
3826046&
3927047'
4028050(
4129051)
422A052*
432B053+
442C054,
452D055-
462E056.
472F057/
48300600
49310611
50320622
51330633
52340644
53350655
54360666
55370677
56380708
57390719
583A072:
593B073;
603C074<
613D075=
623E076>
633F077?
6440100@
6541101A
6642102B
6743103C
6844104D
6945105E
7046106F
7147107G
7248110H
7349111I
744A112J
754B113K
764C114L
774D115M
784E116N
794F117O
8050120P
8151121Q
8252122R
8353123S
8454124T
8555125U
8656126V
8757127W
8858130X
8959131Y
905A132Z
915B133[
925C134\
935D135]
945E136^
955F137_
9660140`
9761141a
9862142b
9963143c
10064144d
10165145e
10266146f
10367147g
10468150h
10569151i
1066A152j
1076B153k
1086C154l
1096D155m
1106E156n
1116F157o
11270160p
11371161q
11472162r
11573163s
11674164t
11775165u
11876166v
11977167w
12078170x
12179171y
1227A172z
1237B173{
1247C174|
1257D175}
1267E176~
1277F177DEL

Matrix Transpose

/* Transpose the matrix */
#include<stdio.h>

int main()
{
int a[4][4],i,j,b;

for(i=0;i<4;i++)
{
printf("\nEnter elements of %d row of Matrix: ",i+1);
for(j=0;j<4;j++)
scanf("%d",&a[i][j]);
}

for(i=0;i<4;i++)
{
for(j=i+1;j<4;j++)
{
b=a[i][j];
a[i][j]=a[j][i];
a[j][i]=b;
}
}

printf("\nTransposed Matrix:\n\n");
for(i=0;i<4;i++)
{
for(j=0;j<4;j++)
printf("%4d",a[i][j]);
printf("\n");
}
return 0;
}

Sum of two Matrix

/* Sum of two Matrix */
#include<stdio.h>

int main()
{
int a[5][5],b[5][5],c[5][5];
int i,j;

for(i=0;i<5;i++)
{
printf("\nEnter elements of %d row of first Matrix: ",i+1);
for(j=0;j<5;j++)
scanf("%d",&a[i][j]);
}

for(i=0;i<5;i++)
{
printf("\nEnter elements of %d row of 2nd Matrix: ",i+1);
for(j=0;j<5;j++)
scanf("%d",&b[i][j]);
}

printf("\nSum of Matrix:\n\n");
for(i=0;i<5;i++)
{
for(j=0;j<5;j++)
{
c[i][j]=a[i][j]+b[i][j];
printf("%3d ",c[i][j]);
}
printf("\n");
}
return 0;
}

Matrix Multiplication

/* Matrix multiplication */
#include<stdio.h>

int main()
{
int arr1[3][3],arr2[3][3],arr3[3][3]={0},i,j,k;

printf("Type a matrix of 3 rows & 3 colomns :\n");
for(i=0;i<3;i++)
for(j=0;j<3;j++)
scanf("%d",&arr1[i][j]);

printf("Type another matrix of 3 rows & 3 colomns :\n");
for(i=0;i<3;i++)
for(j=0;j<3;j++)
scanf("%d",&arr2[i][j]);

for(i=0;i<3;i++)
{
for(j=0;j<3;j++)
{
for(k=0;k<3;k++)
arr3[i][j]=arr3[i][j]+arr1[i][k]*arr2[k][j];
}

}

printf("\n\nOutput:\n");
for(i=0;i<3;i++)
{
for(j=0;j<3;j++)
printf("%5d",arr3[i][j]);
printf("\n\n");
}

return 0;
}

Sort array of 10 strings

/* Sort array of 10 strings. */

#include<string.h>
#include<stdio.h>

int main()
{
int i,j;
char str[10][10],temp[10];
printf("Type 10 names :\n");
for(i=0;i<10;i++)
{
// gets(str[i]);
// fgets is a better option over gets to read multiword string .
fgets(str[i], 10, stdin);
}
for(i=0;i<10;i++)
{
for(j=0;j<10-1-i;j++)
{
if(strcmpi(str[j],str[j+1])>0)
{
strcpy(temp,str[j]);
strcpy(str[j],str[j+1]);
strcpy(str[j+1],temp);
}
}
}

printf("\nSorted Names :\n");
for(i=0;i<10;i++)
puts(str[i]);
return 0;
}

Insertion Sort

/* Insertion Sort */

#include<stdio.h>

int main()
{
int arr[10],i,j,new;
printf("Please enter 10 values:\n");
for(i=0;i<10;i++)
scanf("%d",&arr[i]);

for(i=1;i<10;i++)
{
new=a[i];
for(j=i-1;j>=0&&new<a[j];j--)
{
a[j+1]=a[j];
}
a[j+1]=new;
}

printf("Sorted Array is:\n");
for(i=0;i<10;i++)
printf("%d\n",arr[i]);

return 0;
}

Selection Sort

/* Selection Sort */

#include<stdio.h>

int main()
{
int arr[10],i,j,k,t;
printf("Please enter 10 values:\n");
for(i=0;i<10;i++)
scanf("%d",&arr[i]);

for(i=0;i<10;i++)
{
k=i;
for(j=i;j<10;j++)
{
if(a[k]>a[j])
k=j;
}
if(k!=i)
{
t=a[k];
a[k]=a[i];
a[i]=t;
}
}

printf("Sorted Array is:\n");
for(i=0;i<10;i++)
printf("%d\n",arr[i]);

return 0;
}

Bubble Sort

/* Bubble Sort */

#include<stdio.h>

int main()
{
int arr[10],i,j,t;
printf("Please enter 10 values:\n");
for(i=0;i<10;i++)
scanf("%d",&arr[i]);

for(i=0;i<9;i++)
{
for(j=0;j<9-i;j++)
{
if (arr[j]>arr[j+1])
{
t=arr[j];
arr[j]=arr[j+1];
arr[j+1]=t;
}
}
}

printf("Sorted Array is:\n");
for(i=0;i<10;i++)
printf("%d\n",arr[i]);

return 0;
}

Binary Search

/* Binary Search */

#include<stdio.h>

int main()
{
int arr[10],i,max,min,mid,val,index;

printf("Please enter 10 values in ascending order:\n");
for(i=0;i<10;i++)
scanf("%d",&arr[i]);

printf("\nEnter a value to be searched: ");
scanf("%d",&val);

max=9;
min=0;
index=-1;
while(min<=max)
{
mid=(max+min)/2;
if(val==arr[mid])
{
index=mid;
break;
}
if(arr[mid]>val)
max=mid-1;
else
min=mid+1;
}

if(index>=0)
printf("Value found in Array at %d location",index);
else
printf("Value not found in Array");
return 0;
}

File Copy using command line arguments

/* File Copy using command line arguments */

#include<stdio.h>
int main(int argc,char *argv[])
{
FILE *fs,*ft;
int ch;
if(argc!=3)
{
printf("Invalide numbers of arguments.");
return 1;
}
fs=fopen(argv[1],"r");
if(fs==NULL)
{
printf("Can't find the source file.");
return 1;
}
ft=fopen(argv[2],"w");
if(ft==NULL)
{
printf("Can't open target file.");
fclose(fs);
return 1;
}

while(1)
{
ch=fgetc(fs);
if (feof(fs)) break;
fputc(ch,ft);
}

fclose(fs);
fclose(ft);
return 0;
}

File to upper case using command line arguments

/* File to upper case using command line arguments */

#include<stdio.h>
int main(int n,char *a[])
{
int c;
FILE *fr,*fw;

if(n!=3)
{
printf("Invalide numbers of arguments.");
return 1;
}

if((fr=fopen(a[1],"r"))==NULL)
{
printf("File can't be open.");
return 1;
}
if((fw=fopen(a[2],"r+"))==NULL)
{
printf("File can't be open.");
fclose(fr);
return 1;
}
while(1)
{
c=fgetc(fr);
if(feof(fr)) break;
c=~c;
fputc(c,fw);
}
fclose(fr);
fclose(fw);
return 0;
}

Count characters of file

/* Count characters of file */

#include<stdio.h>
int main()
{
FILE *fp;
char a[10];
long cnt=0;
int c;

printf("Type a file name : ");
gets(a);

if((fp=fopen(a,"r"))==NULL)
printf("File dosen't exist.");
else
{
while(1)
{
c=fgetc(fp);
if(feof(fp)) break;
cnt++;
}
printf("\nfile have %ld characters",cnt);
}
fclose(fp);
return 0;
}

Write to text file

/* Write to text file */

#include<stdio.h>
int main()
{
FILE *fp;
char mystr[100];

fp=fopen("mytext.txt","w");
if(fp==NULL)
{
puts("Some error occured.");
return 1;
}

printf("\nEnter some lines:\n");
while(strlen(gets(mystr))>0)
{
fputs(mystr,fp);
fputs("\n",fp);
}
fclose(fp);
return 0;
}

Read text file

/* Read text file */

#include<stdio.h>
int main()
{
FILE *fp;
int ch;

fp=fopen("myfile.txt","r");
if(fp==NULL)
{
printf("Can't find the source file.");
return 1;
}
while(1)
{
ch=fgetc(fp);
if(feof(fp)) break;
printf("%c",ch);
}
fclose(fp);
return 0;
}

Towers of Hanoi by recursion

/* Towers of Hanoi by recursion */

#include<stdio.h>
void toh(int,char,char,char);

int main()
{
int n=3;
toh(n,'A','B','C');
return 0;
}

void toh(int n,char a,char b,char c)
{
if(n==1)
printf("\nMoved from %c to %c",a,c);
else
{
toh(n-1,a,c,b);
toh(1,a,' ',c);
toh(n-1,b,a,c);
}
}

Binary by recursion

/* Binary by recursion */

#include<stdio.h>
void binary(long);
int main()
{
long n;
printf("Type a value : ");
scanf("%ld",&n);
binary(n);
return 0;
}

void binary(long n)
{
if(n>1)
binary(n/2);
printf("%ld",n%2);
}

GCD by Recursion

/* greatest common divisor by recursion */
#include<stdio.h>
int gcd(int,int);

int main()
{
int a,b;
printf("Type 2 values to find GCD :\n");
scanf("%d %d",&a,&b);
printf("GCD : %d",gcd(a,b));
return 0;
}

int gcd(int m,int n)
{
if(n>m) return gcd(n,m);
if(n==0) return m;
return gcd(n,m%n);
}

 

Sum of digit by Recursion

/* Sum of digit by recursion */

#include<stdio.h>
int sod(int);

int main()
{
int i;
printf(" Type any value : ");
scanf("%d",&i);
printf("Sum of digit : %d",sod(i));
return 0;
}

int sod(int n)
{
if(n<1)
return 0;
return(n%10+sod(n/10));
}

Reverse by Recursion

/* Reverse by Recursion */

#include<stdio.h>
int rev(int,int);

int main()
{
int a;
printf("Type a value : ");
scanf("%d",&a);
printf("Reverse: %d",rev(a,0));
return 0;
}

int rev(int i,int r)
{
if(i > 0)
return rev(i/10,(r*10)+(i%10));
return r;
}

Fibonacci by Recursion

/* Fibonacci by Recursion */

#include<stdio.h>
int fib(int);

int main()
{
printf("Type any value : ");
printf("\nNth value: %d",fib(getche()-'0'));
return 0;
}

int fib(int n)
{
if(n<=1)
return n;
return(fib(n-1)+fib(n-2));
}

Power by Recursion

/* Power by Recursion */

#include<stdio.h>
int pow(int,int);

int main()
{
int i,j;
printf("Type two values : \n");
scanf("%d %d",&i,&j);

printf("i pow j = %d",pow(i,j));
return 0;
}

int pow(int i,int j)
{
if(j==1)
return i;
return (i*pow(i,j-1));
}

Factorial by Recursion

/* Factorial by Recursion */

#include<stdio.h>
int fact(int);

int main()
{
int n;
printf("Type any value : ");
scanf("%d",&n);
n=fact(n);
printf("\nFactorial : %d ",n);
return 0;
}

int fact(int x)
{
if(x==1)
return(x);
else
x=x*fact(x-1);
}

Series Program : 1 3 8 15 27 50 92 169 311

1 3 8 15 27 50 92 169 311
void main()
{
int a=1, b=3, c=4, n=10, sum, i;
printf("%d %d ",a,b,c);
for(i=4; i<=n; i++)
{
sum = a+b+c;
printf("%d ",sum);
a = b;
b = c;
c = sum;
}
}

Series Program : 2 15 41 80 132 197 275 366 470 587

2 15 41 80 132 197 275 366 470 587

 
int main()
{
int a=2,i,n=10;
for(i=1;i<=n;i++)
{
printf("%d ",a);
a+=13*i;
}
return 0;
}

Series Program : 1 2 3 6 9 18 27 54...

1 2 3 6 9 18 27 54...
int main()
{
int a=1,b=2,i,n=10;
printf("%d %d ",a, b);
for(i=3;i<=n;i++)
{
if(i%2==1)
{
a=a*3;
printf("%d ",a);
}
else
{
b=b*3;
printf("%d ",b);
}
}
return 0;
}

Series Program : 1/2 - 2/3 + 3/4 - 4/5 + 5/6 - ...... n

1/2 - 2/3 + 3/4 - 4/5 + 5/6 - ...... n
int main()
{
double i, n,sum=0;
n=10;
for(i=1;i<=n;i++)
{
if ((int)i%2==1)
sum+=i/(i+1);
else
sum-=i/(i+1);
}
printf("Sum: %lf",sum);
return 0;
}

Series Program : [(1^1)/1] + [(2^2)/2] + [(3^3)/3] + [(4^4)/4] + [(5^5)/5] + ... + [(n^n)/n]

[(1^1)/1] + [(2^2)/2] + [(3^3)/3] + [(4^4)/4] + [(5^5)/5] + ... + [(n^n)/n]
long power(int a, int b)
{
long i, p=1;
for(i=1;i<=b;i++)
{
p=p*a;
}
return p;
}

int main()
{
long i,n;
double sum=0;
n=5;
for(i=1;i<=n;i++)
{
sum=sum+(power(i,i)/i);
}
printf("Sum: %lf",sum);
return 0;
}

Series Program : (1!/1) + (2!/2) + (3!/3) + (4!/4) + (5!/5) + ... + (n!/n)

(1!/1) + (2!/2) + (3!/3) + (4!/4) + (5!/5) + ... + (n!/n)
long fact(int n)
{
long i, f=1;
for(i=1;i<=n;i++)
{
f=f*i;
}
return f;
}

int main()
{
long i,n;
double sum=0;
n=5;
for(i=1;i<=n;i++)
{
sum=sum+(fact(i)/i);
}
printf("Sum: %lf",sum);
return 0;
}

Series Program : (1^1) + (2^2) + (3^3) + (4^4) + (5^5) + ... + (n^n)

(1^1) + (2^2) + (3^3) + (4^4) + (5^5) + ... + (n^n)
long power(int a, int b)
{
long i, p=1;
for(i=1;i<=b;i++)
{
p=p*a;
}
return p;
}

int main()
{
long i,n,sum=0;
n=5;
for(i=1;i<=n;i++)
{
sum=sum+power(i,i);
}
printf("Sum: %d",sum);
return 0;
}

Series Program : 1! + 2! + 3! + 4! + 5! + ... + n!

1! + 2! + 3! + 4! + 5! + ... + n!
long fact(int n)
{
long i, f=1;
for(i=1;i<=n;i++)
{
f=f*i;
}
return f;
}

int main()
{
long i,n,sum=0;
n=5;
for(i=1;i<=n;i++)
{
sum=sum+fact(i);
}
printf("Sum: %d",sum);
return 0;
}

Series Program : (1) + (1+2) + (1+2+3) + (1+2+3+4) + ... + (1+2+3+4+...+n)

(1) + (1+2) + (1+2+3) + (1+2+3+4) + ... + (1+2+3+4+...+n)
int main()
{
int i,j,n,sum=0;
n=10;
for(i=1;i<=n;i++)
{
for(j=1;j<=i;j++)
{
sum+=j;
}
}
printf("Sum: %d",sum);
return 0;
}

Series Program : (1*1) + (2*2) + (3*3) + (4*4) + (5*5) + ... + (n*n)

(1*1) + (2*2) + (3*3) + (4*4) + (5*5) + ... + (n*n)
int main()
{
int i,n,sum=0;
n=10;
for(i=1;i<=n;i++)
{
sum+=i*i;
}
printf("Sum: %d",sum);
return 0;
}

series program : 1 + 2 + 3 + 4 + 5 + ... + n

1 + 2 + 3 + 4 + 5 + ... + n
int main()
{
int i,n,sum=0;
n=10;
for(i=1;i<=n;i++)
{
sum+=i;
}
printf("Sum: %d",sum);
return 0;
}

Alphabet pattern : ABCDE ABCD ABC AB A

ABCDE
ABCD
ABC
AB
A


#include <stdio.h>

int main()
{
int i, j;
for(i=5;i>=1;i--)
{
for(j=1;j<=i;j++)
{
printf("%c",'A' + j-1);
}
printf("\n");
}

return 0;
}

Alphabet pattern : ABCDE BCDE CDE DE E

ABCDE
BCDE
CDE
DE
E


#include <stdio.h>

int main()
{
int i, j;
for(i=1;i<=5;i++)
{
for(j=i;j<=5;j++)
{
printf("%c", 'A'-1 + j);
}
printf("\n");
}

return 0;
}

Alphabet pattern : EDCBA DCBA CBA BA A

EDCBA
DCBA
CBA
BA
A


#include <stdio.h>

int main()
{
int i, j;
for(i=5;i>=1;i--)
{
for(j=i;j>=1;j--)
{
printf("%c",'A'-1 + j);
}
printf("\n");
}

return 0;
}

Alphabet pattern : EDCBA EDCB EDC ED E

EDCBA
EDCB
EDC
ED
E


#include <stdio.h>

int main()
{
int i, j;
for(i=1;i<=5;i++)
{
for(j=5;j>=i;j--)
{
printf("%c",'A'-1 + j);
}
printf("\n");
}

return 0;
}

Alphabet pattern : A BB CCC DDDD EEEEE

A
BB
CCC
DDDD
EEEEE


#include <stdio.h>

int main()
{
int i, j;
for(i=1;i<=5;i++)
{
for(j=1;j<=i;j++)
{
printf("%c",'A'-1 + i);
}
printf("\n");
}

return 0;
}

Alphabet pattern : E DD CCC BBBB AAAAA

E
DD
CCC
BBBB
AAAAA


#include <stdio.h>

int main()
{
int i, j;
for(i=5;i>=1;i--)
{
for(j=5;j>=i;j--)
{
printf("%c",'A'-1 + i);
}
printf("\n");
}

return 0;
}

Alphabet pattern : EEEEE DDDD CCC BB A

EEEEE
DDDD
CCC
BB
A


#include <stdio.h>

int main()
{
int i, j;
for(i=5;i>=1;i--)
{
for(j=1;j<=i;j++)
{
printf("%c",'A'-1 + i);
}
printf("\n");
}

return 0;
}

Alphabet pattern : AAAAA BBBB CCC DD E

AAAAA
BBBB
CCC
DD
E


#include <stdio.h>

int main()
{
int i, j;
for(i=1;i<=5;i++)
{
for(j=5;j>=i;j--)
{
printf("%c",'A'-1 + i);
}
printf("\n");
}

return 0;
}

Alphabet pattern : A AB ABC ABCD ABCDE

A
AB
ABC
ABCD
ABCDE


#include <stdio.h>

int main()
{
int i, j;
for(i=1;i<=5;i++)
{
for(j=1;j<=i;j++)
{
printf("%c",'A' + j-1);
}
printf("\n");
}

return 0;
}

Alphabet pattern : E DE CDE BCDE ABCDE

E
DE
CDE
BCDE
ABCDE


#include <stdio.h>

int main()
{
int i, j;
for(i=5;i>=1;i--)
{
for(j=i;j<=5;j++)
{
printf("%c",'A' + j-1);
}
printf("\n");
}

return 0;
}

Alphabet Pattern : A BA CBA DCBA EDCBA

A
BA
CBA
DCBA
EDCBA


#include <stdio.h>

int main()
{
int i, j;
for(i=1;i<=5;i++)
{
for(j=i;j>=1;j--)
{
printf("%c",'A' + j-1);
}
printf("\n");
}

return 0;
}

Alphabet Pattern E ED EDC EDCB EDCBA

E
ED
EDC
EDCB
EDCBA


#include <stdio.h>

int main()
{
int i, j;
for(i=5;i>=1;i--)
{
for(j=5;j>=i;j--)
{
printf("%c",'A' + j-1);
}
printf("\n");
}

return 0;
}

Tuesday 20 September 2016

Star Pattern : Pure Diamond

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

CODE : Awesome Logic :

int main()
{
int i, j;

for(i=1; i<=5; i++)
{
for(j=5; j>i; j--)
{
printf(" ");
}
printf("*");
for(j=1; j<(i-1)*2; j++)
{
printf(" ");
}
if(i==1) printf("\n");
else printf("*\n");
}

for(i=4; i>=1; i--)
{
for(j=5; j>i; j--)
{
printf(" ");
}
printf("*");
for(j=1; j<(i-1)*2; j++)
{
printf(" ");
}
if(i==1) printf("\n");
else printf("*\n");
}

return 0;
}

Star Pattern : top left edge diamond

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

#include <stdio.h>

int main()
{
int i, j;
for(i=1;i<=5;i++)
{
for(j=1;j<=i;j++)
{
printf("*");
}
printf("\n");
}

return 0;
}

Star pattern : Top right edge diamond

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


#include <stdio.h>

int main()
{
int i, j, k;
for(i=5;i>=1;i--)
{
for(j=1;j<i;j++)
{
printf(" ");
}
for(k=5;k>=i;k--)
{
printf("*");
}
printf("\n");
}

return 0;
}

Star Pattern : bottom left edge diamond

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


#include <stdio.h>

int main()
{
int i, j;
for(i=5;i>=1;i--)
{
for(j=1;j<=i;j++)
{
printf("*");
}
printf("\n");
}

return 0;
}

Star Pattern : bottom right edge diamond

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


#include <stdio.h>

int main()
{
int i, j, k;
for(i=5;i>=1;i--)
{
for(j=5;j>i;j--)
{
printf(" ");
}
for(k=1;k<=i;k++)
{
printf("*");
}
printf("\n");
}

return 0;
}

Star Pattern : Half Diamond

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

#include <stdio.h>

int main()
{
int i, j, k;
for(i=1;i<=5;i++)
{
for(j=i;j<5;j++)
{
printf(" ");
}
for(k=1;k<(i*2);k++)
{
printf("*");
}
printf("\n");
}

return 0;
}

Star Pattern : Bottom half Diamond

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

#include <stdio.h>

int main()
{
    int i, j, k;
    for(i=5;i>=1;i--)
    {
        for(j=5;j>i;j--)
        {
                printf(" ");
        }
        for(k=1;k<(i*2);k++)
        {
                printf("*");
        }
        printf("\n");
    }

    return 0;
}

Star Pattern : Diamond

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

CODE :
#include <stdio.h>

int main()
{
int i, j, k;
for(i=1;i<=5;i++)
{
for(j=i;j<5;j++)
{
printf(" ");
}
for(k=1;k<(i*2);k++)
{
printf("*");
}
printf("\n");
}
for(i=4;i>=1;i--)
{
for(j=5;j>i;j--)
{
printf(" ");
}
for(k=1;k<(i*2);k++)
{
printf("*");
}
printf("\n");
}

return 0;


Star Pattern : Hollow Diamond

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

CODE:

#include <stdio.h>

int main()
{
int i, j, k;
for(i=1;i<=5;i++)
{
for(j=1;j<=6-i;j++)
{
printf("*");
}
for(k=1;k<i;k++)
{
printf(" ");
}
for(j=1;j<=6-i;j++)
{
printf("*");
}
printf("\n");
}
for(i=2;i<=5;i++)
{
for(j=1;j<=i;j++)
{
printf("*");
}
for(k=1;k<=5-i;k++)
{
printf(" ");
}
for(j=1;j<=i;j++)
{
printf("*");
}
printf("\n");
}

return 0;
}

Sunday 18 September 2016

Number pattern : Pyramid of square of 1 to 25

                  1  
4 9 16
25 36 49 64 81
100 121 144 169 196 225 256
289 324 361 400 441 484 529 576 625

#include<stdio.h>

int main()
{
int i, j, k=1;
for(i=1;i<=5;i++)
{
for(j=i;j<5;j++)
{
printf(" ");
}
for(j=1;j<(i*2);j++)
{
printf("%3d ",k*k);
k++;
}
printf("\n");
}
return 0;
}

Number pattern : rectangle of 1

11111
1 1
1 1
1 1
11111



#include<stdio.h>

int main()
{
int i,j;
for(i=1;i<=5;i++)
{
for(j=1;j<=5;j++)
{
if(j==5 || j==1 || i==1 || i==5)
printf("1");
else
printf(" ");
}
printf("\n");
}
return 0;
}

Number pattern : Stuff Diamond

    1
123
12345
1234567
123456789
1234567
12345
123
1

CODE:
#include<stdio.h>

int main()
{
int i, j, k;
for(i=1;i<=5;i++)
{
for(j=i;j<5;j++)
{
printf(" ");
}
for(k=1;k<(i*2);k++)
{
printf("%d",k);
}
printf("\n");
}
for(i=4;i>=1;i--)
{
for(j=5;j>i;j--)
{
printf(" ");
}
for(k=1;k<(i*2);k++)
{
printf("%d",k);
}
printf("\n");
}
return 0;
}

middle Pyramid number pattern

    1 
1 2
1 2 3
1 2 3 4
1 2 3 4 5

#include<stdio.h>

int main()
{
int i,j;
for(i=1;i<=5;i++)
{
for(j=5;j>i;j--)
{
printf(" ");
}
for(j=1;j<=i;j++)
{
printf("%d ",j);
}
printf("\n");
}
return 0;
}

Pyramid top view using 1 to 5

5 5 5 5 5 5 5 5 5 
5 4 4 4 4 4 4 4 5
5 4 3 3 3 3 3 4 5
5 4 3 2 2 2 3 4 5
5 4 3 2 1 2 3 4 5
5 4 3 2 2 2 3 4 5
5 4 3 3 3 3 3 4 5
5 4 4 4 4 4 4 4 5
5 5 5 5 5 5 5 5 5

int main()
{
int i, j, n=5;

for(i=n; i>1; i--)
{
for(j=n;j>=1;j--)
{
if(j>i) printf("%d ", j);
else printf("%d ", i);
}
for(j=2;j<=n;j++)
{
if(j>i) printf("%d ", j);
else printf("%d ", i);
}
printf("\n");
}
for(i=1; i<=n; i++)
{
for(j=n;j>=1;j--)
{
if(j>i) printf("%d ", j);
else printf("%d ", i);
}
for(j=2;j<=n;j++)
{
if(j>i) printf("%d ", j);
else printf("%d ", i);
}
printf("\n");
}

return 0;
}

1 to 100 : Left edge pyramid : number pattern

1
2 4
3 6 9
4 8 12 16
5 10 15 20 25
6 12 18 24 30 36
7 14 21 28 35 42 49
8 16 24 32 40 48 56 64
9 18 27 36 45 54 63 72 81
10 20 30 40 50 60 70 80 90 100

int main()
{
int i,j;
for(i=1;i<=10;i++)
{
for(j=1;j<=i;j++)
{
printf("%d ",i*j);
}
printf("\n");
}
return 0;
}

Number pattern : X

1     1
2 2
3 3
4
3 3
2 2
1 1

CODE

int main()
{
int i,j,k=1;
int m[7][7]={0};
for(i=1;i<=7;i++)
{
for(j=1;j<=7;j++)
if(j==i || 8-i==j)
m[i-1][j-1]=k;
if(i<4) k++;
else --k;

}
for(i=0;i<7;i++)
{
for(j=0;j<7;j++)
{
if(m[i][j]==0)
printf(" ");
else
printf("%d",m[i][j]);
}
printf("\n");
}
return 0;
}

number pattern : diamond

      1
2 2
3 3
4 4
3 3
2 2
1


Code:

int main()
{
int i,j,k;
for(i=1;i<=4;i++)
{
for(j=4;j>=(i-1)*2-1;j--)
printf(" ");
printf("%d",i);
for(j=2;j<=(i-1)*4;j++)
printf(" ");
if(i>1)
printf("%d",i);
printf("\n");
}
for(i=3;i>=1;i--)
{
for(j=4;j>=(i-1)*2-1;j--)
printf(" ");
printf("%d",i);
for(j=2;j<=(i-1)*4;j++)
printf(" ");
if(i>1)
printf("%d",i);
printf("\n");
}
return 0;
}

Square number pattern 1 to 16

1  2  3  4  5  
16 6
15 7
14 8
13 12 11 10 9

CODE

int main()
{
int i,j,k=6,l=13,m=16;
for(i=1;i<=5;i++)
{
for(j=1;j<=5;j++)
{
if(i==1)
printf("%-3d",j);
else if(j==5)
printf("%-3d",k++);
else if(i==5)
printf("%-3d",l--);
else if(j==1)
printf("%-3d",m--);
else
printf(" ");
}
printf("\n");
}
return 0;
}



Number pattern N=39714

N=39714

3 9 1 7 4
9 1 7 4
1 7 4
7 4
4

code:

#include <stdio.h>

int main()
{
long n = 39714, i=1;
for(i=10;i<n;i*=10);

for (i=i/10; n>0; i/=10)
{
printf("%d\n", n);
n%=i;
}

return 0;
}



Number pattern :- 1, 23, 456, 78910

1
23
456
78910

#include<stdio.h>
int main()
{
int i,j,k;
k=1;
for(i=1;i<5;i++)
{
for(j=1;j<=i;j++)
{
printf("%d",k++);
}
printf("\n");
}
return 0;
}

Number pattern 1 10 101 1010 10101

1
10
101
1010
10101

#include<stdio.h>
int main()
{
int i,j,k;
for(i=1;i<=5;i++)
{
for(j=1;j<=i;j++)
{
printf("%d",j%2);
}
printf("\n");
}
return 0;
}

left edge pyramid number pattern

1
123
12345
1234567

#include<stdio.h>
void main()
{
int i,j;
for(i=1;i<=7;i+=2)
{
for(j=1;j<=i;j++)
{
printf("%d",j);
}
printf("\n");
}
return 0;
}

Number pattern : left edge pyramid

1 
2 6
3 7 10
4 8 11 13
5 9 12 14 15

#include<stdio.h>
int main()
{
int i,j,k;
for(i=1;i<=5;i++)
{
k = i;
for(j=1;j<=i;j++)
{
printf("%d ", k);
k += 5-j;
}
printf("\n");
}
return 0;
}

Number pattern : Pyramid star and Numbers

12344321
123**321
12****21
1******1

#include<stdio.h>
int main()
{
int i,j,k;
for(i=4;i>=1;i--)
{
for(j=1;j<=4;j++)
{
if(j<=i)
printf("%d",j);
else
printf(" ");
}
for(j=4;j>=1;j--)
{
if(j<=i)
printf("%d",j);
else
printf(" ");
}
printf("\n");
}
return 0;
}

Number pattern pyramid

    1
2 3 4
5 6 7 8 9

#include<stdio.h>
int main()
{
int i,j,k;
k=1;
for(i=1;i<=5;i+=2)
{
for(j=5;j>=1;j--)
{
if(j>i)
printf(" ");
else
printf("%d ",k++);
}
printf("\n");
}
return 0;
}

number pattern : a perfect square

1   2   3   4   5   6   7   8   9   10
36 37 38 39 40 41 42 43 44 11
35 64 65 66 67 68 69 70 45 12
34 63 84 85 86 87 88 71 46 13
33 62 83 96 97 98 89 72 47 14
32 61 82 95 100 99 90 73 48 15
31 60 81 94 93 92 91 74 49 16
30 59 80 79 78 77 76 75 50 17
29 58 57 56 55 54 53 52 51 18
28 27 26 25 24 23 22 21 20 19

 
#include<stdio.h>

int main()
{
int a[10][10]={0},i,j,low=0,top=9,n=1;
for(i=0;i<5;i++,low++,top--)
{
for(j=low;j<=top;j++,n++)
a[i][j]=n;
for(j=low+1;j<=top;j++,n++)
a[j][top]=n;
for(j=top-1;j>=low;j--,n++)
a[top][j]=n;
for(j=top-1;j>low;j--,n++)
a[j][low]=n;
}
printf("\t\t\t\tPerfect Square\n");
for(i=0;i<10;i++)
{
printf("\n\n\t");
for(j=0;j<10;j++)
{
printf("%6d",a[i][j]);
delay(300);
}
}
return 0;
}

 

Number pattern double verticle pyramids

1        1
12 21
123 321
1234 4321
1234554321

#include<stdio.h>

int main()
{
int i,j,k;
for(i=1;i<=5;i++)
{
for(j=1;j<=5;j++)
{
if(j<=i)
printf("%d",j);
else
printf(" ");
}
for(j=5;j>=1;j--)
{
if(j<=i)
printf("%d",j);
else
printf(" ");
}
printf("\n");
}
return 0;
}

Number pattern horizontal pyramid

1
2*2
3*3*3
4*4*4*4
4*4*4*4
3*3*3
2*2
1
#include<stdio.h>
int main()
{
int i,j;
for(i=1;i<=4;i++)
{
for(j=1;j<=i;j++)
{
if(j<i)
printf("%d*",i);
else
printf("%d",i);
}
printf(" \n");
}
for(i=4;i>=1;i--)
{
for(j=1;j<=i;j++)
{
if(j<i)
printf("%d*",i);
else
printf("%d",i);
}
printf(" \n");
}
return 0;
}

Number pattern 1 22 333 4444 55555

1
22
333
4444
55555

#include <stdio.h>

int main()
{
int i, j;
for(i=1;i<=5;i++)
{
for(j=1;j<=i;j++)
{
printf("%d",i);
}
printf("\n");
}

return 0;
}

Number pattern 5 44 333 2222 11111

5
44
333
2222
11111

#include <stdio.h>

int main()
{
int i, j;
for(i=5;i>=1;i--)
{
for(j=5;j>=i;j--)
{
printf("%d",i);
}
printf("\n");
}

return 0;
}

Number pattern 55555 4444 333 22 1

55555
4444
333
22
1

#include <stdio.h>

int main()
{
int i, j;
for(i=5;i>=1;i--)
{
for(j=1;j<=i;j++)
{
printf("%d",i);
}
printf("\n");
}

return 0;
}

Number Pattern 11111 2222 333 44 5

11111
2222
333
44
5

#include <stdio.h>

int main()
{
int i, j;
for(i=1;i<=5;i++)
{
for(j=5;j>=i;j--)
{
printf("%d",i);
}
printf("\n");
}

return 0;
}

Number Pattern 12345 4321 123 21 1

12345
4321
123
21
1

int main()
{
int i,j,k;
for(i=5;i>=1;i--)
{
if(i%2==1) k=1;
else k=i;
for(j=1;j<=i;j++)
{
printf("%d",k);
if(i%2==1) k++;
else k--;
}
printf("\n");
}
return 0;
}

Number Pattern 1234567 12345 123 1

1234567
12345
123
1

int main()
{
int i,j;
for(i=7;i>=1;i-=2)
{
for(j=1;j<=i;j++)
{
printf("%d",j);
}
printf("\n");
}
return 0;
}

Number Pattern 1 01 101 0101

1
01
101
0101

#include <stdio.h>
int main()
{
int i, j;
for(i=1;i<=4;i++)
{
for(j=i;j>=1;j--)
{
printf("%d",j%2);
}
printf("\n");
}
return 0;
}

Number Pattern 13579 3579 579 79 9

13579
3579
579
79
9

#include <stdio.h>
int main()
{
int i,j;
for(i=1;i<=9;i+=2)
{
for(j=i;j<=9;j+=2)
{
printf("%d",j);
}
printf("\n");
}
return 0;
}

Number Pattern 1, 2 4,1 3 5, 2 4 6 8, 1 3 5 7 9

1
2 4
1 3 5
2 4 6 8
1 3 5 7 9

#include<stdio.h>
int main()
{
int i,j,k;
for(i=1;i<=5;i++)
{
if(i%2==0)
{
k=2;
}
else
{
k=1;
}
for(j=1;j<=i;j++,k+=2)
{
printf("%d ", k);
}
printf("\n");
}
return 0;
}

Number Pattern 55555 45555 34555 23455 12345

55555
45555
34555
23455
12345

int main()
{
int i, j, k;
for(i=5;i>=1;i--)
{
k = i;
for(j=1;j<=5;j++)
{
if(k <= 5)
{
printf("%d",k);
}
else
{
printf("5");
}
k++;
}
printf("\n");
}
return 0;
}

Number Pattern 12345 2345 345 45 5

12345
2345
345
45
5

code:

#include <stdio.h>

int main()
{
int i, j;
for(i=1;i<=5;i++)
{
for(j=i;j<=5;j++)
{
printf("%d",j);
}
printf("\n");
}

return 0;
}

Number Pattern 54321 4321 321 21 1

54321
4321
321
21
1

CODE:
#include <stdio.h>

int main()
{
int i, j;
for(i=5;i>=1;i--)
{
for(j=i;j>=1;j--)
{
printf("%d",j);
}
printf("\n");
}

return 0;
}

Number Pattern 54321 5432 543 54 5

54321
5432
543
54
5

CODE:

#include <stdio.h>

int main()
{
    int i, j;
    for(i=1;i<=5;i++)
    {
        for(j=5;j>=i;j--)
        {
            printf("%d",j);
        }
        printf("\n");
    }

    return 0;
}

Number Pattern 1 12 123 1234 12345

1
12
123
1234
12345

Code;

#include <stdio.h>

int main()
{
    int i, j;
    for(i=1;i<=5;i++)
    {
        for(j=1;j<=i;j++)
        {
            printf("%d",j);
        }
        printf("\n");
    }

    return 0;
}

Number Pattern 5 45 345 2345 12345

5
45
345
2345
12345

CODE:
#include <stdio.h>

int main()
{
int i, j;
for(i=5;i>=1;i--)
{
for(j=i;j<=5;j++)
{
printf("%d",j);
}
printf("\n");
}

return 0;
}

Number Pattern 1 21 321 4321 54321

1
21
321
4321
54321

CODE:
#include <stdio.h>

int main()
{
int i, j;
for(i=1;i<=5;i++)
{
for(j=i;j>=1;j--)
{
printf("%d",j);
}
printf("\n");
}

return 0;
}

Number Pattern 5 54 543 5432 54321

5
54
543
5432
54321

CODE : 
#include <stdio.h>

int main()
{
int i, j;
for(i=5;i>=1;i--)
{
for(j=5;j>=i;j--)
{
printf("%d",j);
}
printf("\n");
}

return 0;
}

Number Pattern - 12345 1234 123 12 1

12345
1234
123
12
1

Code : 
#include <stdio.h>

int main()
{
int i, j;
for(i=5;i>=1;i--)
{
for(j=1;j<=i;j++)
{
printf("%d",j);
}
printf("\n");
}

return 0;
}

Saturday 17 September 2016

File or image store into database by gwt

GreetingService.java


package com.client;


import com.google.gwt.user.client.rpc.RemoteService;


importcom.google.gwt.user.client.rpc.RemoteServiceRelativePath;


/**


 * The client side stub for the RPC service.


 */


@RemoteServiceRelativePath("greet")


public interface GreetingService extends RemoteService {


      String upload(String topic, String stream, String Tag, String plink, String fpath );


}


               


GreetinServiceAsync.java


package com.client;


import com.google.gwt.user.client.rpc.AsyncCallback;


/**


 * The async counterpart of <code>GreetingService</code>.


 */


public interface GreetingServiceAsync 
{


  void upload(String topic, String stream, String Tag, String plink, String fpath, AsyncCallback<String> callback );



}


TestExample.java


package com.client;


import com.google.gwt.core.client.EntryPoint;


import com.google.gwt.core.client.GWT;


import com.google.gwt.event.dom.client.ClickEvent;


import com.google.gwt.event.dom.client.ClickHandler;


import com.google.gwt.user.client.Window;


import com.google.gwt.user.client.rpc.AsyncCallback;


import com.google.gwt.user.client.ui.AbsolutePanel;


import com.google.gwt.user.client.ui.Button;


import com.google.gwt.user.client.ui.FileUpload;


import com.google.gwt.user.client.ui.Label;


import com.google.gwt.user.client.ui.ListBox;


import com.google.gwt.user.client.ui.RootPanel;


import com.google.gwt.user.client.ui.TextBox;


/**


 * Entry point classes define <code>onModuleLoad()</code>.


 */


public class TestExample implements EntryPoint


{


private final GreetingServiceAsync a1 = GWT.create(GreetingService.class);


        RootPanel rt;


        AbsolutePanel absolutePanel;


        TextBox textBox;


        ListBox comboBox;


        TextBox textBox_1;


        TextBox textBox_2;


        FileUpload fileUpload;


        Button button;


        String s1,s2,s3,s4,s5;


      public void onModuleLoad()


      {



              rt=RootPanel.get();



              absolutePanel = new AbsolutePanel();


              rt.add(absolutePanel, 218, 24);


              absolutePanel.setSize("445px", "434px");



              textBox = new TextBox();


              absolutePanel.add(textBox, 143, 39);



              Label lblTopic = new Label("Topic");


              absolutePanel.add(lblTopic, 86, 42);



              comboBox = new ListBox();


              comboBox.addItem("Computer Science");


              comboBox.addItem("Environment");


              comboBox.addItem("Physics");


              comboBox.addItem("Chemistry");


              comboBox.addItem("Biology");


              absolutePanel.add(comboBox, 143, 88);


              comboBox.setSize("148px", "24px");



              Label lblStreams = new Label("Streams");


              absolutePanel.add(lblStreams, 69, 88);



              textBox_1 = new TextBox();


              absolutePanel.add(textBox_1, 143, 139);



              Label lblTags = new Label("Tags");


              absolutePanel.add(lblTags, 87, 139);



              textBox_2 = new TextBox();


              absolutePanel.add(textBox_2, 143, 194);



              Label lblPublicLink = new Label("Public Link");


              absolutePanel.add(lblPublicLink, 49, 194);



              fileUpload = new FileUpload();


              absolutePanel.add(fileUpload, 143, 254);


              button = new Button("New button");


              absolutePanel.add(button, 156, 311);



              button.addClickHandler(new ClickHandler()


              {


                  public void onClick(ClickEvent event)


                  {


                        Window.alert("onclick");


                        String topic=textBox.getText();


                   String strm=comboBox.getItemText(comboBox.getSelectedIndex());


                        String tag=textBox_1.getText();


                        String plink=textBox_2.getText();


                        String fpath=fileUpload.getFilename();



        a1.upload(topic, strm, tag, plink, fpath, newAsyncCallback<String>() 
            {



              @Override


             public void onSuccess(String result)


             {


                 // TODO Auto-generated method stub


                  String f="yes";


                  System.out.println(result);


                  // TODO Auto-generated method stub


                  if(result.equals(f))


                  {


                     System.out.println("onsuccess");


                     Window.alert("File Upload");



                  }


                  else


                  {


                     Window.alert("Filis not uploaded");


                  }



           }



           @Override


           public void onFailure(Throwable caught) 
            {


                  // TODO Auto-generated method stub


                  Window.alert("Failure");


            }


        });


      }


   });


              button.setText("Uplod lctr notes");


              button.setSize("133px", "28px");



              Label lblFile = new Label("File");


              absolutePanel.add(lblFile, 98, 254);


              lblFile.setSize("27px", "21px");


    }


}


GreetingServiceimp.java


package com.server;


import java.io.File;


import java.io.FileInputStream;


import java.io.FileOutputStream;


import java.io.IOException;


import java.io.InputStream;


import java.sql.Connection;


import java.sql.DriverManager;


import java.sql.PreparedStatement;


import java.sql.ResultSet;


import java.sql.SQLException;


import java.sql.Statement;


import com.client.GreetingService;


importcom.google.gwt.user.server.rpc.RemoteServiceServlet;


/**


 * The server side implementation of the RPC service.


 */


@SuppressWarnings("serial")


public class GreetingServiceImpl extendsRemoteServiceServlet implements


    GreetingService


{



      Connection con=null;


      Statement st=null;


      ResultSet rs=null;


      String query;



      String url="jdbc:mysql://localhost:3306/gwtlogin";



 public void call()


 {


       try


       {


             Class.forName("com.mysql.jdbc.Driver");


       }


       catch(ClassNotFoundException e)


       {


             System.out.print(e.getMessage());


       }


       try


       {


             con=DriverManager.getConnection(url, "root","");


             st=con.createStatement();


       }


       catch(SQLException e)


       {


             System.out.println(e.getMessage());


       }


 }


      @Override


public String upload(String topic, String stream, String Tag, String plink,


                  String fpath) {


            // TODO Auto-generated method stub


            call();


            String ss="no";


            int k=0;


          FileInputStream fis = null;


          PreparedStatement pstmt = null;



          System.out.println(fpath);


          try


          {


            System.out.println("Hello try");


            con.setAutoCommit(false);


            File file = new File(fpath);


            fis = new FileInputStream(file);


            pstmt = con.prepareStatement("insert into uploadfile(Topic, Stream, Tag, PublicLink, FileBody ) values ( ?, ?, ?, ?, ?)");


            //pstmt.setString(1, id);


            pstmt.setString(1, topic);


            pstmt.setString(2, stream);


            pstmt.setString(3, Tag);


            pstmt.setString(4, plink);


            pstmt.setAsciiStream(5, fis, (int) file.length());


            k=pstmt.executeUpdate();


            System.out.println("Bye");


            if(k==1)


                  {


                        ss="yes";



                  }


            con.commit();


          }


          catch (Exception e)


          {


            System.err.println("Error: " + e.getMessage());


            e.printStackTrace();


          }


          finally {


              try {


                        pstmt.close();


                  } catch (SQLException e) {


                        // TODO Auto-generated catch block


                        e.printStackTrace();


                  }


              try {


                        fis.close();


                  } catch (IOException e) {


                        // TODO Auto-generated catch block


                        e.printStackTrace();


                  }


              try {


                        con.close();


                  } catch (SQLException e) {


                        // TODO Auto-generated catch block


                        e.printStackTrace();


                  }


            }



          return ss;


      }


}


I hope you will able to store file into database. If any error has occurred or any question comes in your mind. Freely ask your problem by comment we just solve your problem within 1 hour.

Saturday 27 August 2016

Stay Hungry, Stay Foolish


The greatest entrepreneur speech ever:

“Today I want to tell you three stories from my life. That’s it. No big deal. Just three stories.

The first story is about connecting the dots.

I dropped out of Reed College after the first 6 months, but then stayed around as a drop-in for another 18 months or so before I really quit. So why did I drop out?

It started before I was born. My biological mother was a young, unwed college graduate student, and she decided to put me up for adoption. She felt very strongly that I should be adopted by college graduates, so everything was all set for me to be adopted at birth by a lawyer and his wife. Except that when I popped out they decided at the last minute that they really wanted a girl.

So my parents, who were on a waiting list, got a call in the middle of the night asking: “We have an unexpected baby boy; do you want him?” They said: “Of course.” My biological mother later found out that my mother had never graduated from college and that my father had never graduated from high school. She refused to sign the final adoption papers. She only relented a few months later when my parents promised that I would someday go to college.

And 17 years later I did go to college. But I naively chose a college that was almost as expensive as Stanford, and all of my working-class parents’ savings were being spent on my college tuition.

After six months, I couldn’t see the value in it. I had no idea what I wanted to do with my life and no idea how college was going to help me figure it out. And here I was spending all of the money my parents had saved their entire life.

So I decided to drop out and trust that it would all work out OK. It was pretty scary at the time, but looking back it was one of the best decisions I ever made. The minute I dropped out I could stop taking the required classes that didn’t interest me, and begin dropping in on the ones that looked interesting.

It wasn’t all romantic. I didn’t have a dorm room, so I slept on the floor in friends’ rooms, I returned Coke bottles for the 5¢ deposits to buy food with, and I would walk the 7 miles across town every Sunday night to get one good meal a week at the Hare Krishna temple. I loved it. And much of what I stumbled into by following my curiosity and intuition turned out to be priceless later on. Let me give you one example:

Reed College at that time offered perhaps the best calligraphy instruction in the country. Throughout the campus every poster, every label on every drawer, was beautifully hand calligraphed. Because I had dropped out and didn’t have to take the normal classes,

I decided to take a calligraphy class to learn how to do this. I learned about serif and sans serif typefaces, about varying the amount of space between different letter combinations, about what makes great typography great. It was beautiful, historical, artistically subtle in a way that science can’t capture, and I found it fascinating.

None of this had even a hope of any practical application in my life. But 10 years later, when we were designing the first Macintosh computer, it all came back to me. And we designed it all into the Mac. It was the first computer with beautiful typography. If I had never dropped in on that single course in college, the Mac would have never had multiple typefaces or proportionally spaced fonts.

And since Windows just copied the Mac, it’s likely that no personal computer would have them. If I had never dropped out, I would have never dropped in on this calligraphy class, and personal computers might not have the wonderful typography that they do. Of course it was impossible to connect the dots looking forward when I was in college. But it was very, very clear looking backward 10 years later.

Again, you can’t connect the dots looking forward; you can only connect them looking backward. So you have to trust that the dots will somehow connect in your future. You have to trust in something — your gut, destiny, life, karma, whatever. This approach has never let me down, and it has made all the difference in my life.

My second story is about love and loss.

I was lucky — I found what I loved to do early in life. Woz and I started Apple in my parents’ garage when I was 20. We worked hard, and in 10 years Apple had grown from just the two of us in a garage into a $2 billion company with over 4,000 employees. We had just released our finest creation — the Macintosh — a year earlier, and I had just turned 30. And then I got fired.

How can you get fired from a company you started? Well, as Apple grew we hired someone who I thought was very talented to run the company with me, and for the first year or so things went well. But then our visions of the future began to diverge and eventually we had a falling out. When we did, our Board of Directors sided with him.

So at 30 I was out. And very publicly out. What had been the focus of my entire adult life was gone, and it was devastating.

I really didn’t know what to do for a few months. I felt that I had let the previous generation of entrepreneurs down — that I had dropped the baton as it was being passed to me. I met with David Packard and Bob Noyce and tried to apologize for screwing up so badly.

I was a very public failure, and I even thought about running away from the valley. But something slowly began to dawn on me — I still loved what I did. The turn of events at Apple had not changed that one bit. I had been rejected, but I was still in love. And so I decided to start over.

I didn’t see it then, but it turned out that getting fired from Apple was the best thing that could have ever happened to me. The heaviness of being successful was replaced by the lightness of being a beginner again, less sure about everything. It freed me to enter one of the most creative periods of my life.

During the next five years, I started a company named NeXT, another company named Pixar, and fell in love with an amazing woman who would become my wife. Pixar went on to create the world’s first computer animated feature film, Toy Story, and is now the most successful animation studio in the world. In a remarkable turn of events, Apple bought NeXT, I returned to Apple, and the technology we developed at NeXT is at the heart of Apple’s current renaissance. And Laurene and I have a wonderful family together.

I’m pretty sure none of this would have happened if I hadn’t been fired from Apple. It was awful tasting medicine, but I guess the patient needed it. Sometimes life hits you in the head with a brick. Don’t lose faith. I’m convinced that the only thing that kept me going was that I loved what I did. You’ve got to find what you love. And that is as true for your work as it is for your lovers.

Your work is going to fill a large part of your life, and the only way to be truly satisfied is to do what you believe is great work. And the only way to do great work is to love what you do. If you haven’t found it yet, keep looking. Don’t settle. As with all matters of the heart, you’ll know when you find it. And, like any great relationship, it just gets better and better as the years roll on. So keep looking until you find it. Don’t settle.

My third story is about death.

When I was 17, I read a quote that went something like: “If you live each day as if it was your last, someday you’ll most certainly be right.” It made an impression on me, and since then, for the past 33 years, I have looked in the mirror every morning and asked myself: “If today were the last day of my life, would I want to do what I am about to do today?” And whenever the answer has been “No” for too many days in a row, I know I need to change something.

Remembering that I’ll be dead soon is the most important tool I’ve ever encountered to help me make the big choices in life. Because almost everything — all external expectations, all pride, all fear of embarrassment or failure — these things just fall away in the face of death, leaving only what is truly important. Remembering that you are going to die is the best way I know to avoid the trap of thinking you have something to lose. You are already naked. There is no reason not to follow your heart.

About a year ago I was diagnosed with cancer. I had a scan at 7:30 in the morning, and it clearly showed a tumor on my pancreas. I didn’t even know what a pancreas was. The doctors told me this was almost certainly a type of cancer that is incurable, and that I should expect to live no longer than three to six months.

My doctor advised me to go home and get my affairs in order, which is doctor’s code for prepare to die. It means to try to tell your kids everything you thought you’d have the next 10 years to tell them in just a few months. It means to make sure everything is buttoned up so that it will be as easy as possible for your family. It means to say your goodbyes.

I lived with that diagnosis all day. Later that evening I had a biopsy, where they stuck an endoscope down my throat, through my stomach and into my intestines, put a needle into my pancreas and got a few cells from the tumor. I was sedated, but my wife, who was there, told me that when they viewed the cells under a microscope the doctors started crying because it turned out to be a very rare form of pancreatic cancer that is curable with surgery. I had the surgery and I’m fine now.

This was the closest I’ve been to facing death, and I hope it’s the closest I get for a few more decades. Having lived through it, I can now say this to you with a bit more certainty than when death was a useful but purely intellectual concept:

No one wants to die. Even people who want to go to heaven don’t want to die to get there. And yet death is the destination we all share. No one has ever escaped it. And that is as it should be, because Death is very likely the single best invention of Life. It is Life’s change agent. It clears out the old to make way for the new. Right now the new is you, but someday not too long from now, you will gradually become the old and be cleared away. Sorry to be so dramatic, but it is quite true.

Your time is limited, so don’t waste it living someone else’s life. Don’t be trapped by dogma — which is living with the results of other people’s thinking. Don’t let the noise of others’ opinions drown out your own inner voice. And most important, have the courage to follow your heart and intuition. They somehow already know what you truly want to become. Everything else is secondary.

When I was young, there was an amazing publication called The Whole Earth Catalog, which was one of the bibles of my generation. It was created by a fellow named Stewart Brand not far from here in Menlo Park, and he brought it to life with his poetic touch. This was in the late 1960s, before personal computers and desktop publishing, so it was all made with typewriters, scissors and Polaroid cameras. It was sort of like Google in paperback form, 35 years before Google came along: It was idealistic, and overflowing with neat tools and great notions.

Stewart and his team put out several issues of The Whole Earth Catalog, and then when it had run its course, they put out a final issue. It was the mid-1970s, and I was your age. On the back cover of their final issue was a photograph of an early morning country road, the kind you might find yourself hitchhiking on if you were so adventurous. Beneath it were the words: “Stay Hungry. Stay Foolish.” It was their farewell message as they signed off. Stay Hungry. Stay Foolish. And I have always wished that for myself. And now, as you graduate to begin anew, I wish that for you.

Stay Hungry. Stay Foolish.”

Steve Jobs,
Stanford University Commencement address,
June 2005


How do you make a mark?

How do you make a mark with a new company in a competitive market? How did Facebook reach its first $100 million mark in revenue?

The answer may surprise you - and change the way you think about your own business strategy.

In 2006, Mark Zuckerberg and his team were more focused on coding Facebook than growing revenue. Mark hired Dan Rose from Jeff Bezo’samazon.com as “VP of Business Development” to help grow revenue.

Dan had learned from Jeff Bezos that one big partnership can make all the difference to revenues. He watched Myspace start doing big deals in the grand style of it’s new Deal Maker owner, Rupert Murdoch. The problem was, Facebook was growing, but was not as big or as established as Myspace yet, so its marketing partnerships were still small.

Within a month of Dan joining Facebook, in August 2006, everything changed. Myspace announced a $900 million deal with Google. Myspace had the traffic, and Google had the ad network. It was a perfect partnership where Google would manage Myspace’s ads, and that deal single-handedly made Myspace profitable.

Dan Rose asked “Who has the most to lose from this deal?” The answer was Bill Gates’ Microsoft MSN ad network, which had lost out to their arch rival Google. Dan jumped on the phone to Microsoft, and asked them if they wanted a similar deal with Facebook. Microsoft’s answer? “Okay, we’ll be down there tomorrow to iron it out.”

That one deal, wrapped up 24 hours later, doubled Facebook’s revenues in 2006 from a forecast $22 million to over $40 million. The year after, the Microsoft deal was worth over $100 million in revenue to Facebook.

One phone call to solve Microsoft’s problem - which was not wanting to lose to Google - led to Facebook’s first $100 million.

Sometimes to win the war, it’s easier to help others fight their battles than to fight your own. Sometimes their battles are much bigger than yours.

Who would you love to work with who would want to have you in their corner? Who could you be helping to win big today?

The fastest way to find out? Bring in someone with inside knowledge - Inside knowledge that’s outside the box.

“If opportunity doesn't knock, build a door.”
~ Milton Berle

 

Steve Jobs’ Top 10 rules of thumb

Great entrepreneurs don’t use rule books, but they do use rules of thumb:

Rule books are fixed. Rules of thumb are flexible.
Rule books put you in a box. Rules of thumb point you on a path.
Rule books instruct you. Rules of thumb inspire you.

All the ingredients of fast-growing companies - Creativity, culture, talent, team and trust - grow with the guidance of the right rules of thumb.

Here’s Steve Jobs’ Top 10:

Rule 1 - “Be a yardstick of quality. Some people aren’t used to an environment where excellence is expected.”

Rule 2 - “Design is not just what it looks like and feels like. Design is how it works.”

Rule 3 - “One of my mantras - focus and simplicity. Simple can be harder than complex.”

Rule 4 - “My model for business is The Beatles. They were four guys who kept each other’s kind of negative tendencies in check. They balanced each other and the total was greater than the sum of the parts. That’s how I see business: great things in business are never done by one person, they’re done by a team of people.”

Rule 5 - “Sometimes when you innovate, you make mistakes. It is best to admit them quickly, and get on with improving your other innovations.”

Rule 6 - “The only way to do great work is to love what you do. If you haven’t found it yet, keep looking.”

Rule 7 - “For the past 33 years, I have looked in the mirror every morning and asked myself: ‘If today were the last day of my life, would I want to do what I am about to do today?’ And whenever the answer has been ‘No’ for too many days in a row, I know I need to change something.”

Rule 8 - “Your time is limited, so don’t waste it living someone else’s life.”

Rule 9 - “Overthinking leads to negative thoughts”

Rule 10 - “Stay hungry, stay foolish.”

When you throw away the rule book, and write down your rules of thumb, you’re writing down your guiding principles. They give you a simple compass to follow instead of a complex map to remember. What are yours?

Would you give all your money away? This Person did

Would you give all your money away? If so, where? This is the extraordinary story of Chuck Feeney, who finally achieves his 34 year mission of going from $8 billion to broke this year.

2016 is the year his Foundation gives the last of his money away. In the process, he has become the hero of Bill Gates and Warren Buffett, who said “Chuck has set an example not only for people of my age but also younger generations. He will be an example 100 years from now or 200 years from now.”

“He is my hero. He is Bill Gates’ hero. He should be everybody’s hero.”

Here’s Chuck’s 3 steps to making, and giving away $8 billion.

START BY DECIDING TO GIVE IT AWAY BEFORE YOU MAKE IT

Chuck was born into a poor, Irish family during the Great Depression in 1931. He shovelled snow and sold Christmas cards door-to-door as a kid to make money to take home. While young and in poverty, he read Andrew Carnegie’s classic essay, “The Gospel of Wealth”.

Andrew Carnegie’s essay was a revolutionary call for those who create wealth to live modestly, and to give all their excess wealth to support others while still alive: “Giving while living.”

The words touched him so deeply, Chuck decided at that moment that he would dedicate his life to create wealth to give away, saying “I want the last cheque I write to bounce.”

THEN TRAVEL THE WORLD

As a teenager, Chuck joined the US airforce during the Korean War. He got to see first hand the difficulty servicemen had in getting the products they wanted from home. So he set up a business to import and sell them the goods they wanted. He found a way to sell them without duty, by setting up stores on the air-side of airports and his company, Duty Free Shoppers took off.

Ever bought anything from a DFS shop at an airport? That’s Chuck’s company.

But from the early days, Chuck had already set up his company so that all the proceeds went into his foundation, the Atlantic Philanthropies, so the money the company made could be given away each year. The money has gone into causes around the world in health, education and human rights.

When Chuck sold DFS in 1996, his Foundation took all the money from the sale, and committed to spend everything within 20 years - by 2016. By the time it gives the last of his money away, it will have given away $8 billion.

AND CHUCK IT ALL THE WAY

What about Chuck? Surely he has kept enough aside to live in luxury? Today, at 85 years old, Chuck does not own a home or a car. He still famously wears a watch he bought for $15, and he carries his papers in a plastic bag.

Chuck says “I always tried to live my life as though nothing changed. People would say, 'You can have a Rolls-Royce'. I'd say to that, 'What do I want with a Rolls-Royce when I can have a bike?’"

Instead of measuring his success by his level of money in the bank, he measures it by his level of happiness: “People used to ask me how I got my jollies, and I guess I'm happy when what I'm doing is helping people and unhappy when what I'm doing isn't helping people.”

2016 marks the end of Chuck’s giving, but just the beginning of his legacy. His story inspired Bill Gates to also give all his money away, and to launch the Giving Pledge, which now has 142 of the World’s Billionaires pledging to give the majority of their wealth away while alive - including Richard Branson, Mark Zuckerberg, Elon Musk, Tim Cook, Warren Buffett and many more.

Bill Gates credits Chuck for the new age of giving, saying “Chuck Feeney is a remarkable role model, and the ultimate example of giving while living.”

As you begin another week, how would things change if you were to know everything you make will be given away to a cause far bigger than yourself?

Where would you contribute the money you are yet to make?

How would it change your sense of purpose and determination?

Make that decision now so you can focus at money flowing through you, not to you.

“There’s a limit to what you can get. There’s no limit to what you can give.”

Do you believe in luck?


Do you believe in luck? Here’s the incredible story of 34-year old William Tanuwijaya, who has created Indonesia’s first Billion dollar ‘Unicorn’, and the lucky set of coincidences that led to him raising $100 million when he most needed it…

When he became a teenager, Williams’ father sent him on a one way ticket from Sumatra to Jakarta with the family’s savings, hoping he’d end up with a better life.

William enrolled in a college and for three years worked 12 hour night shifts in an Internet cafe to pay for his tuition. Using his nights exploring the Internet, he got inspired to start his company, Tokopedia, as the first online marketplace for Indonesia in 2009.

The good news? From day one, Tokopedia started growing. The bad news? There was no startup funding scene in Indonesia at the time.

William remembers the struggle as he visited potential investors: “I was told ’William, don’t waste your time. The guys who started Amazon, Facebook and Google, they are special people. Unfortunately, you are not.’”

William said, “I decided right then that I will never give up on myself.”

He picked up a small investment from a company that invested in mining companies, giving him time to look for more. Then, five long years after launch, in 2014, luck struck. Within less than a week, he raised $100 million by a series of chance events.

As William recalls:

“I’d been in a 7 years relationship, a long distance one with my girlfriend. She studied medicine, and on her graduation, she wanted to go to visit Japan, and asked me to go for holiday with her.”

“But I said no to her, that I can’t take a holiday, as Tokopedia needs me, and Tokopedia was almost running out of cash by November.”

“Secretly, I bought a ticket, filled out a leave form for the first time in 5 years, asked her parent's approval, and planned for my secret proposal to her on 1st of October in Osaka.”

“At the end of September, I got a call from SoftBank, that Son-san (Masayoshi Son, one of the first tech investors in Asia and one of Japan’s richest men) requested a meeting in early October. Living in Indonesia, you need 5 working days to arrange a VISA. That request was less than 5 working days.”

“But, I already had the VISA, ticket in hand!”

“Then, on the 30th of September, one of my shareholders asked me to meet with Sequoia Capital. The Sequoia venture partner called me and ask for a meeting the day after. I told him that I am on the way to airport going to Osaka. When I arrived at Osaka, the venture partner was also there, took the same flight with me, and ended up chatting with me the whole day. I almost skipped my proposal.”

Then, the proposal. She said yes.

“The day after my proposal, I flew to Tokyo to met with Son-san.”

"That week, 3 proposals happened. And the rest is history.”

William got married, and raised $100 million from Softbank and Sequoia - the first company in South East Asia to raise that amount. That event sparked the beginning of the investing wave into Indonesia, Singapore and Malaysia, with Tokopedia being the first investment by Sequoia Capital into Asia.

In April this year, William raised another $147 million, and today Tokopedia is worth over a billion dollars.

Some people think luck is completely random. Others think it’s “what happens when preparation meets opportunity”. I see it as the same four things that make a great footballer ‘lucky’ enough to keep being at the right place, at the right time, to score the goals:

LOCATION - Be at the right place, at the right time, and the universe will reward you. Most of us are too busy being in the wrong place, at the wrong time.

UNDERSTANDING - Understand the game is on, which means looking out for the ball - the opportunities - coming your way, and take action when they arrive.

CONNECTIONS - No matter how good a player you are, you won’t get any balls passed to you if there’s no one on the pitch. Surround yourself with the right people on your team.

KNOWLEDGE - Keep practicing. You only score the goals if you know how to kick the ball when it shows up.

Location, Understanding, Connections, Knowledge = L.U.C.K.

Follow these principles, and you’ll get more lucky. Maybe not happy marriage lucky. Maybe not $100 million lucky. Maybe different lucky. And maybe better lucky.

“Synchronicity is an ever present reality for those who have eyes to see.” ~ Carl Jung


Keep at it, because you’re leading the world’s 5th wave of exponential economic growth

A message to entrepreneurs: Keep at it, because you’re leading the world’s 5th wave of exponential economic growth:

Up until 1780, world economic activity was relatively flat, with the Gross World Product (all economic value creation worldwide) under US$200 billion for over 5,000 years.

The world then went through exponential growth over 200 years from 1800 to 2000, doubling every 20 years, with Gross World Product growing from US$200 billion to $40 trillion.

The four waves of exponential growth have been:

1. The Industrial revolution
2. The race for oil
3. Corporate capitalism
4. Financial markets

Each wave grew and fell in power over around 50 years each.
Each wave led to a global transfer of wealth.
Each age changed all the rules.

In the 15 years from 2000 to 2015, despite a dotcom crash and global crisis, Gross World Product has doubled again, from $40 trillion to over $80 trillion - We continue to add value to each other at an accelerating rate.

What is this fifth wave we’re in now? Entrepreneurial start-ups.

The rules have changed again:

It’s no longer about economies of scale, but economies of speed.
It’s no longer about getting money but giving value.
Today collaboration beats competition.
Today David beats Goliath.

This wave has only just begun, and as with any wave, you can sink or swim.

Or you can take the entrepreneurial 3rd option, and surf.

"The person who says it cannot be done should not interrupt the person who is doing it.” ~ Chinese Proverb


 

Proof that entrepreneurship doesn’t depend on your company size, but on your mindset

Proof that entrepreneurship doesn’t depend on your company size, but on your mindset: Here are the top five company comebacks - each from the jaws of billion dollar failures.

STARBUCKS

In 2008, Starbucks' over expansion into music, movies and too many loss-making stores led to an exodus of customers as quality fell. 977 stores closed and its stock price plummeted 80% from $40 to $7.83. In the midst of the crisis, founder, Howard Schultz returned as the CEO, saying Starbucks had “forgotten what we stand for.”

He refocused 100% on the coffee, closed all stores for a day to retrain the baristas, brought all 10,000 store managers to New Orleans to rediscover their sense of mission and purpose. As he says, “If we hadn’t had New Orleans, we wouldn’t have turned things around.” Since then, Starbucks has doubled in size and profitability, growing to over 23,000 stores, $16 billion in revenue and $3 billion in profit. Howard remains as both Chairman and CEO today.

NETFLIX

In 2011, Netflix announced: "We will no longer offer a plan that includes both unlimited streaming and DVDs by mail." forcing subscribers to join two separate services and pay $16 a month instead of $10. The massive backlash led to more than 800,000 customers quitting Netflix in a single quarter. Netflix’s stock plunging fell 77% in 4 months from $300 a share to around $65.

Founder, Reed Hastings, took personal responsibility for the miss-step and apologized, saying “I messed up. I slid into arrogance based upon past success. Inside Netflix I say ‘Actions speak louder than words,’ and we should just keep improving our service.” He reversed the changes, refocused the company on quality and the customer, launching original content like “House of Cards”, and over the next few years the company has recovered to be the fastest growing video streaming company with over $6 billion in revenue.

LEGO

In the late 1990’s, Lego lost money for the first time in its history, with its traditional blocks struggling against the rise of video games and other toy makers. Jørgen Vig Knudstorp stepped in as CEO in 2004, and says “When I became CEO, things had gone awfully wrong at Lego.” He began by refocusing the entire staff of 14,000: “We had to ask, ‘Why does Lego Group exist?’ Ultimately, we determined the answer: to offer our core products, whose unique design lets children learn systematic, creative problem solving - a crucial twenty-first-century skill. We also decided we want to compete not by being the biggest but by being the best.”

He began involving Lego fans in product development and rewarding ‘Super users’. The Lego brand was reignited, and Lego has now become the most profitable toy company in the world. As Jørgen says, “We used to be seen as a bit of a basket case. Our competitors were ten years ahead of us. Now we’ve passed them.”

APPLE

In 1997 Apple had lost its way, was in disarray and just a few months away from bankruptcy when Steve Jobs returned as Interim CEO. His first step shocked the Apple faithful: A $150 million deal with arch-rival Bill Gates to put Microsoft products on all Apple computers. The move sent a message to the market that Apple had to be a serious business that made smart commercial decisions, and rebranded Steve from being a dreamer and visionary to also a serious business leader.

He refocused the team, brought on Tim Cook from Compaq (who now leads Apple), and then began the chain of innovative product launches from the iMac, to iPod, to iPhone. Apple’s market cap grew from $3 billion when Steve Jobs returned to the company, to more than $740 billion today. It’s cash went from deficit to over $200 billion today: The biggest corporate turnaround in history.

TESLA & SpaceX

In 2008, both of Elon Musk’s companies, Tesla and SpaceX, were out of money and he was broke. As he says "I could either pick SpaceX or Tesla or split the money I had left between them. If I split the money, maybe both of them would die. If I gave the money to just one company, the probability of it surviving was greater, but then it would mean certain death for the other company. I debated that over and over.”

That was on top of his personal challenges: "You have these huge doubts that your life is not working, your car is not working, you’re going through a divorce, and all of those things. I felt like a pile of sh_t. I didn't think we would overcome it. I thought things were probably f*@king doomed.”

He went knocking on all the doors he could, getting Sergey Brin to put up $500,000 and Bill Lee to put up $2 million. Elon managed to pull together all the parts for a $40 million round of funding, but wasn’t able to close. Then, on Christmas Eve, SpaceX announced a $1.6 billion contract to SpaceX, and the Tesla deal closed hours before Tesla would have gone bankrupt.

Elon broke down in tears and said “I hadn’t had an opportunity to buy a Christmas present for Talulah or anything. I went running down the f*@king street in Boulder, and the only place that was open sold these sh%*y trinkets, and they were about to close. The best thing I could find were these plastic monkeys with coconuts—those ‘see no evil, hear no evil’ monkeys.”

He bought the monkeys, turned both companies around, and eight years later - in the last month -has reached new records with the sea landing of his Falcon 9 rocket and the largest product launch in history with the Tesla Model 3.

Each of these five comeback stories show that any company of any size can be turned around when approached with an entrepreneurial mindset. What would Steve Jobs do if he were in your shoes? What would Elon Musk do if he owned your company?

Shift your mindset, and set your mind free.

You’re never too small to start, never too big to fail, and it’s never too late to start again.

“I don’t measure a man’s success by how high he climbs, but how he he bounces when he hits bottom.” ~ George S Patton Jr.

Featured post

The Thrill of Programming: Exploring the Satisfaction Behind the Code

Different individuals find satisfaction in programming for various reasons. Here are some common factors that tend to bring satisfaction to ...