Hàm - chương trình con - void in C
void swap (int &number1, int &number2);
#include <stdio.h>
#include <stdlib.h>
void s (int *x, int *y);
int main(int argc, char *argv[]) {
printf (" vao 2 so nguyen : ");
int x,y;
scanf("%d%d",&x,&y);
s(&x,&y);
printf("2 so sau khi hoan vi la : %d %d",x,y);
printf("\n\n\n");
system("pause");
return 0;
}
void s (int *x, int *y){
int z = *x;
*x = *y;
*y = z;
}
|
Hoán vị |
#include <stdio.h>
#include <stdlib.h>
void r (int a[], int n);
int main(int argc, char *argv[]) {
printf("nhap vao do dai mang: ");
int i,n;
scanf("%d",&n);
int a[100];
for (i=0;i<n;i++) {
printf ("A[%d]= ",i+1);
scanf ("%d",&a[i]);
}
r (a,n);
printf("chuoi sau khi dao nguoc la: ");
for (i=0;i<n;i++) printf ("%d ",a[i]);
printf("\n\n\n");
system("pause");
return 0;
}
void r (int a[100], int n){
int i,j;
for (i=0;i<n/2;i++){
j=a[i];
a[i] = a[n-1-i];
a[n-1-i]=j;
}
}
|
Đảo ngược |
int countCharacter(char array[], char ch);
#include <stdio.h>
#include <stdlib.h>
int c(char a[], char i);
int main(int argc, char *argv[]) {
char a[100],b;
printf("vao chuoi ki tu A: ");
gets(a);
printf("vao ki tu B: ");
gets(&b);
printf("\n\n\n");
c(a,b);
printf("\n\n\n");
system("pause");
return 0;
}
int c(char a[100], char b){
int i,t=0;
for (i=0;i<100;i++) if (a[i]== b) t=t+1;
if (t==0) printf("-1");
if (t!=0) printf("%d",t);
}
|
tìm kiếm |
end
Không có nhận xét nào:
Đăng nhận xét