Extremal problems for cycles in graphs and hypergraphs