Câu 4.1: Viết chương trình nhập vào từ bàn phím n số thực, hãy ghi các số thực dương vào một tệp văn bản

Thursday, November 27, 2014
dữ liệu vừa nhập sẽ lưu vào file có địa chỉ  C:\\outputbai41.txt
//code Dung NV
#include <stdio.h>
#include <conio.h>
void nhap(float a[],int n)
{
                int i;
                for (i=0;i<n;i++)
                {
                                printf("\nNhap phan tu thu   %d   :    ",i);
                                scanf("%f",&a[i]);
                }
}
void ghitep(float a[],int n,FILE *v)
{
                int i;
                for (i=0;i<n;i++)
                                if (a[i]>0)
                                                fprintf(v,"   %5.2f   ",a[i]);
}
void main()
{
                int n;
                float a[100];
                FILE *u;
                u=fopen("c:\\outputbai41.txt","wt");
                printf("\nNhap so phan tu: n=    ");
                scanf("%d",&n);
                nhap(a,n);
                ghitep(a,n,u);
                fclose(u);
                printf("\nhoan tat");
                getch();
}
Chia sẻ bài viết ^^
Other post

All comments [ 0 ]


Your comments