1 / 7

Funções em C

Funções em C. Funções em C. #include &lt;stdio.h&gt; #include &lt;stdlib.h&gt; int main(void) { linha(); printf(&quot;xDB Um programa em C xDB<br>&quot;); linha(); system(&quot;pause&quot;); } linha(void) { int j; for (j=1; j&lt;=20; j++) printf(&quot;xDB&quot;); printf(&quot;<br>&quot;); }. Funções em C.

cricket
Download Presentation

Funções em C

An Image/Link below is provided (as is) to download presentation Download Policy: Content on the Website is provided to you AS IS for your information and personal use and may not be sold / licensed / shared on other websites without getting consent from its author. Content is provided to you AS IS for your information and personal use only. Download presentation by click this link. While downloading, if for some reason you are not able to download a presentation, the publisher may have deleted the file from their server. During download, if you can't get a presentation, the file might be deleted by the publisher.

E N D

Presentation Transcript


  1. Funções em C

  2. Funções em C #include <stdio.h> #include <stdlib.h> int main(void) { linha(); printf("\xDB Um programa em C \xDB\n"); linha(); system("pause"); } linha(void) { int j; for (j=1; j<=20; j++) printf("\xDB"); printf("\n"); }

  3. Funções em C • Tem estrutura semelhante a função main(); • São chamadas (usadas) da mesma forma que usamos funções de C (printf(), scaf(), gets(), getche(), etc) • Retorna valor através do comando return(); • Termina função com comando return;

  4. #include <stdio.h> #include <stdlib.h> float average(float a, float b); void linha(void); int main(void) { linha(); printf("\xDB Um programa em C \xDB\n"); linha(); /*****Cáculo da média entre dois números**************/ printf("\n%f",average(10.0,5.0)); system("pause"); } void linha(void) { int j; for (j=1; j<=20; j++) printf("\xDB"); printf("\n"); } float average(float a, float b) { float ave; ave = (a + b) / 2; return ave; }

  5. float average(int size, float list[]){  int k;  float sum = 0.0;  for (k=0; k<size; k++)    sum += list[k];  return sum / size;} void print_table(int x_size, int y_size, float table[][5]);{  int i, j;  for (i = 0; i < xsize; i++) {    for (j = 0; j < y_size; j++)      printf("\t%f", (double) table[i][j]);    printf("\n");  }} Funções e Vetores

  6. float abs (int x) { ... } void abs (int x) { ... } Cabeçalho de Função abs(x) int x; { ... } abs(int x) { ... }

  7. Escopo de variáveis • Variáveis globais: • Podem ser vista em todo o programa e são declaradas fora das funções • Só são vistas dentro das funções em que foram declaradas

More Related