HN - Aptech
Bạn có muốn phản ứng với tin nhắn này? Vui lòng đăng ký diễn đàn trong một vài cú nhấp chuột hoặc đăng nhập để tiếp tục.

HN - Aptech


 
Trang ChínhTrang Chính  PortalPortal  GalleryGallery  Latest imagesLatest images  Tìm kiếmTìm kiếm  Đăng kýĐăng ký  Đăng NhậpĐăng Nhập  

 

 [Code 1] :Module test practical

Go down 
2 posters
Tác giảThông điệp
spyware
Đại Bàng Tinh
Đại Bàng  Tinh
spyware


Tổng số bài gửi : 116
Join date : 04/06/2009
Age : 39
Đến từ : HN

[Code 1] :Module test practical Empty
Bài gửiTiêu đề: [Code 1] :Module test practical   [Code 1] :Module test practical Icon_minitimeFri Jun 12, 2009 11:36 pm

Code:
/*Question 3:
Write menu-based program with the following menu:
1. Input N and array of integer
2. Find the largest negative number value
3. Count the number that is not square numbers
4. sort all elements by descending and display them
5. Exit

Q1: Input N and array of integer
  when user chooses 1 from main menu, do the followings
- fist, display 'N=' and accept positive integer N
- then, accept N integer and store them into array
Q2: Find the largest negative number value
  when user chooses 2 from main menu, find the largest numbet
value in the array (which accept in the first menu) and return this value
to the main function for printing out.
(Note: if the array has no negative number, return 0)
Q3: Count the number that is no square numbers
 when the user chooses 3 from main menu, count the number that is
not square number and return it to the main function for printing out
(it the array has no numbe, dispay 0)
Q4: Sort all element by decending and display them
 when user chooses 4 from main menu, sort all elements by decending
and display
Q5: Exit
 when user chooses 5 from main menu, the program will be exit. */

#include<conio.h>
#include<stdio.h>
// khai bao ham con
void input(int a[], int *n);
void show(int a[], int n); // hien thi mang vua nhap
int maxne(int a[], int n);// tra ve cho ham main in ra
int checkcp(int n); // kiem tra so chinh phuong
int notcp(int a[], int n); // tra ve cho ham main in ra
void sort(int a[],int n);//sau khi sap xep hien thi ngay trong ham con
void menu(void);
// Define main function
void main()
{
int choice,i,n,p[100];
clrscr();
do
{
clrscr();
menu();
scanf("%d",&choice);
switch(choice)
   {
   case 1: input(p,&n); getch(); break;
   case 2: show(p,n);
      printf("\nThe largest negative number is: %d",maxne(p,n));
      getch(); break;
   case 3: show(p,n);
      printf("\nHas [%d] number that is not square number.",notcp(p,n));
      getch(); break;
   case 4: show(p,n);sort(p,n); getch(); break;
   case 5: exit(0);
   }
} while(choice!=5);
getch();
}
//// Define functions ////
//define menu function
void menu(void)
{
   printf("\n1. Input N and array of integer");
   printf("\n2. Find the largest negative number value");
   printf("\n3. Count the number that is not square numbers");
   printf("\n4. Sort all elements by decending and display them");
   printf("\n5. Exit");
   printf("\n  Pleases enter your choice !");
}
//Define input function
void input(int a[],int *n)
{
   int i;
   printf("N= ");
   scanf("%d",n);
   for(i=0;i<*n;i++)
   {
      printf("a[%d]= ",i);
      scanf("%d",&a[i]);
   }

}
// Define show function
void show(int a[],int n)
{
   int i;
   printf("\nInput array:");
   for(i=0;i<n;i++)
      printf("%5d",a[i]);
}
// Define function to find the largest negative number
int maxne(int a[],int n)
{
   int i,j,am,kt=0;
   for(i=0;i<n;i++)
   {
      if(a[i]<0)
      {
         am=a[i];
         kt++;
         break;
      }
   }
   for(j=i+1;j<n;j++)
   {
      if(a[j]<0 && a[j]>am) am=a[j];
   }
   if(kt)    return am;
   return 0;
}
// define check square number function
int checkcp(int n)
{
   int i,kt=0;
//   if(n<0) return 0;
   for(i=1;i<=n;i++)
      if(i*i==n) kt++;
   if(kt)   return 1;
   return 0;
}
// define count number that not square number function
int notcp(int a[],int n)
{
   int dem=0,i,j;
   for(i=0;i<n;i++)
   {
      if(checkcp(a[i])==0) dem++;
   }
   if(dem==0) return 0;
   return dem;

}
// define sort function
void sort(int a[],int n)
{
   int i,j,temp;
   for(i=0;i<n-1;i++)
      for(j=i+1;j<n;j++)
      {
         if(a[j]>a[i])
         {
         temp=a[i];
         a[i]=a[j];
         a[j]=temp;
         }
      }
printf("\n");
for(i=0;i<n;i++)
   printf("%5d",a[i]);
}
Về Đầu Trang Go down
spyware
Đại Bàng Tinh
Đại Bàng  Tinh
spyware


Tổng số bài gửi : 116
Join date : 04/06/2009
Age : 39
Đến từ : HN

[Code 1] :Module test practical Empty
Bài gửiTiêu đề: Re: [Code 1] :Module test practical   [Code 1] :Module test practical Icon_minitimeFri Jun 12, 2009 11:49 pm

/* Question 1 */

/*1. Find and return max and min of N real number */
void minmax(float a[], int n,float *min,float *max);

/*2. Find and return the largest string of N strings */
void maxstr(char (*p)[100], int n,char *maxs);

/*3. Check whether an integer is prime or not */
int ktrahh(int n);

/*4. Funtion for printing N float numbers */
void inf(float a[],int n);
Về Đầu Trang Go down
spyware
Đại Bàng Tinh
Đại Bàng  Tinh
spyware


Tổng số bài gửi : 116
Join date : 04/06/2009
Age : 39
Đến từ : HN

[Code 1] :Module test practical Empty
Bài gửiTiêu đề: Re: [Code 1] :Module test practical   [Code 1] :Module test practical Icon_minitimeSat Jun 13, 2009 7:09 pm

Code:
/* Question 2
Write a program to accept one string, after that count the number of words
and trim all space character at the last of string (you must print length
of string before and after trim).
the program must be divided into three modules which do the followings:
- Accept one string from user's input
- Count the number of words
- Trim all space character at the last of string
(you must be printf length of string before and after trim).*/

#include<conio.h>
#include<stdio.h>
#include<string.h>
void input(char a[]);
int count(char a[]);
void cuts(char a[]);
// Define main function
void main()
{
   char str[100];
   clrscr();
   input(str);
   printf("Numbers of words is: %d",count(str));
   cuts(str);
getch();
}
// Define function
// Define input function
void input(char a[])
{
   printf("Input string:");
   fflush(stdin);
   gets(a);
}
// Define count function
int count(char a[])
{
   int i,j,n,dem;
   n=strlen(a);
   for(i=0,dem=0; i<n; i++)
      if(a[i]!=' '&& a[i]!='\t')
      {
         for(j=i+1;j<n;j++)
         {
            if(a[j]!=' '&& a[j]!='\t'&& a[j]!='\0')
            continue;
            else
            {
               dem++;
               i=j;
               break;
            }
         }
      }
   return dem;
}
// Define Cuts function
void cuts(char a[])
{
   int i,n;
   n=strlen(a);
   printf("\nLength of string before trim: %d",n);
   for(i=n-1;i>=0;i--)
      if(a[i]==' '|| a[i]=='\t')   a[i]='\0';
      else break;
   printf("\nString after trim: ");
   puts(a);
   printf("Length of string after trim: %d",strlen(a));
}
Về Đầu Trang Go down
spyware
Đại Bàng Tinh
Đại Bàng  Tinh
spyware


Tổng số bài gửi : 116
Join date : 04/06/2009
Age : 39
Đến từ : HN

[Code 1] :Module test practical Empty
Bài gửiTiêu đề: Re: [Code 1] :Module test practical   [Code 1] :Module test practical Icon_minitimeSat Jun 13, 2009 7:39 pm

- các file txt đính kèm ( hok hỉu sao, 4r không có chức năng gửi file đính kèm nhỉ)

link http://www.mediafire.com/file/jzxxjnntut1/Code 1.rar
Về Đầu Trang Go down





Join date : 01/01/1970

[Code 1] :Module test practical Empty
Bài gửiTiêu đề: Re: [Code 1] :Module test practical   [Code 1] :Module test practical Icon_minitimeMon Jun 29, 2009 1:29 am

sao em làm code ham trim nó ko cắt khoảng trắng nhờ?????????
Về Đầu Trang Go down
Sponsored content





[Code 1] :Module test practical Empty
Bài gửiTiêu đề: Re: [Code 1] :Module test practical   [Code 1] :Module test practical Icon_minitime

Về Đầu Trang Go down
 
[Code 1] :Module test practical
Về Đầu Trang 
Trang 1 trong tổng số 1 trang
 Similar topics
-
» [Code 2] Module test practical
» code 09 thiếu EXAM1 mời các bác vào chém code hay cực (menu)
» code:08/day du!/code nay kha hay, cac ban tham khao!!
» code 19 đã ok các chú các bác vào chém đê !!!!!!!!!!!(code fia dứơi nhé)
» code 13 chua co Q1 ai vào bổ xung em fat^_^ (góp tí cho xôm)

Permissions in this forum:Bạn không có quyền trả lời bài viết
HN - Aptech :: Khóa Học :: SEMESTER I :: C :: Bài Tập-
Chuyển đến