#include <stdio.h>
int main()
{
int c;
for(c=0;c<100;c=c+1)
{
puts("I shall refrain from calling my friends names.");
}
return(0);
}
output are;
I shall refrain from calling my friends names.
I shall refrain from calling my friends names.
I shall refrain from calling my friends names.
I shall refrain from calling my friends names.
I shall refrain from calling my friends names.
I shall refrain from calling my friends names.
I shall refrain from calling my friends names.
I shall refrain from calling my friends names.
I shall refrain from calling my friends names.
I shall refrain from calling my friends names.
I shall refrain from calling my friends names.
I shall refrain from calling my friends names.
I shall refrain from calling my friends names.
I shall refrain from calling my friends names.
I shall refrain from calling my friends names.
I shall refrain from calling my friends names.
I shall refrain from calling my friends names.
I shall refrain from calling my friends names.
I shall refrain from calling my friends names.
I shall refrain from calling my friends names.
I shall refrain from calling my friends names.
I shall refrain from calling my friends names.
I shall refrain from calling my friends names.
I shall refrain from calling my friends names.
I shall refrain from calling my friends names.
I shall refrain from calling my friends names.
I shall refrain from calling my friends names.
I shall refrain from calling my friends names.
I shall refrain from calling my friends names.
I shall refrain from calling my friends names.
I shall refrain from calling my friends names.
I shall refrain from calling my friends names.
I shall refrain from calling my friends names.
I shall refrain from calling my friends names.
I shall refrain from calling my friends names.
I shall refrain from calling my friends names.
I shall refrain from calling my friends names.
I shall refrain from calling my friends names.
I shall refrain from calling my friends names.
Process returned 0 (0x0) execution time : 1.702 s
Press any key to continue.
Wednesday, January 30, 2013
TIC TAC
#include <stdio.h>
int main (void)
{
int player = 0;
int winner = 0;
int choice = 0;
int row = 0;
int column = 0;
int line = 0;
char board [3][3] = {
{'1','2','3'},
{'4','5','6'},
{'7','8','9'}
};
int i;
for(i=0;i<9,winner==0;i++)
{
printf("\n\n");
printf(" %c | %c | %c\n", board[0][0], board[0][1], board[0][2]);
printf("---|---|---\n");
printf(" %c | %c | %c\n", board[1][0], board[1][1], board[1][2]);
printf("---|---|---\n");
printf(" %c | %c | %c\n", board[2][0], board[2][1], board[2][2]);
player = i%2 + 1;
do
{
printf("\nPlayer %d, please enter the number of the square "
"where you want to place your %c: ",
player,(player==1)?'X':'O');
scanf("%d", &choice);
row = --choice/3;
column = choice%3;
}while(choice<0 || choice>9 || board [row][column]>'9');
board[row][column] = (player == 1) ? 'X' : 'O';
if((board[0][0]==board[1][1] && board[0][0]==board[2][2]) ||
(board[0][2]==board[1][1] && board[0][2]==board[2][0]))
winner = player;
else
for(line = 0; line <=2; line++)
if((board[line][0]==board[line][1] && board[line][0]==board[line][2])||
(board[0][line]==board[1][line] && board[0][line]==board[2][line]))
winner = player;
} printf("\n\n");
printf(" %c | %c | %c\n", board[0][0], board[0][1], board[0][2]);
printf("---|---|---\n");
printf(" %c | %c | %c\n", board[1][0], board[1][1], board[1][2]);
printf("---|---|---\n"); printf(" %c | %c | %c\n", board[2][0], board[2][1], board[2][2]);
if(winner==0)
printf("The game is a draw\n");
else
printf("Player %d has won\n", winner);
return 0;
}
out put
1 | 2 | 3
---|---|---
4 | 5 | 6
---|---|---
7 | 8 | 9
Player 1, please enter the number of the square where you want to place your X:
4
1 | 2 | 3
---|---|---
X | 5 | 6
---|---|---
7 | 8 | 9
Player 2, please enter the number of the square where you want to place your O:
6
1 | 2 | 3
---|---|---
X | 5 | O
---|---|---
7 | 8 | 9
Player 1, please enter the number of the square where you want to place your X:
6
Player 1, please enter the number of the square where you want to place your X:
3
1 | 2 | X
---|---|---
X | 5 | O
---|---|---
7 | 8 | 9
Player 2, please enter the number of the square where you want to place your O:
1
O | 2 | X
---|---|---
X | 5 | O
---|---|---
7 | 8 | 9
Player 1, please enter the number of the square where you want to place your X:
7
O | 2 | X
---|---|---
X | 5 | O
---|---|---
X | 8 | 9
Player 2, please enter the number of the square where you want to place your O:
8
O | 2 | X
---|---|---
X | 5 | O
---|---|---
X | O | 9
Player 1, please enter the number of the square where you want to place your X:
5
O | 2 | X
---|---|---
X | X | O
---|---|---
X | O | 9
Player 1 has won
int main (void)
{
int player = 0;
int winner = 0;
int choice = 0;
int row = 0;
int column = 0;
int line = 0;
char board [3][3] = {
{'1','2','3'},
{'4','5','6'},
{'7','8','9'}
};
int i;
for(i=0;i<9,winner==0;i++)
{
printf("\n\n");
printf(" %c | %c | %c\n", board[0][0], board[0][1], board[0][2]);
printf("---|---|---\n");
printf(" %c | %c | %c\n", board[1][0], board[1][1], board[1][2]);
printf("---|---|---\n");
printf(" %c | %c | %c\n", board[2][0], board[2][1], board[2][2]);
player = i%2 + 1;
do
{
printf("\nPlayer %d, please enter the number of the square "
"where you want to place your %c: ",
player,(player==1)?'X':'O');
scanf("%d", &choice);
row = --choice/3;
column = choice%3;
}while(choice<0 || choice>9 || board [row][column]>'9');
board[row][column] = (player == 1) ? 'X' : 'O';
if((board[0][0]==board[1][1] && board[0][0]==board[2][2]) ||
(board[0][2]==board[1][1] && board[0][2]==board[2][0]))
winner = player;
else
for(line = 0; line <=2; line++)
if((board[line][0]==board[line][1] && board[line][0]==board[line][2])||
(board[0][line]==board[1][line] && board[0][line]==board[2][line]))
winner = player;
} printf("\n\n");
printf(" %c | %c | %c\n", board[0][0], board[0][1], board[0][2]);
printf("---|---|---\n");
printf(" %c | %c | %c\n", board[1][0], board[1][1], board[1][2]);
printf("---|---|---\n"); printf(" %c | %c | %c\n", board[2][0], board[2][1], board[2][2]);
if(winner==0)
printf("The game is a draw\n");
else
printf("Player %d has won\n", winner);
return 0;
}
out put
1 | 2 | 3
---|---|---
4 | 5 | 6
---|---|---
7 | 8 | 9
Player 1, please enter the number of the square where you want to place your X:
4
1 | 2 | 3
---|---|---
X | 5 | 6
---|---|---
7 | 8 | 9
Player 2, please enter the number of the square where you want to place your O:
6
1 | 2 | 3
---|---|---
X | 5 | O
---|---|---
7 | 8 | 9
Player 1, please enter the number of the square where you want to place your X:
6
Player 1, please enter the number of the square where you want to place your X:
3
1 | 2 | X
---|---|---
X | 5 | O
---|---|---
7 | 8 | 9
Player 2, please enter the number of the square where you want to place your O:
1
O | 2 | X
---|---|---
X | 5 | O
---|---|---
7 | 8 | 9
Player 1, please enter the number of the square where you want to place your X:
7
O | 2 | X
---|---|---
X | 5 | O
---|---|---
X | 8 | 9
Player 2, please enter the number of the square where you want to place your O:
8
O | 2 | X
---|---|---
X | 5 | O
---|---|---
X | O | 9
Player 1, please enter the number of the square where you want to place your X:
5
O | 2 | X
---|---|---
X | X | O
---|---|---
X | O | 9
Player 1 has won
MATRIXX
#include <stdio.h>
int main()
{
int a[10][10], b[10][10], mult[10][10], r1, c1, r2, c2, x, y, z;
printf("Enter rows and column for first matrix: ");
scanf("%d%d", &r1, &c1);
printf("Enter rows and column for second matrix: ");
scanf("%d%d",&r2, &c2);
/* If colum of first matrix in not equal to row of second matrix, asking user to enter the size of matrix again. */
while (c1!=r2)
{
printf("Error! column of first matrix not equal to row of second.\n");
printf("Enter rows and column for first matrix: ");
scanf("%d%d", &r1, &c1);
printf("Enter rows and column for second matrix: ");
scanf("%d%d",&r2, &c2);
}
/* Storing elements of first matrix. */
printf("\nEnter elements of matrix 1:\n");
for(x=0; x<r1; ++x)
for(y=0; y<c1; ++y)
{
printf("Enter elements a%d%d: ",x+1,y+1);
scanf("%d",&a[x][y]);
}
/* Storing elements of second matrix. */
printf("\nEnter elements of matrix 2:\n");
for(x=0; x<r2; ++x)
for(y=0; y<c2; ++y)
{
printf("Enter elements b%d%d: ",x+1,y+1);
scanf("%d",&b[x][y]);
}
/* Initializing elements of matrix mult to 0.*/
for(x=0; x<r1; ++x)
for(y=0; y<c2; ++y)
{
mult[x][y]=0;
}
/* Multiplying matrix a and b and storing in array mult. */
for(x=0; x<r1; ++x)
for(y=0; y<c2; ++y)
for(z=0; z<c1; ++z)
{
mult[x][y]+=a[x][z]*b[z][y];
}
/* Displaying the multiplication of two matrix. */
printf("\nOutput Matrix:\n");
for(x=0; x<r1; ++x)
for(y=0; y<c2; ++y)
{
printf("%d ",mult[x][y]);
if(y==c2-1)
printf("\n\n");
}
return 0;
}
output
Enter rows and column for first matrix: 0 5
Enter rows and column for second matrix: 9 2
Error! column of first matrix not equal to row of second.
Enter rows and column for first matrix: 9 2
Enter rows and column for second matrix: 5 0
Error! column of first matrix not equal to row of second.
Enter rows and column for first matrix:
int main()
{
int a[10][10], b[10][10], mult[10][10], r1, c1, r2, c2, x, y, z;
printf("Enter rows and column for first matrix: ");
scanf("%d%d", &r1, &c1);
printf("Enter rows and column for second matrix: ");
scanf("%d%d",&r2, &c2);
/* If colum of first matrix in not equal to row of second matrix, asking user to enter the size of matrix again. */
while (c1!=r2)
{
printf("Error! column of first matrix not equal to row of second.\n");
printf("Enter rows and column for first matrix: ");
scanf("%d%d", &r1, &c1);
printf("Enter rows and column for second matrix: ");
scanf("%d%d",&r2, &c2);
}
/* Storing elements of first matrix. */
printf("\nEnter elements of matrix 1:\n");
for(x=0; x<r1; ++x)
for(y=0; y<c1; ++y)
{
printf("Enter elements a%d%d: ",x+1,y+1);
scanf("%d",&a[x][y]);
}
/* Storing elements of second matrix. */
printf("\nEnter elements of matrix 2:\n");
for(x=0; x<r2; ++x)
for(y=0; y<c2; ++y)
{
printf("Enter elements b%d%d: ",x+1,y+1);
scanf("%d",&b[x][y]);
}
/* Initializing elements of matrix mult to 0.*/
for(x=0; x<r1; ++x)
for(y=0; y<c2; ++y)
{
mult[x][y]=0;
}
/* Multiplying matrix a and b and storing in array mult. */
for(x=0; x<r1; ++x)
for(y=0; y<c2; ++y)
for(z=0; z<c1; ++z)
{
mult[x][y]+=a[x][z]*b[z][y];
}
/* Displaying the multiplication of two matrix. */
printf("\nOutput Matrix:\n");
for(x=0; x<r1; ++x)
for(y=0; y<c2; ++y)
{
printf("%d ",mult[x][y]);
if(y==c2-1)
printf("\n\n");
}
return 0;
}
output
Enter rows and column for first matrix: 0 5
Enter rows and column for second matrix: 9 2
Error! column of first matrix not equal to row of second.
Enter rows and column for first matrix: 9 2
Enter rows and column for second matrix: 5 0
Error! column of first matrix not equal to row of second.
Enter rows and column for first matrix:
MULTIPLICATION TABLE
#include<stdio.h>
main()
{
int r,i,j;
printf("\nEnter the number:");
scanf("%d",&r);
for (i=1;i<r;i++)
for(j=1;j<=12;j++)
printf("\n%d*%d=%d",i,j,i*j);
printf("\n");
}
main()
{
int r,i,j;
printf("\nEnter the number:");
scanf("%d",&r);
for (i=1;i<r;i++)
for(j=1;j<=12;j++)
printf("\n%d*%d=%d",i,j,i*j);
}
SYNTAX
DATA TYPE SYNTAX BYTES
INTERGER(INT) %d 16
FLOAT %f 32
DOUBLE %f 64
CHARACTER(CHAR) %c 8
STRING %s 128
INTERGER(INT) %d 16
FLOAT %f 32
DOUBLE %f 64
CHARACTER(CHAR) %c 8
STRING %s 128
history of programming
The History of Programming Languages
As with any of todays ideas which we often take for granted, there is usually a long history behind them which can span thousands of years. Programming Languages are different only in that they were dependent on the development of todays computers, which was a process that started about 2000 years ago. Since the development of the transistor in the early 50's, both the computers and the programming languages written to work with them have expanded many times over, often spawning new languages off of older, outdated ones.
In the following pages you will be introduced to the significant events in history that lead up to where we are today with Programming Languages. The sections below seperate our timeline into 5 main series of events. These sections allow for a better understanding of how each time period related to the next, without burying the ideas under mounds of dates and numbers.
1200 - 1940: The Birth of Modern Computing and Programming Ideas
In order for there to be "Programming Languages", we first must have something to program. The following section outlines the events in history which lead to the development of computers and the languages that run on them.
1941 - 1950: The Concepts Become Reality
The ideas and thoughts of the past 1900 years come into form as the first computing languages are developed.
1951 - 1970: Programming As We Know It Begins
As the importance of computers begins to grow rapidly, so does the power of the programming languages that are developed for them.
1971 - 1990: Languages Are Everywhere
The basis for computer operating systems is born, creating an explosion of programming languages that will make the computer the focal point of business and personal activities.
1991 - 2001: The Arrival of the Internet Languages
By the mid 90's, the Internet had become part of our society. With the start of the new millennium, the Internet is as common as the television, and with it comes new languages designed specifically for its use.
As with any of todays ideas which we often take for granted, there is usually a long history behind them which can span thousands of years. Programming Languages are different only in that they were dependent on the development of todays computers, which was a process that started about 2000 years ago. Since the development of the transistor in the early 50's, both the computers and the programming languages written to work with them have expanded many times over, often spawning new languages off of older, outdated ones.
In the following pages you will be introduced to the significant events in history that lead up to where we are today with Programming Languages. The sections below seperate our timeline into 5 main series of events. These sections allow for a better understanding of how each time period related to the next, without burying the ideas under mounds of dates and numbers.
1200 - 1940: The Birth of Modern Computing and Programming Ideas
In order for there to be "Programming Languages", we first must have something to program. The following section outlines the events in history which lead to the development of computers and the languages that run on them.
1941 - 1950: The Concepts Become Reality
The ideas and thoughts of the past 1900 years come into form as the first computing languages are developed.
1951 - 1970: Programming As We Know It Begins
As the importance of computers begins to grow rapidly, so does the power of the programming languages that are developed for them.
1971 - 1990: Languages Are Everywhere
The basis for computer operating systems is born, creating an explosion of programming languages that will make the computer the focal point of business and personal activities.
1991 - 2001: The Arrival of the Internet Languages
By the mid 90's, the Internet had become part of our society. With the start of the new millennium, the Internet is as common as the television, and with it comes new languages designed specifically for its use.
Subscribe to:
Comments (Atom)