Untitled
unknown
c_cpp
9 months ago
822 B
3
Indexable
#include <stdio.h> #include <string.h> typedef struct { int duration; char title[ 100 ]; } Movie; Movie findShortestMovie( Movie movies[], int size ) { Movie shortestMovie = movies[ 0 ]; for( int i = 1; i < size; ++i ) { if( movies[ i ].duration < shortestMovie.duration ) { shortestMovie = movies[ i ]; } } return shortestMovie; } int main() { Movie movies[] = { { 120, "Film 1" }, { 90, "Film 2" }, { 105, "Film 3" }, { 80, "Film 4" }, }; int size = sizeof( movies ) / sizeof( movies[ 0 ] ); Movie shortest = findShortestMovie( movies, size ); printf(" Najkrotszy film: %s, czas trwania: %d minut\n", shortest.title, shortest.duration ); return 0; }
Editor is loading...
Leave a Comment