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 BT1893

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

Liên kết rút gọn:

https://gokisoft.com/1893

Bình luận

avatar
An Văn Minh [T2008A]
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;
}


avatar
Nguyễn Anh Vũ [T2008A]
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;
}


avatar
Đặng Trần Nhật Minh [T2008A]
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;

}


avatar
Bùi Văn Mạnh [T2008A]
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;
}


avatar
Trần Thị Khánh Huyền [T2008A]
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;
}


avatar
Nguyễn Hữu Hiếu [T2008A]
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;
}


avatar
Nguyễn Tiến Đạt [T2008A]
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;
}


avatar
Nguyễn Xuân Mai [T2008A]
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;
}


avatar
nguyễn Sử [T2008A]
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;
}
	



avatar
vuong huu phu [T2008A]
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;
}