Professional Documents
Culture Documents
1
while(N <= 0 || N>1000); // Vong lap yeu cau nhap vao n thoa man dieu kien
if(so_nguyen_to(N))
printf("\n %d la so nguyen to", N);
else
printf("\n %d la khong phai so nguyen to", N);
getch();
return 1;
}
// Ham kiem tra so nguyen to
int so_nguyen_to(int N)
{
int i;
if(N == 1)
return 1;
else
{
for( i = 2; i < N/2; i++)
{
if(N % i == 0)
return 0;
}
return 1;
}
}
Bài 2:
#include <stdio.h>
2
for(int j = i + 1; j < n; j++){
if(a[i] < a[j]){
temp = a[i];
a[i] = a[j];
a[j] = temp;
}
}
}
}
Bài 3:
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
struct node {
int id;
char name[30];
struct node *next;
};
printf("\n[head] =>");
//bat dau tu phan dau cua list
while(ptr != NULL) {
printf(" id: %d, name: %s =>",ptr->id, ptr->name);
ptr = ptr->next;
}
printf(" [null]\n");
}
//link->key = key;
link->id = id;
strcpy(link->name, tenSV);
//tro link do toi first node cu
link->next = head;
4
int main() {
int id, n;
char name[30];//ten sv
insert(id,name);
}
// in danh sach sv
printList();
return 0;
}