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)
![An Văn Minh [T2008A]](https://www.gravatar.com/avatar/e0f14efe4b11f7d9d5901e8802319c92.jpg?s=80&d=mm&r=g)
An Văn Minh
2020-09-22 07:46:57
#include<stdio.h>
#include<stdlib.h>
int main(){
int N;
printf("\nNhap N:");
scanf("%d", &N);
int t[N],i;
int s=0;
for(i=0;i<N;i++){
printf("\nt[%d]:", i);
scanf("%d", &t[i]);
}
for(i=0;i<N;i++){
s=s+t[i];
}
printf("\nTong= %d", s);
return 0;
}
![Nguyễn Anh Vũ [T2008A]](https://www.gravatar.com/avatar/8863d24ed74b396082becbc4db8331fd.jpg?s=80&d=mm&r=g)
Nguyễn Anh Vũ
2020-09-20 08:21:00
#include <stdio.h>
#include <stdlib.h>
/* run this program using the console pauser or add your own getch, system("pause") or input loop */
//bat dau code
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);
}
//ket thuc code
;
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-18 05:28:29
#include "bits/stdc++.h"
int main() {
int n;
printf("\nNhap n: "); scanf("%d", &n);
int a[n];
for (int i = 0; i < n; i++) printf("\nNhap a[%d]: ", i + 1), scanf("%d", &a[i]);
for (int i = 0; i < n; i++) printf("\na[%d] = %d", i + 1, a[i]);
int sum = 0;
for (int i = 0; i < n; i++) sum += a[i];
printf("\nTong: %d", sum);
return 0;
}
![Bùi Văn Mạnh [T2008A]](https://www.gravatar.com/avatar/17e9c94870c94e61c9203ee31dccf01c.jpg?s=80&d=mm&r=g)
Bùi Văn Mạnh
2020-09-18 04:47:16
#include <stdio.h>
#include <stdlib.h>
int main() {
int i, n, tong;
printf("\Nhap n = ");
scanf("%d",&n);
tong=0;
int k[i];
for (i=0;i<n;i++){
printf("\nNhap k[%d]: ",i);
scanf("%d", &k[i]);
tong=tong+k[i];
}
printf("Tong cua cac so trong day la %d", tong);
return 0;
}
![Trần Thị Khánh Huyền [T2008A]](https://www.gravatar.com/avatar/554e115833778e4294a01aebe228f3d6.jpg?s=80&d=mm&r=g)
Trần Thị Khánh Huyền
2020-09-18 00:56:06
#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, i, sum;
printf("\Nhap n = ");
scanf("%d",&n);
sum=0;
int t[i];
for (i=0;i<n;i++){
printf("\nNhap t[%d]: ",i);
scanf("%d", &t[i]);
sum=sum+t[i];
}
printf("Tong cua cac so trong day la %d", sum);
return 0;
}
![Nguyễn Hữu Hiếu [T2008A]](https://www.gravatar.com/avatar/ca2884508b617fee77f000c7d99c219d.jpg?s=80&d=mm&r=g)
Nguyễn Hữu Hiếu
2020-09-17 09:42: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 i,n, tong = 0;
printf("\nNhap n:");
scanf("%d", &n);
int array[n];
for(i=0;i<n;i++) {
printf("\nNhap phan tu thu %d " , i);
scanf("%d", &array[i]);
tong = tong + array[i];
}
for (i=0;i<n;i++) {
printf("%d, ", array[i]);
}
printf("\nTong cac phan tu: %d", tong);
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-17 04:09: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 n: ");
scanf("%d",&n);
if (n<=0){
printf("Sai index");
}
else{
int a[n],i,tong=0;
for(i=0;i<n;i++){
printf("Nhap a[%d] = ",i);
scanf("%d",&a[i]);
tong=tong+ a[i];
}
for(i=0;i<n;i++){
printf("a[%d] = %d\n",i,a[i]);
}
printf("Tong cac phan tu = %d",tong);
}
return 0;
}
![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-17 03:49:18
#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 i,n,tong=0;
printf("\nNhap so nguyen N:");
scanf("%d",&n);
int t[n];
for(i=0;i<=n-1;i++){
printf("\nNhap t[%d]:",i);
scanf("%d",&t[i]);
}
for(i=0;i<=n-1;i++){
printf("%d ",t[i]);
tong += t[i];
}
printf("\nTong = %d",tong);
return 0;
}
![nguyễn Sử [T2008A]](https://www.gravatar.com/avatar/47487be2776ac2ec915b0936ef7ab5ae.jpg?s=80&d=mm&r=g)
nguyễn Sử
2020-09-17 03:28:39
int main(int argc, char *argv[]) {
int i = 1, n, tong ;
printf("\nNhap gia tri n: ");
scanf("%d",&n);
int a[n];
for(i = 1; i < n; i++){
printf("\nNhap gia tri a[%d]: ", i);
scanf("%d", &a[i]);
}
for(i=1;i<n;i++){
tong=tong+a[i];
}printf("\n tong= %d",tong);
return 0;
}
![vuong huu phu [T2008A]](https://www.gravatar.com/avatar/307a5cf29780afab49706dc8b15b86c6.jpg?s=80&d=mm&r=g)
vuong huu phu
2020-09-17 03:21:00
#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,i,t;
t=0;
i=1;
printf("\n nhap n = ");
scanf("%d",&n);
int a [n];
for(i=1;i<n;i++){
printf("\n nhap a[%d]",i);
scanf("%d",&a[i]);
}
for(i=1;i<n;i++){
t=t+a[i];
}printf("\n tong = %d",t);
return 0;
}