Bài 200 : Tính tổng các phần tử trong mảng
Tải Code về máy
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
| #include<stdio.h>
#include<conio.h>
#define MAX 100
void nhapmang(int a[MAX],int &n)
{
do{
printf("Nhap vao so phan tu cua mang:n=");
scanf("%d",&n);
if(n<1||n>MAX)
printf("So ban nhap vao khong hop le!Xin vui long nhap lai!\n");
else
break;
}while(n<1||n>MAX);
for(int i=0;i<n;i++)
{
printf("Nhap vao a[%d]=",i);
scanf("%d",&a[i]);
}
}
void xuatmang(int a[MAX],int n)
{
for(int i=0;i<n;i++)
{
printf("%4d",a[i]);
}
printf("\n");
}
void tinhtongcacphantutrongmang(int a[MAX],int n)
{
int tong=0;
for(int i=0;i<n;i++)
{
tong+=a[i];
}
printf("\nTong cac phan tu co trong mang la:%d",tong);
}
void main()
{
int a[MAX],n,tieptuc;
quaylai:nhapmang(a,n);
printf("\n>>>>>>>>>>>>>>>>>>>>>>>>MANG VUA NHAP LA:<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<\n");
xuatmang(a,n);
tinhtongcacphantutrongmang(a,n);
printf("\nBan co muon tiep tuc chay chuong trinh hay khong ? Neu co bam phim C,nguoc lai bam bat ky 1 phim nao khac de ket thuc\n");
tieptuc=getch();
if(tieptuc=='c'||tieptuc=='C')
goto quaylai;
}
|
Nhận xét
Đăng nhận xét