1. Write a program that asks the user to type 10 integers of an array. The program must compute and write how many integers are greater than or equal to 10.
Code: int b[10];
int i;
int s=0;
for (i=0;i<10;i++){
printf("So thu %d
:",i+1);
scanf("%d",&b[i]);
}
for(i=0;i<10;i++){
if (b[i]>10){
s=s+1;
}
}
printf("Co %d so lon hon
10",s);
Bài 2: Write a program that asks the user to type 10 integers of an array. The program must output the largest element in the array, and the index at which that element was found.
Code:int a[10];
int max=a[0];
int index;
int i;
for(i=0;i<10;i++){
printf("So thu %d: ",i+1);
scanf("%d",&a[i]);
}
for(index=0,i=1;i<10;i++){
if(a[i]>max){
max
=a[i];
index=i+1;
}
}
printf("So lon nhat trong mang
la %d",max);
printf("\nSo do nam o vi tri
thu %d",index);
Bài 3:Input values are accepted from the user into the array. Displays highest of the entered values. Prints average of values entered.
Code:int a[10];
int max=a[0];
int index;
int i;
float sum;
for(i=0;i<10;i++){
printf("So thu %d: ",i+1);
scanf("%d",&a[i]);
}
for(index=0,i=1;i<10;i++){
if(a[i]>max){
max
=a[i];
index=i+1;
}
}
for(i=0;i<10;i++){
sum=sum+a[i];
}
printf("So lon nhat trong mang
la %d",max);
printf("\nTrung binh la
%.2f",sum/10);
Bài 4:Write a program that accepts the following numbers in an array and reverses the array
int a[10];
int
max=a[0];
int index;
int i;
float sum;
for(i=0;i<10;i++){
printf("So
thu %d: ",i+1);
scanf("%d",&a[i]);
}
for(i=9;i>=0;i=i-1){
printf("\na[%d]:%d",i+1,a[i]);
}
Bài 5: Write a program to
count the number of vowels in a line of text
Code:char b[100];
Code:char b[100];
int s=0,i;
printf("Moi nhap
day :");
scanf("%s",b);
for(i=0;i<100;i++){
if(b[i]=='a'||b[i]=='i'||b[i]=='o'||b[i]=='u'||b[i]=='e'||b[i]=='A'||b[i]=='I'||b[i]=='O'||b[i]=='U'||b[i]=='E'){
s=s+1;
}
}
printf("So nguyen
am la: %d",s);
Bài 6:. Write a program that asks the user to type 10 integers of an array and
an integer V. The program must search if V is in the array of 10 integers. The
program writes "V is in the array" or "V is not in the
array".
Code:(Quên Save):
Bài 7:Write a program that asks the user to type 10 integers of an array and
an integer value V. The program must search if the value V exists in the array
and must remove the first occurrence of V, shifting each following element left
and adding a zero at the end of the array. The program must then write the
final array
Code:int n[10];
int i;
int v;
printf("Nhap vao
so V: ");
scanf("%d",&v);
for(i=0;i<10;i++){
printf("Nhap vao so%d:
",i+1);
scanf("%d",&n[i]);
}
for(i=0;i<10;i++){
if(n[i]==v){
for(;i<10;i++){
n[i]=n[i+1];
}
n[9]=0;
}
}
printf("final
aray");
for(i=0;i<10;i++){
printf("%d\t",n[i]);
}
Bài 8:. Write a program that
asks the user to type 10 integers of an array and an integer value V and an
index value i between 0 and 9. The program must put the value V at the place i
in the array, shifting each element right and dropping off the last element.
The program must then write the final array
Code:int a[10];
Code:int a[10];
int index;
int i;
int v;
int j;
printf("Xin moi nhap V:
");
scanf("%d",&v);
printf("Xin moi nhap index:
");
scanf("%d",&index);
for(i=0;i<5;i++){
printf("Xin
moi nhap So %d :",i+1);
scanf("%d",&a[i]);
}
j=index;
for(j;j<5;j++){
a[j+1]=a[j];
}
a[index]=v;
printf("Final array:
");
for(i=0;i<5;i++){
printf("%d\t",a[i]);
}
Bài 9:Write a program that asks the user to type 10 integers of an array. The
program will then display either "the array is growing", "the
array is decreasing", "the array is constant", or "the
array is growing and decreasing
Code:int
tang=0,giam=0,hang=0;
int i=0;
int a[size];
for(i=0;i<size;i++){
printf("Xin moi nhap so %d:
",i+1);
scanf("%d",&a[i]);
}
for(i=0;i<size;i++){
if(a[i]<a[i+1]){
tang=tang+1;
}
if(a[i]>a[i+1]){
giam=giam+1;
}
if(a[i]==a[i+1]){
hang=hang+1;
}
}
if(tang== (size-1)){
printf("Array
is growing");
}
else if (giam == (size-1)){
printf("Array
is decrease");
}
else if (hang==(size-1)){
printf("Array
is constant");
}
else{
printf("Array
is growing and decrease");
}
return 0;
Bài 10:Write a program that
asks the user to type 10 integers of an array. The program will then sort the
array in descending order and display it.
Code:int a[10];
Code:int a[10];
int i;
for(i=0;i<10;i++){
printf("Xin
moi nhap So %d :",i+1);
scanf("%d",&a[i]);
}
printf("Final array:
");
for(i=9;i>=0;i=i-1){
printf("%d\t",a[i]);
}
Bài 11: Write a program which takes 2 arrays of 10 integers each, a and b. c is an array with 20 integers. The program should put into c the appending of b to a, the first 10 integers of c from array a, the latter 10 from b. Then the program should display c.
Code:int
a[10],b[10],c[20];
int i;
printf("Xin
moi nhap day thu 1\n");
for
(i=0;i<10;i++){
printf("So thu %d
:",i+1);
scanf("%d",&a[i]);
}
printf("Xin
moi nhap day thu 2\n");
for
(i=0;i<10;i++){
printf("So thu %d
:",i+1);
scanf("%d",&b[i]);
}
for(i=0;i<10;i++){
c[i]=a[i];
c[i+10]=b[i];
}
printf("Day
thu 3:\n");
for(i=0;i<20;i++){
printf("%d\t",c[i]);
}
Nhận xét
Đăng nhận xét