Bai3.cpp - #include<stdio.h>#include<math.h>#include<windows.h>#include<conio.h>#include<time.h>#include<stdlib.h> int n void Menu(int int randomN(int

Bai3.cpp -...

This preview shows page 1 - 2 out of 2 pages.

#include<stdio.h> #include<math.h> #include<windows.h> #include<conio.h> #include<time.h> #include<stdlib.h> int n; void Menu(int&); int randomN(int); int behonbangN(int); int giaithuaN(int); int F(int); int sohoanthien(int); int main(){ int chon; do{ system("CLS"); Menu(chon); switch(chon) { case 1: printf("Nhap N= "); scanf("%d",&n); break; case 2: randomN(n); break; case 3: behonbangN(n); break; case 4: giaithuaN(n); break; case 5: for (int i=1; i<n; i++) printf("%d ",F(i)); getch; F(n); break; case 6: if (sohoanthien(n) ) printf("%d la so hoan thien\n", n); else printf("%d khong phai la so hoan thien\n", n); return 0; break; case 0: break; default: printf("Ban chon sai. Moi ban chon lai MENU!\n"); break; } getch(); }while(chon!=0); return 0; } void Menu(int &chon) { printf("\t\t\t ======================MENU========================\n"); printf("\t\t\t |1. Nhap so nguyen duong N |\n"); printf("\t\t\t |2. Tao ra N so ngau nhien khoang tu 1 den 99 |\n"); printf("\t\t\t |3. In ra tat ca so nguyen to nho hon hoac bang N |\n");
Image of page 1

Subscribe to view the full document.

Image of page 2

Unformatted text preview: printf(&quot;\t\t\t |4. Tinh N giai thua |\n&quot;); printf(&quot;\t\t\t |5. In ra N so Fibonaci dau tien |\n&quot;); printf(&quot;\t\t\t |6. Kiem tra N co phai so hoan thien khong |\n&quot;); printf(&quot;\t\t\t |0. Thoat |\n&quot;); printf(&quot;\t\t\t ==================================================\n&quot;); printf(&quot;Ban chon: &quot;); scanf(&quot;%d&quot;, &amp;chon); } int randomN(int n){ srand(time(NULL)); for (int i=0; i&lt;n; i++){ printf(&quot;%d &quot;, rand()%100); } return 0; } int behonbangN(int n){ for (int i=0; i&lt;=n; i++) printf(&quot;%d &quot;,i); getch; } int giaithuaN(int n){ int gt=1; for (int i=1; i&lt;=n; i++) gt *=i; printf(&quot;%d!= %d&quot;,n, gt); getch; } int F(int n){ if(n==0) return 0; else if(n==1) return 1; return F(n-1)+F(n-2); } int sohoanthien(int n){ int tong=0; for (int i=1; i&lt;=n/2; i++){ if (n%i==0) tong +=i; } if (tong==n) return true; return false; }...
View Full Document

  • Spring '15
  • Thuy Do

What students are saying

  • Left Quote Icon

    As a current student on this bumpy collegiate pathway, I stumbled upon Course Hero, where I can find study resources for nearly all my courses, get online help from tutors 24/7, and even share my old projects, papers, and lecture notes with other students.

    Student Picture

    Kiran Temple University Fox School of Business ‘17, Course Hero Intern

  • Left Quote Icon

    I cannot even describe how much Course Hero helped me this summer. It’s truly become something I can always rely on and help me. In the end, I was not only able to survive summer classes, but I was able to thrive thanks to Course Hero.

    Student Picture

    Dana University of Pennsylvania ‘17, Course Hero Intern

  • Left Quote Icon

    The ability to access any university’s resources through Course Hero proved invaluable in my case. I was behind on Tulane coursework and actually used UCLA’s materials to help me move forward and get everything together on time.

    Student Picture

    Jill Tulane University ‘16, Course Hero Intern

Ask Expert Tutors You can ask You can ask ( soon) You can ask (will expire )
Answers in as fast as 15 minutes