#include <stdio.h>
#include <conio.h>
#include <stdlib.h>
#include <string.h>
#include <math.h>
typedef struct {
int n;
int pt[50];
}list;
void nhap(list &L) {
printf("So phan tu danh sach N= ");
scanf("%d",&L.n);
for(int i=1; i<=L.n; i++) {
printf("Phan tu thu %d: ",i);
scanf("%d",&L.pt[i]);
}
}
void xuat(list L){
for(int i=1;i<=L.n;i++){
printf("n[%d]: %d\n",i,L.pt[i]);
}
}
double TBC(list L){
int avg,sum=0;
double r;
for(int i=1;i<=L.n;i++){
sum+=L.pt[i];
}
return avg=(double)sum/L.n;
}
bool KTSNT(list L)
{
if(L.n<2)
return false;
for(int i=2; i<L.n/2; i++){
if(L.n%i==0){
return false;
}
return true;
}
}
int TongPTSNT(list L){
int tong=0;
for(int i=2; i<=L.n; i++){
if(KTSNT(L) == true){
tong += L.pt[i];
}
}
return tong;
}
/*int tichscp(list L){
int tich;
for(int i=1; i<=L.n; i++){
if(i*i == L.pt[i]){
tich *= L.pt[i];
}
}
return tich;
}
*/
int main(){
int i,avg,snt;
list L;
nhap(L);
xuat(L);
printf("TBC = %.2f\n", TBC(L));
printf("Tong SNT = %d\n", TongPTSNT(L));
//printf("Tich so chinh phuong: %d\n", tichscp(L));
}
bác nào giúp em fix với ạ.
Nhập n: 1 , 2, 3 , 4 ,5
Đúng là tổng = 10
Nhưng chương trình chạy = 15


83% thành viên diễn đàn không hỏi bài tập, còn bạn thì sao?