By GokiSoft.com|
20:11 20/09/2023|
Lập Trình C
Bài toán pointer đầu tiên - Hello pointer - Lập trình C
- Khai báo con trỏ *p
- Cấp phát mảng p gồm 10 phần tử
- Nhập các phần tử trong mảng
- Tính tổng các số chia hết cho 2 trong mảng p
Tags:
Phản hồi từ học viên
5
(Dựa trên đánh giá ngày hôm nay)
![Nguyên Phấn Đông [community]](https://www.gravatar.com/avatar/c9c4f8f79ce35b9224637b6cc5fbe5c4.jpg?s=80&d=mm&r=g)
Nguyên Phấn Đông
2020-09-21 14:47:52
#include<stdio.h>
#include<stdlib.h>
int main(){
int n=10,t[10],i;
int *p=t;
for(i=0;i<10;i++){
printf("p[%d]:", i);
scanf("%d", &p[i]);
}
int s=0;
for(i=0;i<10;i++){
if(t[i]%2==0){
s=s+t[i];
}
}
printf("\nTong=%d", s);
return 0;
}
![Do Trung Duc [T2008A]](https://www.gravatar.com/avatar/2973ac07124f066b4605c535e8d39a99.jpg?s=80&d=mm&r=g)
Do Trung Duc
2020-09-21 14:24:58
#include <stdio.h>
#include <stdlib.h>
/* run this program using the console pauser or add your own getch, system("pause") or input loop */
int main(int argc, char *argv[]) {
int *p, S, i;
p = (int*) calloc (10 , sizeof(int));
S = 0;
for(i=0;i<10;i++){
printf("Nhap phan tu p[%d] = ", i);
scanf("%d", &p[i]);
}
for(i=0;i<10;i++){
if(p[i] % 2 ==0){
S = S + p[i];
}
}
printf("Tong cac so chia het cho 2 trong mang p la S = %d ", S);
return 0;
}
![An Văn Minh [T2008A]](https://www.gravatar.com/avatar/e0f14efe4b11f7d9d5901e8802319c92.jpg?s=80&d=mm&r=g)
An Văn Minh
2020-09-21 12:34:55
#include<stdio.h>
#include<conio.h>
#include<math.h>
int main(){
int N=10;
int t[N],i;
int *p=t;
for(i=0;i<N;i++){
printf("\np[%d]:", i);
scanf("%d", &p[i]);
}
int s=0;
for(i=0;i<N;i++){
if(i%2==0){
s=s+i;
}
}
printf("\nTong=%d", s);
return 0;
}
![hainguyen [T2008A]](https://www.gravatar.com/avatar/32855ce6db55d60134d830aee06b41e5.jpg?s=80&d=mm&r=g)
hainguyen
2020-09-21 11:26:13
#include <stdio.h>
#include <stdlib.h>
/* run this program using the console pauser or add your own getch, system("pause") or input loop */
int main(int argc, char *argv[]) {
int *p, i;
p = (int *) malloc (10 * sizeof(int));
for(i=0; i<10; i++){
printf("\nNhap p[%d] = ", i);
scanf("%d", p + i);
}
int num = 0;
for(i=0; i<10; i++){
if(p[i]%2 == 0){
printf("\n%d", p[i]);
num = num + p[i];
}
}
printf("\nTong cac so chia het cho 2 la: %d", num);
return 0;
}
![Triệu Văn Lăng [T2008A]](https://www.gravatar.com/avatar/1348e3562c6492c26f796cb1f45982a1.jpg?s=80&d=mm&r=g)
Triệu Văn Lăng
2020-09-21 10:10:33
#include <stdio.h>
#include <stdlib.h>
/* run this program using the console pauser or add your own getch, system("pause") or input loop */
int main(int argc, char *argv[]) {
int *p, i;
p= (int*) malloc (10*sizeof(int));
for(i=0;i<10;i++) {
printf("\nnhap p[%d]=",i);
scanf("%d",p+i);
}
int sum=0;
for(i=0;i<10;i++) {
if(p[i]%2==0) {
sum=sum+p[i];
}
}
printf("\ntong cac so chia het cho 2 la: %d",sum);
return 0;
}
![Đặng Trần Nhật Minh [T2008A]](https://www.gravatar.com/avatar/ee8dc5a777ad26f3a962e86c233437cf.jpg?s=80&d=mm&r=g)
Đặng Trần Nhật Minh
2020-09-21 09:42:00
#include <stdio.h>
#include <stdlib.h>
int main() {
int *p, sum = 0;
p = (int *)malloc(10 * sizeof(int));
for (int i = 0; i < 10; i++) {
printf("Nhap a[%d] = ", i);
scanf("%d", p + i);
if (*(p + i) % 2 == 0) sum += *(p + i);
}
printf("SUM = %d", sum);
return 0;
}
![Nguyễn Tiến Đạt [T2008A]](https://www.gravatar.com/avatar/b5819cd0adc95c727c7ad0c2bcf6098b.jpg?s=80&d=mm&r=g)
Nguyễn Tiến Đạt
2020-09-21 09:15:47
#include<stdio.h>
#include<stdlib.h>
int main(){
int *p,i,tong=0;
p=(int)malloc(10 * sizeof(int));
printf("\nNhap gia tri cac phan tu:");
for(i=0;i<10;i++){
printf("\np[%d]= ",i);
scanf("%d",p+i);
}
for(i=0;i<10;i++){
if(p[i] % 2==0){
tong=tong+p[i];
}
}
printf("\nTong cac phan tu chan la %d",tong);
}
![Nguyễn Xuân Mai [T2008A]](https://www.gravatar.com/avatar/d3d863d6f47708501814fb41e9c38f31.jpg?s=80&d=mm&r=g)
Nguyễn Xuân Mai
2020-09-21 09:06:39
#include <stdio.h>
#include <stdlib.h>
/* run this program using the console pauser or add your own getch, system("pause") or input loop */
int main(int argc, char *argv[]) {
int *p,i,tong=0;
p = (int *) malloc (10 * sizeof(int));
printf("\nNhap phan tu cua mang p");
for(i=0;i<10;i++){
printf("\nNhap p[%d] = ", i);
//scanf("%d", &p[i]);
scanf("%d", p + i);
}
for(i=0;i<10;i++){
if(p[i]%2==0){
tong=tong+p[i];
}
}printf("Tong cac so chia het cho 2 = %d ",tong);
return 0;
}