By GokiSoft.com|
20:18 14/12/2021|
Lập Trình C
Tính tổng mảng N phần tử - Lập trình C
Tạo 1 mảng gồm N phần tử => N nhập từ bàn phím
In ra các phần tử trong mảng
Tính tổng các phần tử trong mảng
Tags:
Phản hồi từ học viên
5
(Dựa trên đánh giá ngày hôm nay)
![Do Trung Duc [T2008A]](https://www.gravatar.com/avatar/2973ac07124f066b4605c535e8d39a99.jpg?s=80&d=mm&r=g)
Do Trung Duc
2020-09-17 03:17:41
#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 N;
printf("\nNhap gia tri dai index mang N=");
scanf("%d", &N);
int k[N], i;
for(i =0; i<=N; i++){
printf("\nNhap gia tri cho phan tu k[%d]=", i);
scanf ("%d", &k[i]);
}
for(i =0; i<=N; i++){
printf("\nGia tri phan tu trong mang = %d", k[i]);
}
int tong;
tong = 0;
for(i =0; i<=N; i++){
tong = tong + k[i];
}
printf("\n Tong gia tri cac phan tu trong mang = %d", tong);
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-17 03:06:54
#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 n;
printf("\nnhap n: "); scanf("%d",&n);
int A[n];
int i;
for(i=1;i<=n;i++) {
printf("\nnhap A[%d]: ",i); scanf("%d",&A[i]);
}
for(i=1;i<=n;i++){
printf("\nA[n]: %d",A[i]);
}
int S=0;
for(i=1;i<=n;i++){
S=S+i;
}
printf("\ntong cac phan tu trong A la: %d",S);
return 0;
}
![Trần Văn Lâm [T2008A]](https://www.gravatar.com/avatar/cfc15c8cb7781ad669b013e01f9f1a6b.jpg?s=80&d=mm&r=g)
Trần Văn Lâm
2020-09-17 02:30:17
#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 N;
printf("\nNhap so N:");
scanf("%d", &N);
int h[N], i, s;
s = 0;
i = 1;
for(i = 1; i < N; i++){
printf("\nNhap h[%d]:", i);
scanf("%d", &h[i]);
}
for(i = 1; i < N; i++){
s += h[i];
printf("\nTong s = %d", s);
}
return 0;
}
![hainguyen [T2008A]](https://www.gravatar.com/avatar/32855ce6db55d60134d830aee06b41e5.jpg?s=80&d=mm&r=g)
hainguyen
2020-09-16 16:14:05
#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];
int n;
printf("\nNhap t[0]= ");
scanf("%d", &t[0]);
printf("\nNhap t[1]= ");
scanf("%d", &t[1]);
printf("\nNhap t[2]= ");
scanf("%d", &t[2]);
printf("\nNhap t[3]= ");
scanf("%d", &t[3]);
printf("\nNhap t[4]= ");
scanf("%d", &t[4]);
n = t[0] + t[1] + t[2] + t[3] + t[4];
printf("\ntong cua cac phan tu la: %d", n);
return 0;
}