, , . , , . . . . . , .
swap(), , .
Void swap(int a, int b)
{
int tmp=a;
a=b;
b=tmp;
}
, . , , , . . . . , . , .
swap1() :
void swap1(int *a, int *b)
{
int tmp=*a;
*a=*b;
*b=tmp;
}
:
#include <stdio.h>
Void swap(int a, int b);
void swap1(int *a, int *b);
Void main(void)
{
int x=5, y=10;
printf( x = %d y = %d\n, x, y);
Swap(x, y);
printf( swap x = %d y = %d\n, x, y);
printf( );
swap1(&x, &y); /* */
printf( swap1 x = %d y = %d\n, x, y);
printf( );
Return 0;
}
//
:
x=5, y=10
swap x=5, y=10
swap1 x=10, y=5
: swap(5,10); /* */ swap1(&5,&10); /* */
, . . :
function(int ar[10]);
function(int ar[]);
function(int *ar);
:
#include <stdio.h>
void sort(int ar[], int n);
Void main(void)
{
int mass[10]={1, 3, -5, 7, 9, 0, 22, 4, 6, 8};
int size=10,i;
printf(Before sorting:);
for(i=0; i<10; i++)
printf(%d,mass[i]);
printf(\n);
Sort(mass, size);
printf(After sorting:);
for(i=0; i<10; i++)
printf(%d,mass[i]);
printf(\n);
}
void sort(int ar[], int n)
/* void sort(int ar[10], int n) void sort(int *ar, int n) */
{
Int i,j,tmp;
for(i=0; i<n; i++)
|
|
{
for(j=i+1; j<n; j++)
{
if (ar[i]>ar[j])
{
tmp=ar[i];
ar[i]=ar[j];
ar[j]=tmp;
}
}
}
}
#include <stdio.h>
void multiply(int U[3][3], int V[3][3], int W[3][3]);
Void main(void)
{
int A[3][3] = {0, 1, 2,
3, 4, 5,
6, 7, 8};
int B[3][3] = {0, 1, 2,
3, 4, 5,
6, 7, 8};
int i, j, [3][3];
Multiply(A, B, C);
printf(Matrix C:\n);
for(i=0; i<3; i++)
printf(%d %d %d\n,C[i][0], C[i][1], C[i][2]);
}
void multiply(int U[3][3], int V[3][3], int W[3][3])
{
Int i, j, k;
for(i=0; i<3; i++)
{
for(j=0; j<3; j++)
{
W[i][j]=0;
For(k=0; k<3; k++)
W[i][j]+=U[i][k]*V[k][j];
}
}
}
. , . , . .
N :
< >[1][2][N];
. . , . . , 0. , :
=< >*< >
,
unsigned arr[40], long double b[10][10], char ch[80];
. .
char . (string). , char. , char, ( 0). \0. . , N , N+1 .
,
char str[11];
, 10 , .
. , . ,
Borland C++
B | o | r | l | a | n | d | C | + | + | \0 |
:
scanf() %s .
gets() ( stdio.h) , . Enter. . .
printf() puts(). . puts() . printf() .
|
|
#include <stdio.h>
/* */
Void main(void)
{
char str[80]; /* */
printf(B 80 : );
gets(str); /* , Enter */
printf( %s \n,str);
printf(B 80 : );
scanf(%s,&str); /* , */
printf( );
Puts(str);
}
, string.h.