Calculate friend count if in the Nth week, N friends dropped out and the remaining number doubled. - C Language Basics

C examples for Language Basics:printf

Description

Calculate friend count if in the Nth week, N friends dropped out and the remaining number doubled.

Demo Code

#include <stdio.h>

int main(void)
{
  const int DUNBARS_NUMBER = 150;

  int friends = 5, week = 0;

  printf("Week | Friends\n");
  printf("-----+--------\n");
  while (friends < DUNBARS_NUMBER)
  {/*from w  w w . ja  v a  2  s  .co  m*/
    printf("%4d | %7d\n", week, friends);
    week++;
    friends -= week;
    friends *= 2;
  }

  return 0;
}

Result


Related Tutorials