[2019-2] 프로그래밍실습II 로또번호 생성 프로그램 과제

2022. 1. 6. 01:17·학교
#include <stdio.h>
#include <stdlib.h>
#include <time.h>
#include <algorithm>
using namespace std;

void lottoGen(int lotto[]);
int computeSum(const int lotto[]);
int oddEven(const int lotto[]);

int main() {
 int lotto[6];
 int count = 0, find, num, sum, odd;

 srand((unsigned int)time(NULL));

 while(count<10) {
   lottoGen(lotto);

   sum = computeSum(lotto);
   odd = oddEven(lotto);

   if (sum >= 81 && sum <= 200 && odd!=0) {
    sort(lotto, lotto + 6);

    for (int k = 0; k < 6; k++) {
     printf("%2d ", lotto[k]);
    }
    printf(" : %d [%d : %d]\n", sum, odd, 6-odd);
    
    count++;
   }
   
  }
 return 0;
}

void lottoGen(int lotto[]) {
 int num, find, count;
  lotto[0] = rand() % 45 + 1;
  count = 1;
  while(count < 6){
   num = rand() % 45 + 1;
   find = 0;
   for (int j = 0; j < count; j++) {
    if (num == lotto[j])
     find = 1;
    break;
   }
   if (find == 0) { //!find
    lotto[count] = num;
    count++;
   }
  }
 }

int computeSum(const int lotto[]) {
 int sum = 0;

 for (int i = 0; i < lotto[i]; i++)
  sum += lotto[i];

 return sum;
}

int oddEven(const int lotto[]) {
 int odd = 0;
 int a, b;
 for (int i = 0; i < 6; i++) {
  if (lotto[i] % 2 == 1)
   odd++;
 }
 if (odd >= 2 && odd <= 4) // 홀수가 2, 3, 4
  return odd;
 else
  return 0;
}

'학교' 카테고리의 다른 글

[2018-2] 웹프로그래밍II 프로젝트 - 장바구니 구현하기  (0) 2022.01.06
[2019-2] 프로그래밍실습II 빙고게임 과제  (0) 2022.01.06
[2019-2] 디지털신호처리 새 소리 만들기 과제  (0) 2022.01.06
[2019-2] 디지털신호처리 첩 신호 만들기 과제  (0) 2022.01.06
[2019-1] 임베디드시스템 프로젝트  (0) 2021.08.26
'학교' 카테고리의 다른 글
  • [2018-2] 웹프로그래밍II 프로젝트 - 장바구니 구현하기
  • [2019-2] 프로그래밍실습II 빙고게임 과제
  • [2019-2] 디지털신호처리 새 소리 만들기 과제
  • [2019-2] 디지털신호처리 첩 신호 만들기 과제
덩이
덩이
찍먹 대마왕
  • 덩이
    Devlog
    덩이
  • 전체
    오늘
    어제
    • 분류 전체보기 (118)
      • 강의 (68)
        • SAP ERP (11)
        • KOSTA (32)
        • Inflearn (0)
        • etc (25)
      • 회사 (0)
        • 스터디 (3)
        • 전자정부 (0)
      • 학교 (15)
      • 스터디 (30)
        • 알고리즘 (25)
        • 프로젝트 (3)
        • 에러 (2)
        • 자격증 (0)
      • 기타 (2)
        • 자료 (1)
        • 회고록 (1)
  • 블로그 메뉴

    • 홈
    • 태그
    • 방명록
  • 링크

    • GitHub
    • Naver
  • 공지사항

  • 인기 글

  • 태그

  • 최근 댓글

  • 최근 글

  • hELLO· Designed By정상우.v4.10.3
덩이
[2019-2] 프로그래밍실습II 로또번호 생성 프로그램 과제
상단으로

티스토리툴바