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 Nguyệt
2020-12-21 03:29:48
#include <stdio.h>
#include <stdlib.h>
int main(void) {
int *p, i, sum=0;
p = (int *) malloc(10 * sizeof(int));
for(i=0;i<10;i++) {
printf("\nNhap p[%d] = ", i);
scanf("%d", p + i);
if (p[i]%2==0) {
sum+=p[i];
}
}
printf("\nSum div 2: %d\n", sum);
}
Đỗ Minh Tâm
2020-12-21 03:29:38
#include<stdio.h>
#include<stdlib.h>
int main(void){
int *p,i;
int sum=0;
p = (int *) malloc(10 * sizeof(int));
for(i=0;i<10;i++) {
printf("\nNhap pt[%d] = ", i);
scanf("%d", p+i);
if (p[i]%2==0){
sum+=p[i];
}
}
printf("\nsum: %d",sum);
}
Dao Thu Huyen
2020-12-21 03:29:02
#include <stdio.h>
#include <stdlib.h>
int main(void){
int *p,i,sum=0;
p= (int *) malloc(10 * sizeof(int));
for(i=0;i<10;i++) {
printf("\nNhap p[%d] = ", i);
scanf("%d",p+i);
if(p[i]%2==0){
sum+=p[i];
}
}
printf("Tong bang=%d",sum);
}
Đỗ Minh Tâm
2020-12-21 03:27:43
#include<stdio.h>
#include<stdlib.h>
int main(void){
int *p,i;
int sum=0;
p = (int *) malloc(10 * sizeof(int));
for(i=0;i<10;i++) {
printf("\nNhap pt[%d] = ", i);
scanf("%d", p+i);
if (p[i]%2==0){
sum+=p[i];
}
}
printf("\nsum: %d",sum);
}
Nguyễn Hữu Hiếu
2020-10-01 14:38:07
#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;
int i, count = 0;
p = (int *) malloc (10 * sizeof(int));
for(i=0;i<10;i++) {
printf("\nNhap phan tu thu p[%d]: ", i);
scanf("%d", p + i);
if(p[i] % 2 == 0) {
count = count + p[i];
}
}
printf("\nTong cac so chia het cho 2 la: %d", count);
return 0;
}
Nguyễn Anh Vũ
2020-09-22 16:19:26
#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[]) {
//bat dau code;
int *p, i, n=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+1);
}
for(i=0, i<10, i++){
if(p[i]%2=0){
n=n+p[i];
}
}printf("\nTong cac so chia het cho 2 = %d", n);
//ket thuc code;
return 0;
}
Trần Văn Lâm
2020-09-22 10:48:46
#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 , S = 0;
p = (int*) malloc(10*sizeof(int));
for(i=0;i<10;i++){
printf("\nNhap p[%d]=%d", i);
scanf("%d", &p[i]);
}
for(i=0;i<10;i++){
if(i%2==0){
S = S + p[i];
}
}printf("\nTong S la:%d", S);
return 0;
}
nguyễn Sử
2020-09-22 06:24:15
#include <stdio.h>
#include <stdlib.h>
int main(int argc, char *argv[]) {
int p[10], t[20], i;
int *p;
p = &p[10];
for (i=0 ;i<=10-1;i++){
printf("\nNhap p[%d]", i);
scanf("%d", &p[i]);
for (i=0;i<=10-1;i++){
if (i%2==0){
S = S + p[i];
}
printf("\ntong=%d", s);
return 0;
}
Trần Thị Khánh Huyền
2020-09-22 03:07:47
#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 t[5], i, sum;
printf("\nNhap phan tu cua mang t");
for(i=0;i<10;i++) {
printf("\nNhap t[%d] = ", i);
scanf("%d", t + i);
}
int *k;
k = t;
sum=0;
for(i=0;i<10;i++) {
printf("\nNhap k[%d] = %d", i, k[i]);
if (k[i]%2==0)
sum = sum +k[i];}
printf("dap so tong can tinh la: %d", sum);
return 0;
}
vuong huu phu
2020-09-21 14:59:09
#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 a[10];
int *p;
p= &a[10];
int i,t;
t=0;
for (i=0 ;i<=10-1;i++){
printf("\n nhap a[%d] ",i);
scanf("%d",&a[i]); }
for (i=0;i<=10-1;i++){
if (i%2==0){
t=t+i;
}
}printf ("\n tong cac so chia het cho 2 %d ",t);
return 0;
}