Hiển thị các bài đăng có nhãn ki tu. Hiển thị tất cả bài đăng
Hiển thị các bài đăng có nhãn ki tu. Hiển thị tất cả bài đăng

Thứ Hai, 9 tháng 2, 2015

Hàm - chương trình con - void in C

Hàm - chương trình con - void in C

code và chương trình sẵn Tại Đây




#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;
}


hoan-vi
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;
 }
}
Dao-nguoc
Đảo ngược






#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);
}


tim-kiem
tìm kiếm




end

Hàm - chương trình con - function in C (tiếp)


Hàm - chương trình con - function in C (tiếp)



code và chương trình sẵn Tại Đây

1. Write a function which accepts an integer value as input, and returns an integer which is the cube of that input


#include <stdio.h>
#include <stdlib.h>

/* Write a function which accepts an integer value as input, and returns an integer which is the cube of that input */
int l(int);
int main(int argc, char *argv[]) {
 printf("vao X= ");
 int x;
 scanf("%d",&x);
 printf("x^3 = %d",l(x)); 
 printf("\n\n\n");
 system("pause");
 return 0;
}
int l(int x){
 int y = x*x*x;
 return y;
}

lap-phuong
Lập phương


2. Write a function that accepts a char as input and returns true if the char is a digit from 0 to 9 or false if the character is not a digit from 0 to 9



#include <stdio.h>
#include <stdlib.h>
/* Write a function that accepts a char as input and returns true 
if the char is a digit from 0 to 9 or false if the character is not a digit from 0 to 9 */
int tf(char);
int main(int argc, char *argv[]) {
 printf("vao ki tu : ");
 char x;
 scanf("%c",&x);
 if (tf(x)) printf("%c nam giua 0 - 9",x);
  else printf ("%c khong nam giua 0 - 9",x); 
 printf("\n\n\n");
 system("pause");
 return 0;
}
int tf(char x){
 int y;
 if (x >= '0' && x<= '9') y = 1;
 else y = 0;
 return y;
}

tim-kiem
tìm kiếm



#include <stdio.h>
#include <stdlib.h>
/* . Write a function named Smallest that takes three integer inputs 
and returns an integer that is the smallest of the three inputs.  
Write the prototype for the Smallest function.  
Write  a program that gets 3 integers from a user and displays the smallest. */
int m(int,int,int);
int main(int argc, char *argv[]) {
 printf ("vao 3 so : ");
 int x,y,z;
 scanf("%d%d%d",&x,&y,&z);
 printf(" so nho nhat trong 3 so %d %d %d la : %d",x,y,z,m(x,y,z)); 
 printf("\n\n\n");
 system("pause");
 return 0;
}
int m(int x,int y, int z){
 int i =x;
 if (i > y) i = y;
 if (i > z) i = z;
 return i;
}

min
min


4. Write a function that, given a letter of the alphabet, returns true if the letter is a vowel (lower or uppercase) and returns false if the letter is not a vowel.



#include <stdio.h>
#include <stdlib.h>
/* Write a function that, given a letter of the alphabet, 
returns true if the letter is a vowel (lower or uppercase) and returns false if the letter is not a vowel. */
int t(char);
int main(int argc, char *argv[]) {
 printf ("vao 1 chu: ");
 char x;
 gets(&x);
 if (t(x)) printf ("%c la nguyen am",x);
  else printf ("%c khong phai la nguyen am",x);
 printf("\n\n\n");
 system("pause");
 return 0;
}
int t(char x){
 int t;
 if (x=='u'||x=='U'||x=='e'||x=='E'||x=='o'||x=='O'||x=='a'||x=='A'||x=='i'||x=='I') t= 1;
  else t=0;
 return t;
}


tim-nguyen-am
tim nguyên âm


end