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VWULQJV (6758785$6 $FHVVDQGRD(VWUXWXUD 0DWUL]HVGH(VWUXWXUDV ,QLFLDOL]DQGRXPD(VWUXWXUD 3217(,526
$5*80(172'(/,1+$'(&20$1'2 $/2&$1'20(0y5,$
81,®(6
23(5$d®(6&20$548,926(0',6&2
$EULUXP$UTXLYR )HFKDUXP$UTXLYR IFORVH 9HULILFDQGRILQDOGHDUTXLYR (2) )XQo}HVSDUD/HU*UDYDUFDUDFWHUDFDUDFWHU
)XQo}HVSDUD/HU*UDYDU6WULQJV )XQo}HVSDUD/HU*UDYDU6WULQJV)RUPDWDGDV
)XQo}HVSDUD/HU*UDYDU(VWUXWXUDV
$FHVVR$OHDWyULR
&RQGLo}HVGH(UUR
$1(;2± )81d®(6*5È),&$6 %,%/,2*5$),$ ),33 )$&8/'$'('(,1)250È7,&$'(35(6,'(17(358'(17(3
3
///,,,1
1
*
8
$
*
(
0
&
1*
*8
8$
$*
*(
(0
0&
&
35()È&,2
(VWDDSRVWLODIRLHODERUDGD FRPRJXLDGHDSUHVHQWDomRGDOLQJXDJHP&PDLVSUHFLVDPHQWHR
7XUER&GD%RUODQGSRULVVRPRVWUD VHGHPRGRVXSHUILFLDOHSRXFRGHWDOKDGR
+LVWyULFR
$/*2/
(XURSD
Ð
%&3/
,QJODWHUUD
Ð
%
86$ .HQ7KRPSVRQ
Ð
&
86$ 'HQQLV5LWFKLH '('3'3,,
Ð
0,*5283$5$
0,&52&20387$'25(6
)LPGpFDGD
Ð
5(*8/$5,=$d­2
$16,
Ð
785%2&
%RUODQG
$OLQJXDJHP&IRLSULPHLUDPHQWHFULDGDSRU'HQQLV05LWFKLHH.HQ7KRPSVRQQRODERUDWyULR
%HOO HP EDVHDGD QD OLQJXDJHP % GH 7KRPSVRQ TXH HUD XPD HYROXomR GD DQWLJD O LQJXDJHP
%&3/
$ /LQJXDJHP & ILFRX FRQWLGD QRV ODERUDWyULRV DWp R ILQDO GD GpFDGD GH PRPHQWR TXH
FRPHoRX D SRSXODU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QYROYLPHQWR GH LPSRUWDQWHV VRIWZDUHV :LQGRZV /LQX[ 9LVXDO %DVLF
&OLSSHU
x7HUVXEVtGLRVEDVHSDUDRDSUHQGL]DGRGDOLQJXDJHP&H-DYD
x /LQJXDJHPSDGURQL]DGD$16,
x (QWHQGHUDIXQGRDSURJUDPDomRHPDPELHQWHV:LQGRZVH8QL[
x 3URJUDPDomRGHVLVWHPDVHPEXWLGRVKDUGZDUH
x /LQJXDJHPSUHIHULGDHPFRQFXUVRVS~EOLFRV
‘‘C é a linguagem de um programador’’
+HUEHUW6FKLOGW
),33 )$&8/'$'('(,1)250È7,&$'(35(6,'(17(358'(17(6
6
///,,,1
1
*
8
$
*
(
0
&
1*
*8
8$
$*
*(
(0
0&
&
(6758785$%È6,&$'(80352*5$0$(0&
8P SURJUDPD & FRQVLVWH HP XPD RX YiULDV IXQo}HV RQGH XPD GDV TXDLV SUH FLVD VHU
GHQRPLQDGD PDLQ 2 SURJUDPD VHPSUH FRPHoD H[HFXWDQGR D IXQomR PDLQ 'HILQLo}HV GH IXQo}HV
DGLFLRQDLVSRGHPSUHFHGHURXVXFHGHUDIXQomR PDLQ
5HJUDV*HUDLV
x
x
x
x
x
x
x
7RGDIXQomRHP&LQFOXVLYHD PDLQGHYHVHULQLFLDGDSRUXPDFKDYHGHDEHUWXUD³^³H
HQFHUUDGDSRUXPDFKDYHGHIHFKDPHQWR³`´
7RGDIXQomRpSURFHGLGDGHSDUrQWHVHV³´
7RGRSURJUDPDGHYHUiFRQWHUDIXQomR PDLQ pXPDSDODYUDUHVHUYDGD
$VLQVWUXo}HVHP&VmRVHPSUHHQFHUUDGDVSRUXPSRQWR HYtUJXOD
$ IRUPDWDomR GRV SUR JUDPDV p DEVROXWDPHQWH OLYUH PDV WHPRV SRU FRQYHQLrQFLD
PDQWHUDOHJLELOLGDGH
2VFRPDQGRVVmRH[HFXWDGRVQDRUGHPHPTXHIRUDPHVFULWRV
2V FRPHQWiULRV GHYHP VHU GHOLPLWDGRV SRU QR LQtFLR H QR ILQDO H SRGHP RFXSDU
GHVGHDOJXPDVFROXQDVHQWUHD VLQVWUXo}HVDDWpYiULDVOLQKDV3RGHVHUXVDQGRWDPEpP
RVFDUDFWHUHV SDUDFRPHQWiULRVGHXPDOLQKD
)RUPD*HUDOGH)81d®(6HP&
2VFRPHQWiULRVSRGHPVHUFRORFDGRVHPTXDOTXHUSDUWH
GRSURJUDPD
GHFODUDomRGHYDULiYHLVJOREDLV
YRLGPDLQYRLGÖ IXQomRSULQFLSDOREULJDWyULD
^ Ö LQLFLDRFRUSRGDIXQomR
GHFODUDo}HVGHYDULiYHLVORFDLV
FRPDQGRV
`Ö ILQDOL]DRFRUSRGDIXQomR
WLSRIXQFDROLVWDGRVDUJXPHQWRVGHHQWUDGDÖ IXQomR
^
GHFODUDo}HVGDVYDULiYHLVORFDLVDIXQomR
FRPDQGRV
`
(;(03/2
/* programa para calcular a area de um círculo */
#include <stdio.h>
LQFOXVmRGR³KHDGHUILOH´VWGLRK
),33 )$&8/'$'('(,1)250È7,&$'(35(6,'(17(358'(17(7
7
///,,,1
1
*
8
$
*
(
0
&
1*
*8
8$
$*
*(
(0
0&
&
float processa(float r);
void main(void)
{
float raio, area;
printf(" Raio = ? ");
scanf("%f", &raio);
area = processa(raio);
printf(" Area = %f", area);
}
float processa (float r)
{
float a;
a=3.1415*r*r;
return(a);
}
GHFODUDomRGHYDULiYHLV
GHILQLFDRGHIXQFDR
GHFODUDFDRGHYDULDYHOORFDO
),33 )$&8/'$'('(,1)250È7,&$'(35(6,'(17(358'(17(8
8
///,,,1
1
*
8
$
*
(
0
&
1*
*8
8$
$*
*(
(0
0&
&
9$5,È9(,6
³eXPHVSDoRGHPHPyULDTXHSRGHFRQWHUDFDGDWHPSRYDORUHVGLIHUHQWHV´
5HJUDV*HUDLV
x
(P&WRGDVDVYDULiYHLVXWLOL]DGDVQRSURJUDPDGHYHPVHUGHFODUDGDVSUHYLDPHQWH
x
1D RFRUUrQFLD GH PDLV G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RUPDGHGHFODUDomRGHYDULiYHLVpDVHJXLQWH
WLSR QRPH
([HPSOR
LQW.
GRXEOH9DORUHV
IORDWTXDGUR
FKDUFDUDFWHU
,QLFLDOL]DQGR9DULiYHLV
3RGHPRV LQLFLDOL]DU XPD YDULiYHO QR PRPHQWR GH VXD GHFODUDomR RX HP TXDOTXHU
PRPHQWRGRSURJUDPD
([HPSOR
int c=8Ö JOREDO
void main(void)
{
float tempo=27.25Ö /RFDO
Ö /RFDO
char tipo='C';
int x;
x=10;
c=c+x;
/HPEUHVHTXHDRGHFODUDUYDULiYHLVHP&OHWUDVPLQ~VFXODVVmRGLIHUHQWHVGHOHWUDVPDL~VFXODVHWRGDVYDUiYHLV
GHYHPVHUGHFODUDGDV }
127(
x
$VYDULiYHLVGHYHUmRVHUGHFODUDGDVDQWHVGHTXDOTXHULQVWUXomR
x
(P&QmRH[LVWHRWLSRERROHDQRQHPRWLSRVWULQJ
x
x
$VYDULiYHLVGRWLSRFDUDFWHUGHYHUmRUHFHEHUYDORUHVHQWUHDVSDVVLPSOHVµ
29DORU]HURUHSUHVHQWDXPYDORUIDOVRHP&RVGHPDLVYDORUHV
¶D¶¶]¶VmRFRQVLGHUDGRVYHUGDGHLURV
),33 )$&8/'$'('(,1)250È7,&$'(35(6,'(17(358'(17(1
10
///,,,1
1
*
8
$
*
(
0
&
1*
*8
8$
$*
*(
(0
0&
&
$ULWPpWLFRV
23(5$'25(6
0DLVLPSRUWDQWHV
6LJQLILFDGR
$WULEXLomR
6RPD
6XEWUDomR
0XOWLSOLFDomR
'LYLVmR
0yGXORUHWRUQDRUHVWRGDGLYLVmR
,QFUHPHQWDGHVHXRSHUDQGR
'HFUHPHQWDGHVHXR SHUDQGR
([HPSOR
D FDUDFWHU µ%¶
D DWRWDO VDODULRFRPLVVmR
WRWDO VXEWRWDOGHVFRQWR
QRWD QRWD
FRPLVVmR OXFUR
UHVWR L
M
([HPSOR
temp=(Fahr-32)*5/9;
i++;
/*equivale i=i+1*/;
2V RSHUDGRUHV H ± SRGHP VHUXWLOL]DGRV DQWHV RX DSyV R RSHUDQGR VH HVWH IRUXWLOL]DGR
DQWHVGRRSHUDQGRHVWHpDWXDOL]DGRDQWHVGDH[HFXomRGDOLQKDGHFRPDQGR&DVRIRUXWL OL]DGRDSyV
RRSHUDQGRRPHVPRpDWXDOL]DGRDQWHVGDUHVROXomRGDOLQKDGHFRPDQGR .
([HPSOR
a
b
c
d
=
=
=
=
10;
a++;
a;
++a;
9DORUHVGDVYDULiYHLVDRWpUPLQRGDH[HFXomR
9DULiYHLV
D
E
F
G
9DORUHV
2SHUDGRUHV$ULWPpWLFRVGH$WULEXLomR
),33 )$&8/'$'('(,1)250È7,&$'(35(6,'(17(358'(17(1
11
///,,,1
1
*
8
$
*
(
0
&
1*
*8
8$
$*
*(
(0
0&
&
2V RSHUDGRUHV DULWPpWLFRV GH DWULEXLomR DOpP GH UHDOL]DU D RSHUDomR HOH DWULEXL R YDORU
UHVXOWDQWHDXPDYDULiYHO2SURJUDPDHP&ILFDPDLVFRPSDFWRHFyGLJRGHPiTXLQDPDLVHILFLHQWH
6LJQLILFDGR
6RPDHDWULEXL
6XEWUDLHDWULEXL
0XOWLSOLFDHDWULEXL
'LYLGHHDWULEXL
'LIHUHQWH
([HPSORV
teste = 10;
teste += 5;
equivale a
=> teste = teste + 5;
teste *=2;
equivale a
=> teste = teste * 2;
$GLYLVmRHPXOWLSOLFDomRWrPSUHFHGrQFLDVREUHDVRPDHDVXEWUDomR
5HODFLRQDLV
!
!
6LJQLILFDGR
0DLRU
0DLRURXLJXDO
0HQRU
0HQRURXLJXDO
,JXDOGDGH
'LIHUHQWH
/yJLFRV
6LJQLILFDGR
/yJLFR(
__ /yJLFR28
/yJLFRGHQHJDomR
),33 )$&8/'$'('(,1)250È7,&$'(35(6,'(17(358'(17(1
12
///,,,1
1
*
8
$
*
(
0
&
1*
*8
8$
$*
*(
(0
0&
&
%LWD%LW
$VYDULiYHLVXWLOL]DGDVQRVH[HP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H3RUFHQWDJHP
),33 )$&8/'$'('(,1)250È7,&$'(35(6,'(17(358'(17(1
14
///,,,1
1
*
8
$
*
(
0
&
1*
*8
8$
$*
*(
(0
0&
&
([HPSOR
void main(void)
{
char cidade_A=‘X’;
char cidade_B=‘Y’;
float distanc=25.5;
printf(“Cidade
= %c \n”,cidade_A);
printf(“Distancia = %f Km\n”,distanc);
printf("A %s %c esta a %f Km \n da %s%c",
`
“cidade”,cidade_A,distanc,”cidade”,cidade_B);
5HVXOWDGRQD7HOD
&LGDGH
;
'LVWDQFLD .P
$FLGDGH;HVWDD.0
GDFLGDGH<
'HILQLQGRRWDPDQKRGHFDPSRVQDLPSUHVVmR
(P&pSRVVtYHODGHILQLomRGHFRPRXPYDORUGHYHVHULPSUHVVRSDUDLVVRGHYH VHFRORFDUR
WDPDQKRGRFDPSRGHLPSUHVVmRORJRDSyVR³ ´
([HPSOR
void main(void)
{
printf(“Nota do 1o Bimestre - %3d\n”, 10);
printf(“Nota do 2o Bimestre - %3d\n”, 4);
}
5HVXOWDGRQDWHOD
Nota do 1o. Bimestre -
10
Nota do 2o. Bimestre -
4
7DPEpP p SRVVtYHO GHILQLU D TXDQWLGDGH GH FDVDV GHFLPDLV D VHU DSUHVHQWDGD &DVR D
TXDQWLGDGH GH FDVDV GHFLPDLV GHILQLGDV IRU PHQRU TXH D T XDQWLGDGH UHDO R YDORU p
DSUHVHQWDGRFRPDUUHGRQGDPHQWR
),33 )$&8/'$'('(,1)250È7,&$'(35(6,'(17(358'(17(1
15
///,,,1
1
*
8
$
*
(
0
&
1*
*8
8$
$*
*(
(0
0&
&
([HPSOR
void main(void)
{
printf(“Nota do 1o Bimestre - %4.2f\n”, 10);
printf(“Nota do 2o Bimestre - %4.2f\n”, 4.78);
printf(“Nota do 2o Bimestre - %4.1f\n”, 4.78);
}
5HVXOWDGRQD7HOD
Nota do 1o. Bimestre -
10.00
Nota do 2o. Bimestre -
4.78
Nota do 2o. Bimestre -
4.8
&RPSOHPHQWDQGRFRP=HURVD(VTXHUGD
3DUD ID]HU R FRPSOHPHQWR GH ]HURV D HVTXHUGD HP YDORUHV LQWHLURV p QHFHVViULR FRORFDU
DSyVR³´RYDORUVHJXLGRGDTXDQWLGDGH
([HPSOR
void main(void)
{
printf(“\nCodigo do Produto - %04d\n”, 13);
printf(“Codigo do Produto - %06d\n”, 13);
printf(“Codigo do Produto - %6.4d\n”, 13);
}
5HVXOWDGRQD7HOD
Codigo do Produto - 0013
Codigo do Produto - 000013
Codigo do Produto -
0013
,PSULPLQGR&DUDFWHUHV
9DULiYHLVGRWLSRFKDUSRGHPVHUDSUHVHQWDGDVHUHSUHVHQWDGDVGHYiULDVIRUPDV$IRUPDGH
DSUHVHQWDomRGHSHQGHGRFyGLJRGHIRUPDWDomRXWLOL]DGR
([HPSOR
),33 )$&8/'$'('(,1)250È7,&$'(35(6,'(17(358'(17(1
16
///,,,1
1
*
8
$
*
(
0
&
1*
*8
8$
$*
*(
(0
0&
&
printf(“Impressão do A - %d %c %x %o \n”, ’A’ ,’A’ ,’A’ ,’A’);
Resultado – Impressão do A – 65 A 41 101
printf(“Varias letras A - %c %c %c %c \n”, ‘A’, 65, 0x41,);
Resultado – Varias letras A – A A A A
SXWFKDU
6LQWD[H
SXWFKDUYDULiYHOFDUDFWHU
'HILQLomR,PSULPHXPDYDULiYHOGRWLSRFDUDFWHUQRGLVSRVLWLYRGHVDtGD ([HPSOR
void main(void)
{
char letra=‘a’;
putchar(letra);
Ö LPSULPHDOHWUD DQDWHOD
}
),33 )$&8/'$'('(,1)250È7,&$'(35(6,'(17(358'(17(1
17
///,,,1
1
*
8
$
*
(
0
&
1*
*8
8$
$*
*(
(0
0&
&
)XQo}HVGH(QWUDGD
VFDQI
6LQWD[H
VFDQIH[SUGHFRQWUROH OLVWDDUJXPHQWRV 'HILQLomR/HLWXUDGHGDGRVIRUPDWDGRVDSD UWLUGRWHFODGR
2QGH H[SU GH FRQWUROH p XPD H[SUHVVmR GH FRQWUROH FRQWHQGR FyGLJRV GH
IRUPDWDomRSUHFHGLGRVSRUXPVLQDO
OLVWDGHDUJXPHQWRVTXHFRQVLVWHQRVHQGHUHoRVGDVYDULiYHLV&RIHUHFHXP
RSHUDGRU SDUD WLSRV EiVLFRV FKDPDGR RSHUDGRU GH HQGH UHoR H UHIHUHQFLDGR
SHORVtPERORTXHUHWRUQDRHQGHUHoRGRRSHUDQGR
&yGLJRVGH)RUPDWDomR
&Ï',*26
F
G
H
I
R
V
X
[
O
6,*1,),&$'2
&DUDFWHUHVLPSOHV
,QWHLUR'HFLPDO
1RWDomR&LHQWtILFD
3RQWR)OXWXDQWH
2FWDO
&DGHLDGH&DUDFWHUHV
'HFLPDOVHPVLQDO
+H[DGHFLPDO
,QWHLURORQJR
([HPSORV
scanf( "%f" , &x ); Ö OrDYDULiYHO[GRWLSRIORDW
void main(void)
{
float anos, dias;
printf(“Digite sua idade em anos: “);
scanf(“%f ”, &anos);
dias = anos*365;
printf(“Sua idade em dias e %.0f”, dias);
}
5HVXOWDGRQD7HOD
),33 )$&8/'$'('(,1)250È7,&$'(35(6,'(17(358'(17(1
18
///,,,1
1
*
8
$
*
(
0
&
1*
*8
8$
$*
*(
(0
0&
&
'LJLWHVXDLGDGHHPDQRV
6XDLGDGHHPGLDVH
JHWFKH
6LQWD[H
LQWJHWFKHYRLG
'HILQLomROrXPFDUDFWHUGRWHFODGRHRLPSULPHQDWHOD1mRUHTXHURSUHVVLRQDPHQWR
GH(17(5!DSyVRFDUDFWHUGLJLWDGR ([HPSOR
letra = getche();
void main(void)
{
char ch;
printf(“Digite algum caracter:”);
ch = getche();
printf(“\n A tecla que voce pressionou e %c.”, ch);
}
5HVXOWDGRQD7HOD
'LJLWHDOJXPFDUDFWHUZ
$WHFODTXHYRFH SUHVVLRQRXHZ
JHWFK
6LQWD[H
LQWJHWFKYRLG
'HILQLomR/rXPFDUDFWHUGRWHFODGRPDVQmRLPSULPHRFDUDFWHUOLGRQDWHOD
([HPSOR
letra = getch();
void main(void)
),33 )$&8/'$'('(,1)250È7,&$'(35(6,'(17(358'(17(1
19
///,,,1
1
*
8
$
*
(
0
&
1*
*8
8$
$*
*(
(0
0&
&
{
char ch;
printf(“Digite algum caracter:”);
ch = getch();
printf(“\n A tecla que voce pressionou e %c,”, ch);
printf(“ a sua sucessora em ASCII e %c.”, ch+1);
}
5HVXOWDGRQD7HOD
'LJLWHDOJXPFDUDFWHU
$WHFODTXHYRFHSUHVVLRQRXH*DVXDVXFHVVRUDHP$6&,,H+
),33 )$&8/'$'('(,1)250È7,&$'(35(6,'(17(358'(17(2
20
///,,,1
1
*
8
$
*
(
0
&
1*
*8
8$
$*
*(
(0
0&
&
&20$1'26'(,7(5$d­2
IRU
6LQWD[H
IRULQLFLDOL]DomRWHVWHLQFUHPHQWR FRPDQGR
'HILQLomR3HUPLWHTXHXPFRQMXQWRGHRSHUDo}HVVHMDH[HFXWDGRDWpTXHRFRUUDXPD
GHWHUPLQDGD FRQGLomR (QJORED H[SUHVV}HV HP XPD ~QLFD H p ~WLO
SULQFLSDOPHQWHTXDQGRTXHUHPRVUHSHWLUDOJRXPQ~PHURIL[RGHYH]HV
2QGHLQLFLDOL]DomR pJHUDOPHQWHXPFRPDQGRGHDWULEXLomRFRPDIXQomRGHFRORFDU
XP YDORU QD YDULiYHO GH FRQWUROH GR ODoR (VVD LQVWUXomR p H[HFXWDGD DSHQDV
XPDYH]DQWHVGRODoRVHUH[HFXWDGR
WHVWH p XPD H[SUHVVmR UHODFLRQDO TXH D LQVWUXomR WHVWD QR SULQFtS LR GH FDGD
XPDGDVLWHUDo}HV3RGH VHXWLOL]DUPDLVGHXPDH[SUHVVmRVHSDUDQGR DVSRU
³´YtUJXOD
LQFUHPHQWRpXPDH[SUHVVmRTXHGHILQHDPDQHLUDFRPRDYDULiYHOGHFRQWUROH
GDLWHUDomRVHUiDOWHUDGDDSyVFDGDXPDGDVDOWHUDo}HVeVHPSUHH[HFXWDGD
DSyVRWpUPLQRGRODoR
([HPSOR
void main(void)
{
for(a=1;a<=3;a++)
printf("Número %d \n",a);
}
5HVXOWDGRQD7HOD
1XPHUR
1XPHUR
1XPHUR
/DoRVIRUVHPDOJXPGRVSDUkPHWURV
2V ODoRV IRUQmR QHFHVVLWDP GH WRGRV RV SDUkPHWURV RV SDUkPHWURV SRG HP VHU
),33 )$&8/'$'('(,1)250È7,&$'(35(6,'(17(358'(17(2
21
///,,,1
1
*
8
$
*
(
0
&
1*
*8
8$
$*
*(
(0
0&
&
RPLWLGRVRXVHMDSRGHKDYHUODoRVFRPRXGRVSDUkPHWURV
([HPSORV
for(x = 0 ; x !=123 ; )
scanf(“%d”, &x);
for( ; x < 10; )
printf(“%d\n”, x
/DoRV,QILQLWRV
&RPDXWLOL]DomRGRIRUpSRVVtYHOVHID]HUORRSVLQILQLWRVSDUDLVVRpQHFH VViULR
VRPHQWHQmRFRORFDUQHQKXPGRVSDUkPHWURV
([HPSOR
for(;;);
/DoRVVHPFRUSR
(VVHWLSRGHODoRpXWLOL]DGRTXDQGRVHTXHUFULDUHVSDoRVGHWHPSRSDUDLVVRp
QHFHVViULRGHL[DUREORFRDVHUUHSHWLGRVHPFRPDQGRDOJXP
for(i = 1; i < 10000; i++);
/DoRVFRPP~OWLSODVH[SUHVV}HVHPFDGDXPGRVSDUkPHWURV
8WLOL]DGRTXDQGRKiDQHFHVVLGDGHGHYiULDVYDULiYHLVQRORRSRXTXDQGRKi PDLV
GHXPDFRQGLomRGHVDtGDGR/RRS
([HPSOR
for(i=0, j=9; i<=9, j>=0 ;i++, j--)
printf (“\n %d %d”,i,j);
),33 )$&8/'$'('(,1)250È7,&$'(35(6,'(17(358'(17(2
22
///,,,1
1
*
8
$
*
(
0
&
1*
*8
8$
$*
*(
(0
0&
&
ZKLOH
6LQWD[H
ZKLOHFRQGLomR FRPDQGR
'HILQLomR 3HUPLWH TXH XP FRQMXQWR GH RSHUDo}HV VHMD H[HFXWDGR HQTXDQWR XPD
FRQGLomR IRU VDWLVIHLWD 7UDEDOKD FRPR XP FRPDQGR IRU FRP DSHQDV D
H[SUHVVmRGRPHLRRWHVWH
2QGH FRQGLomR p JHUDOPHQWH XPD H[S UHVVmR UHODFLRQDO TXH D LQVWUXomR WHVWD QR
SULQFtSLR GH FDGD XPDGDVLWHUDo}HV 3RUWDQWR FRPDQGR SRGHDWpPHVPRQmR
VHUH[HFXWDGR
FRPDQGR SRGH VHU XP VLPSOHV FRPDQGR RX XP EORFR GH FRPDQGRV LQLFLDGR
SRU^ HWHUPLQDGRSRU `
([HPSOR
while(conta<10)
{
total=total+conta;
printf("conta=%d, total=%d",conta,total);
conta++;
}
GRZKLOH
6LQWD[H
GRFRPDQGR ZKLOHFRQGLomR 'HILQLomR 3HUPLWH TXH XP FRQMXQWR GH RSHUDo}HV VHMD H[HFXWDGR HQTXDQWR XPD
FRQGLomRIRUVDWLVIHLWD$SULQFLSDOGLIHUHQoD HQWUHGRZKLOHHZKLOHpTXHRZKLOH
WHVWD D FRQGLomR DQWHV GH H[HFXWDU RV FRPDQGRV H R GR ZKLOH RV FRPDQGRV
VmRH[HFXWDGRVHDSyVDH[HFXomRpTXHDFRQGLomRVHUiYHULILFDGD3RUWDQWR
RV FRPDQGRV TXH HVWmR GHQWUR GR GR ZKLOH VmR H[HFXWDGDV DR PHQRV X PD
YH]
2QGHFRQGLomR pJHUDOPHQWHXPDH[SUHVVmRUHODFLRQDOTXHDLQVWUXomRWHVWDQRILQDO
),33 )$&8/'$'('(,1)250È7,&$'(35(6,'(17(358'(17(2
23
///,,,1
1
*
8
$
*
(
0
&
1*
*8
8$
$*
*(
(0
0&
&
GHFDGDXPDGDVLWHUDo}HV
FRPDQGR SRGH VHU XP VLPSOHV FRPDQGR RX XP EORFR GH FRPDQGRV LQLFLDGR
SRU^ HWHUPLQDGRSRU `
([HPSOR
do {
Y>>1;
X<<1;
} while (Y);
),33 )$&8/'$'('(,1)250È7,&$'(35(6,'(17(358'(17(2
24
///,,,1
1
*
8
$
*
(
0
&
1*
*8
8$
$*
*(
(0
0&
&
&RPDQGRV$X[LOLDUHV
EUHDN
6LQWD[H
EUHDN
'HILQLomR 2 FRPDQGR EUHDN FDXVD D VDtGD LPHGLDWD GH XPD HVWUXWXUD GH UHSHWLomR
(VVH FRPDQGR SRGH VHU XWLOL]DGR GHQWUR GH TXDOTXHU FRPDQGR GH LWHUDomR
FRPRWDPEpPQR VZLWFK
([HPSOR
while(salario>100)
{
scanf(“%d”, &nome);
if (nome==‘a’)
break;
scanf(“%d”,&salario);
}
FRQWLQXH
6LQWD[H
FRQWLQXH
'HILQLomR 2 FRPDQGR FRQWLQXH FDXVD XP GHVYLR LPHGLDWR GR ODoR SDVVDQGR SDUD D
SUy[LPDLWHUDomRVHPH[HFXWDURFyGLJRTXHHVWLYHUDEDL[R ([HPSOR
while(salario>100)
{
scanf(“%d”, &nome);
if (nome==‘a’)
{
salario=1000;
continue;
}
scanf(“%d”,&salario);
}
),33 )$&8/'$'('(,1)250È7,&$'(35(6,'(17(358'(17(2
25
///,,,1
1
*
8
$
*
(
0
&
1*
*8
8$
$*
*(
(0
0&
&
LI
&20$1'26'('(&,6­2
6LQWD[H
LIFRQGLomR FRPDQGR
'HILQLomR3HUPLWHTXHXPFRPDQGRRXFRQMXQWR GHFRPDQGRVVHMDH[HFXWDGRTXDQGR
XPD GHWHUPLQDGD FRQGLomR IRU VDWLVIHLWD 6H R YDORU GD FRQGLomR HQWUH
SDUrQWHVHV IRU YHUGDGHLUR HOH H[HFXWD DV LQVWUXo}HV FDVR VHMD IDOVR DV
LQVWUXo}HVVHUmRLJQRUDGDV
2QGHFRQGLomR pXPDH[SUHVVmROyJLFDRXUHODFLRQD OTXHGHYHVHUVDWLVIHLWDSDUDTXH
DV LQVWUXomR}HV FRQWLGDV HP FRPDQGR VHMDP H[HFXWDGDV e XP WHVWH
XPDGHFLVmR
FRPDQGR p XP FRPDQGR RX FRQMXQWR GH FRPDQGRV TXH VHUmR H[HFXWDGRV
TXDQGRD FRQGLomRIRUVDWLVIHLWD4XDQGRIRUXPFRQMXQWRGHFRPD QGRVGHYHVH
FRORFiORVHQWUHFKDYHV´ ^`´
2EVHUYDo}HV
¾
¾
¾
¾
¾
/HPEUDUTXHHP&QmRKiXPWLSREROHDQR
(P&RYDORU]HURpIDOVRHTXDOTXHURXWURYDORUpIDOVRSRUWDQWRXPD
FRQGLomRSRGHFRQWHUDSHQDVXPYDORULQWHLUR
3DUD YHULILFDU VH XP YDORU p LJXDO DR RXWUR QmR p XWLOL]DGR R VLQDO GH
LJXDOGDGH³ ´HVLPGRLVVLQDLV³ ´
3DUD YHULILFDUVHXPGHWHUPLQDGRYDORUpGLIHUHQWHGRRXWURQmRVHXWLOL]D
³PHQRUHPDLRU´FRPRHP3DVFDOXWLOL]D VHDH[FODPDomRMXQWDPHQWHFRP
RVLQDOGHLJXDOGDGH³ ´
2VRSHUDGRUHVOyJLFRVVmR UHSUHVHQWDQGR³ H´__ UHSUHVHQWDQGR³ RX´H
SDUDDQHJDomRGHXPDFRQGLomR ([HPSOR
void main(void)
),33 )$&8/'$'('(,1)250È7,&$'(35(6,'(17(358'(17(2
26
///,,,1
1
*
8
$
*
(
0
&
1*
*8
8$
$*
*(
(0
0&
&
{
char a, b;
printf(“Digite duas letras:”);
a = getche(); b = getche();
if (a==b)
printf(“\n As duas letras são iguais”);
printf(“\n Fim da Execução”);
}
5HVXOWDGRQD7HOD
'LJLWHGXDVOHWUDVDE
)LPGD([HFXomR
'LJLWHGXDVOHWUDVDD
$VGXDVOHWUDVVmRLJXDLV
)LPGD([HFXomR
LIHOVH
6LQWD[H
LIFRQGLomR HOVH
FRPDQGR7UXH
FRPDQGR)DOVH
'HILQLomR(VWHRXWURIRUP DWRGRFRPDQGRLISHUPLWHTXHXPFRPDQGRRXFRQMXQWRGH
FRPDQGRVVHMDH[HFXWDGRTXDQGRXPDGHWHUPLQDGDFRQGLomRIRUYHUGDGHLUDH
XPRXWURFRQMXQWRGHFRPDQGRVVHMDH[HFXWDGRFDVRHVVDFRQGLomRVHMDIDOVD
2QGHFRQGLomR pXPDH[SUHVVmROyJLFDRXUHODFLRQD O
FRPDQGR7UXHpXPFRPDQGRRXFRQMXQWRGHFRPDQGRVTXHVHUmRH[HFXWDGRV
TXDQGRDFRQGLomRIRUYHUGDGHLUD
FRPDQGR)DOVH p XP FRPDQGR RX FRQMXQWR GH FRPDQGRV TXH VHUmR
H[HFXWDGRVTXDQGRDFRQGLomRIRUIDOVD
([HPSOR
void main(void)
{
char a, b;
),33 )$&8/'$'('(,1)250È7,&$'(35(6,'(17(358'(17(2
27
///,,,1
1
*
8
$
*
(
0
&
1*
*8
8$
$*
*(
(0
0&
&
printf(“Digite duas letras:”);
a = getche(); b = getche();
if (a==b)
printf(“\n As letras são iguais”);
else
printf(“\n As letras são diferentes”);
printf(“\n As duas letras são iguais”);
}
5HVXOWDGRQD7HOD
'LJLWHGXDVOHWUDV DE
$VOHWUDVVmRGLIHUHQWHV
)LPGD([HFXomR
'LJLWHGXDVOHWUDV DD
$VOHWUDVVmRLJXDLV
)LPGD([HFXomR
&RPDQGRVLIV$QLQKDGRV
2SDGUmR$16,&GHILQHTXHDWpLIVDQLQKDGRVGHYHPVHUVXSRUWDGRV
([HPSOR
void main(void)
{
int x, y, z;
scanf(“%d”, &x);
scanf(“%d”, &y);
scanf(“%d”, &z);
if (X<Y)
if (X<Z)
printf(“X
else
printf(“Z
else
if (Y<Z)
printf(“Y
else
printf(“Z
}
é o menor !”);
é o menor !”);
é o menor !”);
é o menor !”);
5HVXOWDGRQD7HOD
;pRPHQRU
),33 )$&8/'$'('(,1)250È7,&$'(35(6,'(17(358'(17(2
28
///,,,1
1
*
8
$
*
(
0
&
1*
*8
8$
$*
*(
(0
0&
&
\pRPHQRU
8WLOL]DomRGH HOVHLI
4XDQGRVHWHPXPDJUDQGHTXDQWLGDGHGHLI HOVHDQLQKDGRVSDUDHYLWDUPXLWRUHFXRQD
PDUJHPHVTXHUGDFRPRDFRQWHFHQRFDVRDEDL[R
if (nota >= 90)
printf(“conceito A”);
else
if (nota >= 70)
printf(“conceito B”);
else
if (nota >= 50)
printf(“conceito C”);
else
if (nota >= 30)
printf(“conceito D”);
else
if (nota > 0)
printf(“conceito E”);
else
printf(“totalmente sem conceito”);
3RGHVHXWLOL]DURIRUPDWRDSUHVHQWDGRDEDL[R
if (nota >= 90)
printf(“conceito A”);
else if (nota >= 70)
printf(“conceito B”);
else if (nota >= 50)
printf(“conceito C”);
else if (nota >= 30)
printf(“conceito D”);
else if (nota > 0)
printf(“conceito E”);
else
printf(“totalmente sem conceito”);
VZLWFK
6LQWD[H
VZLWFKH[SUHVVmR ^
FDVH FRQVWDQWH
FRPDQGRV
EUHDN
FDVH FRQVWDQWH
FRPDQGRV
),33 )$&8/'$'('(,1)250È7,&$'(35(6,'(17(358'(17(2
29
///,,,1
1
*
8
$
*
(
0
&
1*
*8
8$
$*
*(
(0
0&
&
GHIDXOW
`
EUHDN
FRPDQGRVGHIDXOW
'HILQLomR 3HUPLWH TXH XP GHWHUPLQDGR JUXSR GH LQVWUXo}HV VHMD HVFROKLGR HQWUH
GLYHUVRV JUXSRV GLVSRQtY HLV $ VHOHomR p EDVHDGD QR YDORU FRUUHQWH GH XPD
H[SUHVVmRLQFOXtGDQDLQVWUXomR
2QGHH[SUHVVmR pXPDH[SUHVVmRLQWHLUDRXFDUDFWHUJHUDOPHQWHXPDYDULiYHOGHXP
GHVVHVWLSRV
FRQVWDQWH1 VmRRVYDORUHVFRQVWDQWHVDRVTXDLVDH[SUHVVmRVHUiFRPSDUDGD
Vy Ki WHVWH GH LJXDOGDGH 6mR RV SRVVtYHLV YDORUHV TXH D H[SUHVVmR SRGH
DVVXPLU
FRPDQGRV1VmRFRPDQGRVRXFRQMXQWRVGHFRPDQGRVTXHVHUmRH[HFXWDGRV
GHDFRUGRFRPRYDORUGDH[SUHVVmRDSyVRVFRPDQGRVDVHUHPH[HFXWDGDV
HP XPD GHWHUPLQDGD RSomR GHYH VH FRORFDU XP EUHDN SDUD HYLWDU TXH RV
FRPDQGRVDEDL[RGRPHVPRVHMDH[HFXWDGR
FRPDQGRVGHIDXOW VmR RV FRPDQGRV H[HFXWDGRV TXDQGR D H[SUHVVmR
SURFXUDGD QmR IRU HQFRQWUDGD HQWUH DV FRQVWDQWHV GHILQLGDV RX VHMD FDVR
QHQKXPDVGDVFRQVWDQWHVIRULJXDODRSURFX UDGR
2EVHUYDo}HV
¾
¾
¾
$LQVWUXomR GHIDXOW pRSFLRQDOFDVRHODQmRIRUFRORFDGDHQHQKXPDGDV
RSo}HV IRUHP LJXDLV D SURFXUDGD SHOD H[SUHVVmR QmR VHUi H[HFXWDGR
FyGLJRDOJXP
2VZLWFK GLIHUHGRLISRLVHOHVySRGHWHVWDULJXDOGDGH
'XDVFRQVWDQWHV FDVH QmRSRGHPWHUYDORUHVLJXDLV
([HPSOR
void main(void)
{
char opcao;
printf(“Digite V-Vermelho, B-Branco, A-Amarelo”)
opcao = getche();
switch (opcao)
{
case ‘V’:
),33 )$&8/'$'('(,1)250È7,&$'(35(6,'(17(358'(17(3
30
///,,,1
1
*
8
$
*
(
0
&
1*
*8
8$
$*
*(
(0
0&
&
printf(“\nVERMELHO”);
break;
case ‘B’:
printf(“\nBRANCO”);
break;
case ‘A’:
printf(“\nAZUL”);
break;
default :
printf(“\nCOR DESCONHECIDA !”);
}
}
5HVXOWDGRQD7HOD
Digite V-Vermelho, B-Branco, A-Amarelo 9
9(50(/+2
Digite V-Vermelho, B-Branco, A-Amarelo %
%5$1&2
6HRVEUHDNVQmRWLYHVVHPVLGRFRORFDGRVRUHVXOWDGRVHULD
Digite V-Vermelho, B-Branco, A-Amarelo %
%5$1&2
$=8/
&25'(6&21+(&,'$
9iULDVFRQVWDQWHVSDUDXPPHVPRFRQMXQWRGHFRPDQGRV
4XDQGRKiXPFRQMXQWRGHFRPDQGRVTXHSRGHPVHUDFHVVDGRDWUDYpVGHYiULDVFRQVWDQWHV
SRGHVHXWLOL]DUGXDV IRUPDVTXHVmRH[HPSOLILFDGDVQRSURJUDPDDEDL[R
([HPSOR
void main(void)
{
char op;
int v1, v2, res = 0;
printf(“\nDigite o primeiro valor..:”); scanf(“%d”, &v1);
printf(“\nDigite o segundo valor..:”); scanf(“%d”, &v2);
printf(“\nOperação..:”); op = getche();
switch (op)
{
case ‘/’, ‘:’:
res = v1 / v2;
break;
case ‘*’:
case ‘X’:
),33 )$&8/'$'('(,1)250È7,&$'(35(6,'(17(358'(17(3
31
///,,,1
1
*
8
$
*
(
0
&
1*
*8
8$
$*
*(
(0
0&
&
case ‘x’:
res = v1 * v2;
break;
case ‘+’:
res = v1 + v2;
break;
case ‘-’:
res = v1 - v2;
break;
default :
printf(“\nCOR DESCONHECIDA !”);
}
printf(“\nResultado de %d
%c %d e %d”,v1, op, v2, res);
}
),33 )$&8/'$'('(,1)250È7,&$'(35(6,'(17(358'(17(3
32
///,,,1
1
*
8
$
*
(
0
&
1*
*8
8$
$*
*(
(0
0&
&
2SHUDGRU&RQGLFLRQDO7HUQiULR³"³
6LQWD[H
FRQGLomR "H[SUHVVmR7H[SUHVVmR)
'HILQLomR 8PD IRUPD VLPSOHV GH VH H[SUHVVDU D LQVWUXomR LIHOVH (OH p FKDPDGR
WHUQiULR SRLV WUDEDOKD FRP WUrV RSHUDGRUHV e XWLOL]DGR FRPR XPD IRUPD
FRQGLFLRQDOGHDWULEXLomR
2QGHFRQGLomR pXPDH[SUHVVmRUHODFLRQDOTXHVHUiDYDOLDGDSHORRSHUDGRU
H[SUHVVmR7pDH[SUHVVmRDVHUDYDOLDGDTXDQGRDFRQGLomRIRUYHUGDGHLUD
H[SUHVVmR)pDH[SUHVVmRDVHUDYDOLDGDTXDQGRDFRQGLomRIRUIDOVD
([HPSORV
void main(void)
{
int a, b, maior;
scanf(“%d”, &a);
scanf(“%d”, &b);
maior = (a > b) ? a : b;
printf(“Maior = %d”, maior);
}
1mRpUHVWULWRDDWULEXLo}HV
void main(void)
{
int a, b;
scanf(“%d”, &a);
scanf(“%d”, &b);
(a > b) ? printf(“maior e a”) : printf(“maior e a”);
}
),33 )$&8/'$'('(,1)250È7,&$'(35(6,'(17(358'(17(3
33
///,,,1
1
*
8
$
*
(
0
&
1*
*8
8$
$*
*(
(0
0&
&
)81d®(6
8PDIXQomRpXPDXQLGDGHGHFyGLJRGHSURJUDPDDXW{QRPDGHVHQKDGDSDUDFXPSULUXPD
WDUHIDSDUWLFXODU
$IXQomRHP&UHFHEHXPFHUWRQ~PHUR GHSDUkPHWURVHUHWRUQDDSHQDVXPYDORU
'DPHVPDIRUPDTXHGHFODUDPRVYDULiYHLVGHYHPRVGHFODUDUDIXQomR
$GHFODUDomRGHXPDIXQomRpFKDPDGDGH SURWyWLSR HpXPDLQVWUXomRJHUDOPHQWHFRORFDGD
QRLQtFLRGRSURJUDPDTXHHVWDEHOHFHRWLSRGDIXQomRH RVDUJXPHQWRVTXHHODUHFHEH
'HFODUDomRGDV)XQo}HV
WLSRQRPHBIXQomRGHFODUDFDRGRVDUJXPHQWRV Ö GHFODUDomRGR
SURWyWLSRGDIXQomR
GHYHSUHFHGHUVXD
GHILQLomRH FKDPDGD
YRLGPDLQYRLG
^
D QRPHBIXQomROLVWDGRVDUJXPHQWRVDVHUHPHQYLDGRV Ö FKDPD
DIXQomRIDTXDOUHWRUQDXPYDORUHP D
`
WLSR QRPHBIXQomROLVWDGRVSDUkPHWURVUHFHELGRV
^
GHFODUDomRGDVYDULiYHLVORFDLV
FRPDQGRV
UHWXUQYDORU Ö UHWRUQRGHXPYDORU
`
([SUHVV}HVHPQHJULWRFRUUHVSRQGHPDFRPDQGRVRSFLRQDLV
7LSRVGH)XQo}HV
2WLSRGHXPDIXQomRpGHWHUPLQDGRSHORWLSRGHYDORUTXHHOD UHWRUQDSHORFRPDQGR UHWXUQ H
QmRSHORWLSRGHVHXVDUJXPHQWRV
6HXPDIXQomRIRUGRWLSRQmRLQWHLUDHODGHYHVHUGHFODUDGD2YDORUGHIDXOWpLQWFDVRQmRIRU
GHFODUDGD
$OJXQVWLSRV
IORDW UHWRUQDXPYDORUQXPpULFRUHDO
LQW
UHWRUQDYDORULQWHLURQmRpQHFHVViULDDVXDGHFODUDomR
YRLG IXQo}HVTXHQmRUHWRUQDPYDORUHV ([HPSOR
/* calcula a área de uma esfera */
),33 )$&8/'$'('(,1)250È7,&$'(35(6,'(17(358'(17(3
34
///,,,1
1
*
8
$
*
(
0
&
1*
*8
8$
$*
*(
(0
0&
&
#define PI 3.14159;
float area(int r); /* protótipo da função */
void main(void)
{
int raio;
float area_esfera;
printf (“Digite o raio da esfera: ”);
scanf(“%d”, &raio);
area_esfera=area(raio); /* chamada à função */
printf(“A área da esfera é %f”, area_esfera);
}
float area(int r) /* definicao da funcao */
{
return(4*PI*r*r); /* retorna float */
}
),33 )$&8/'$'('(,1)250È7,&$'(35(6,'(17(358'(17(3
35
///,,,1
1
*
8
$
*
(
0
&
1*
*8
8$
$*
*(
(0
0&
&
&/$66(6'($50$=(1$0(172
7RGDVYDULiYHLVHIXQo}HVHP&WHPGRLVDWULEXWRVXPWLSRHXPDFODVVHGHDUPD]HQDPHQWR
2VWLSRVQyVMiFRQKHFHPRV$VFODVVHVGHDUPD]HQDPHQWRVmR
x DXWR
DXWRPiWLFDV
x H[WHUQ
H[WHUQDV
x VWDWLF HVWiWLFDV
x UHJLVWHU HPUHJLVWUDGRUHV
DXWR
$V YDULiYHLV GHFODUDGDV GHQWUR GH XPD IXQomR VmR DXWRPiWLFDV SRU GHIDXOW 9DULiYHLV
DXWRPiWLFDV VmR DV PDLV FRPXQV GHQWUH DV TXDWUR FODVVHV HODV Vm R FULDGDV TXDQGR D IXQomR p
FKDPDGDHGHVWUXtGDVTXDQGRDIXQomRWHUPLQDDVXDH[HFXomR
YRLGPDLQYRLG
^
DXWRLQWL
`
H[WHUQ
7RGDVYDULiYHLVGHFODUDGDVIRUDGHTXDOTXHUIXQomRWHPDFODVVHGHDUPD]HQDPHQWRH[WHUQ
9DULiYHLVFRPHVWHDWU LEXWRVHUmRFRQKHFLGDVSRUWRGDVDVIXQo}HVGHFODUDGDVGHSRLVGHODV
YRLGPDLQYRLG
^
H[WHUQLQW[
`
$ SDODYUD H[WHUQ QmR p XVDGD SDUD FULDU YDULiYHLV GD FODVVH H[WHUQ H VLPSDUD LQIRUPDU DR
FRPSLODGRUTXHXPDYDULiYHOHPTXHVWmRIRLFULDGDHPRXWURSURJUDPDFRPSLODGRVHSDUDGDPHQWHH
VHUiOLQNHGLWDGRMXQWRDHVWHSDUDIRUPDURSURJUDPDILQDO
VWDWLF
9DULiYHLVVWDWLFGHXPODGRVHDVVHPHOKDPjVDXWRPiWLFDVSRLVVmRFRQKHFLGDVVRPHQWHDV
IXQo}HV TXH DV GHFODUDP H GH RXWUR ODGR VH DVVHPHOKDP jV H[WHUQDV SRLV PDQWpP VHXV YDORUHV
PHVPRTXDQGRDIXQomRWHUPLQD
'HFODUDo}HV VWDWLF WrP GRLV XVRV LPSRUWDQWHV H GLVWLQWRV 2 PDLV HOHPHQWDU p SHUPLWLU D
YDULiYHLV ORFDLV UHWHUHP VHXV YDORUHV PHVPR DSyV R WpUPLQR GD H[HFXomR GR EORFR RQGH VmR
GHFODUDGDV
UHJLVWHU
),33 )$&8/'$'('(,1)250È7,&$'(35(6,'(17(358'(17(3
36
///,,,1
1
*
8
$
*
(
0
&
1*
*8
8$
$*
*(
(0
0&
&
$ FODVVH GH DUPD]HQDPHQWR UHJLVWHU LQGLFD TXH D YDULiYHO DVVRFLDGD GHYH VHU
JXDUGDGD ILVLFDPHQWH QXPD PHPyULD GH DFHVVR PXLWR PDLV UiSLGR FKDPDGD UHJLVWUDGRU
8PUHJLVWUDGRUGDPiTXLQDpXPHVSDoRGH ELWVRQGHSRGHPRVDUPD]HQDUXP LQW RXXP
FKDU
%DVLFDPHQWH YDULiYHLV UHJLVWHU VmR XVDGDV SDUD DXPHQWDU D YHORFLGDGH GH
SURFHVVDPHQWR
([HPSOR
#include <time.h>
void main(void)
{
int i,j;
register int m,n;
long t;
t=time(0);
for(j=0;j<5000;j++)
for (i=0;i<5000;i++);
printf(“\n Tempo dos laços não register: %ld“,time(0)-t);
t=time(0);
for(m=0;m<5000;m++)
for (n=0;n<5000;n++);
printf(“\n Tempo dos laços register: %ld“,time(0)-t);
}
),33 )$&8/'$'('(,1)250È7,&$'(35(6,'(17(358'(17(3
37
///,,,1
1
*
8
$
*
(
0
&
1*
*8
8$
$*
*(
(0
0&
&
',5(7,9$6
GHILQH
$GLUHWLYDGHILQH SRGHVHUXVDGDSDUDGHILQLUFRQVWDQWHVVLPEyOLFDVFRPQRPHVDSURSULDGRV
6LQWD[H
GHILQHLGHQWLILFDGRU!WH[WR!
([HPSOR
#define
#define
#define
#define
PI 3.14159
begin }
end {
PRN(n) printf("%.2f\n",n)
void main(void)
begin
float num;
num+=PI;
PRN(num);
end
4XDQGR R FRPSLODGRU HQFRQWUD D GLUHWLYD GHILQH SURFXUD HP FDGD OLQKD DEDL[R GHOD D
RFRUUrQFLDGRLGHQWLILFDGRUHDVXEVWLWXLSHORWH[WR
XQGHI
$GLUHWLYDXQGHI UHPRYHDPDLVUHFHQWHGHILQLomRFULDGDFRP GHILQH
([HPSOR
#undef PI
/* cancela a definição de PI */
LQFOXGH
$ GLUHWLYD LQFOXGH FRPR R QRPH VXJHUH LQFOXL XP SURJUDPD IRQWH RX XP ³KHDGHU ILOH´ QR
IRQWHFRUUHQWHGXUDQWHDFRPSLODomRRXVHMD QDYHUGDGHRFRPSLODGRUVXEVWLWXLDGLUHWLYD LQFOXGH
GRSURJUDPDSHORFRQWH~GRGHDUTXLYRLQGLFDGR
([HPSOR
#include <stdio.h>
#include “funcoes.c”
#include “c:\prog\mouse.c” p
void main(void)
{
int a,b;
}
n
o
),33 )$&8/'$'('(,1)250È7,&$'(35(6,'(17(358'(17(3
38
///,,,1
1
*
8
$
*
(
0
&
1*
*8
8$
$*
*(
(0
0&
&
4XDQGR R DUTXLYR D VHU LQFOXtGR HVWLYHU GHOLPLWDGR SRU ³ !³ R FDPLQKR GH SURFXUD VHUi R
GLUHWyULR &?7&?,1&/8'( RX R GLUHWyULR VHWDGR SDUD FRQWHU RV ³KHDGHU ILOHV´ 4XDQGRGHOL PLWDGR
SRU $63$6 R FDPLQKR GH SURFXUD VHUi R GLUHWyULR FRUUHQWH RX R HVSHFLILFDGR QD GHFODUDomR GD
GLUHWLYDLQFOXGH
*HUDOPHQWHRVDUTXLYRVGHLQFOXVmRRX³KHDGHUILOHV´WHPRQRPHFRPDH[WHQVmR³K´HHVWmR
JUDYDGRVQRGLUHWyULR,1&/8'(
XQGHILILIGHILIQGHIHOVHHQGLI
(VWDV GLUHWLYDV VmR JHUDOPHQWH XVDGDV HP JUDQGHV SURJUDPDV (ODV SHUPLWHP VXVSHQGHU
GHILQLo}HVDQWHULRUHVHSURGX]LUDUTXLYRVTXHSRGHPVHUFRPSLODGRGHPDLVGHXPPRGR
),33 )$&8/'$'('(,1)250È7,&$'(35(6,'(17(358'(17(3
39
///,,,1
1
*
8
$
*
(
0
&
1*
*8
8$
$*
*(
(0
0&
&
9(725(6(0$75,=(6
9(7250$75,=
8P YHWRUPDWUL] p XP WLSR GH GDGR XVDGR SDUD UHSUHVHQWDU XPD FHUWD TXDQWLGDGH GH
YDULiYHLVGHYDORUHVKRPRJrQHRV$OLQJXDJHP&UHVHUYDRHVSDoRGHPHPyULDUHIHUHQWHD WDP
YH]HVRWLSR GDYDULiYHOHHVVH HVSDoRSRGHVHUUHIHUHQFLDGRSRUXPtQGLFH
6LQWD[H
WLSRQRPHYDU>WDP@
2QGH
WLSR pRWLSRGRYHWRUDVHUFRQVWUXtGRSRGHVHUTXDOTXHUXPGRVWLSRVEiVLFRGDOLQJXDJHP&
FRPRIORDWLQWHFKDURXDWpPHVPRXPWLSRGHILQLGRSHORXVXiULR
QRPHYDUpRQRPHGDYDULiYHOTXHVHUiXWLOL]DGDFRPRXPYHWRURXVHMDpRQRPHGRYHWRU
FRQVWUXtGR
WDPpRWDPDQKRGRYHWRUDVHUFULDGRRXVHMDpDTXDQWLGDGHGHYDULiYHLVGRWLSR WLSR TXH
VHUmRFULDGDVFDGDXPDGHODVUHIHUHQFLDGDVSRUXPtQGLFHFRPHoDQGR VHSHOR2
127(
¾
$ OLQJXDJHP & QmR YDOLGD OLPLWHV HP PDWUL]HV FDEH DR SURJUDPDGRU YHULILFDU R FRUUHWR
¾
2SULPHLURtQGLFHGHXPDPDWUL]pRtQGLFH
¾
¾
GLPHQVLRQDPHQWRGDVPHVPDV
9HWRUHV HP & SRVVXL GH XPD RX PDLV GLPHQV}HV FRPR FRQYHQomR FKDPDPRV YHWRUH V
ELGLPHQVLRQDLVGHPDWUL]HV
2QRPHGHXPDPDWUL]GHVDFRPSDQKDGRGHFROFKHWHVUHSUHVHQWDRHQGHUHoRGHPHPyULDRQGHD
PDWUL]IRLDUPD]HQDGD
),33 )$&8/'$'('(,1)250È7,&$'(35(6,'(17(358'(17(4
40
///,,,1
1
*
8
$
*
(
0
&
1*
*8
8$
$*
*(
(0
0&
&
([HPSORV
int meses[12];
5HVXOWDGRQD0HPyULD
OL[R OL[R OL[R OL[R OL[R OL[R OL[R OL[R OL[R OL[R OL[R OL[R
float tabela [2][2];;
5HVXOWDGRQD0HPyULD
OL[R OL[R
OL[R OL[R
5HIHUrQFLDDRV(OHPHQWRV
$OLQJXDJHP&SDUDUHIHUHQFLDUXPDGHWHUPLQDGDSRVLomRQRYHWRUXQLGLPHQVLRQDOXWLOL]D VHR
VHJXLQWHIRUPDWR
QRPHYDU >SRV@
(PXP YHWRUELGLPHQVLRQDOHGHPDLRUHVGLPHQV}HVXWLOL]D VHRVHJXLQWHSDGUmR
QRPHYDU >SRV@>SRV@>SRV@>SRVQ@
([HPSOR
meses[0] = 8;
meses[5] = 6;
5HVXOWDGRQD0HPyULD
OL[R OL[R OL[R OL[R
OL[R OL[R OL[R OL[R OL[R OL[R
([HPSOR
tabela[1][0] = 3.14;
tabela[0][1] = 6.2;
5HVXOWDGRQD0HPyULD
OL[R
OL[R
,QLFLDOL]DomRGHYHWRUHVPDWUL]HV
),33 )$&8/'$'('(,1)250È7,&$'(35(6,'(17(358'(17(4
41
///,,,1
1
*
8
$
*
(
0
&
1*
*8
8$
$*
*(
(0
0&
&
&RQVLGHUDQGR XPD YDULiYHO LQWHLUD QXPHUR SRGH VH LQLFLDOL]DU D YDULiYHO QXPHUR GDV
VHJXLQWHVIRUPDV
LQW
QXPHUR QXPHUR VFDQI ³G´QXPHUR
$ PDWUL] FRPR p XPD YDULiYHO SRGH VH XWLOL]DU WDPEpP HVVHV IRUPDWRV 3DUD IRUQHFHU R
FRQWH~GRGHFDGDXPGRVHOHPHQWRVGDPDWUL]QDVXDGHFODUDomRXWLOL]D VHRVHJXLQWHIRUPDWR
WLSRQRPHYDU>WDP @ ^YDORUYDORUYDORUYDORU7DP`
([HPSORV
int tab[5] = {10, 20, 30, 40, 1};
5HVXOWDGRQD0HPyULD
int mat[][]={{10,10},{20,20}};
5HVXOWDGRQD0HPyULD
3RGHVHID]HUWDPEpPDWULEXLo}HVGDVVHJXLQWHVIRUPDV tab[0] = 0;
tab[1] = 0;
...
tab[4] = 0;
for ( i = 0 ; i < 5;
i++)
scanf (“%d”, &notas[ i ] );
),33 )$&8/'$'('(,1)250È7,&$'(35(6,'(17(358'(17(4
42
///,,,1
1
*
8
$
*
(
0
&
1*
*8
8$
$*
*(
(0
0&
&
([HPSORV
&RQWDURQ~PHURGHYH]HVTXHXPGDGRQ~PHURDSDUHFHQRYHWRU
#define TAM 20
void main()
{
int i, numeros[TAM];
int procurado, qte;
for( i = 0; i < TAM; i++)
scanf("%d", &numeros[i]);
scanf("%d", &procurado);
qte = 0;
for( i = 0; i < TAM; i++)
if(procurado = numeros[i])
qte++;
printf("o número procurado apareceu %d vezes", qte);
}
3URJUDPDSDUDLPSULPLUD PpGLDGDFODVVHHDVQRWDVGRVDOXQRV
#define N_ALUNOS
40
void main()
{
int i;
float notas[N_ALUNOS], media = 0;
for( i = 0; i < N_ALUNOS; i++ )
{
printf (“entre com a nota %d”, i+1);
scanf (“%f”, &notas[ i ]);
media += notas [ i ];
}
printf (“ Média = %f \n”, media / N_ALUNOS);
for ( i = 0; i < N_ALUNOS; i++ )
printf (“\n Nota do aluno %d = %f \n”, i+1, notas[ i ]);
}
(P & p SRVVtYHO LQLFLDOL]DU XP DUUDQMR VHPTXH VH GHILQD DVXD GLPHQVmR LQGLFDQGR VHRV
YDORUHVLQLFLDLVRFR PSLODGRUIL[DUiDGLPHQVmRGRDUUDQMR
([HPSOR
int mat[][]={{10,10},{20,20}};
5HVXOWDGRQD0HPyULD
1mR VH SRGH LQLFLDOL]DU R L pVLPR HOHPHQWR VHP LQLFLDOL]DU WRGRV RV DQWHULRUHV PDVSRGH VH
LQLFLDOL]DUDSHQDVRVSULPHLURVHOHPH QWRVGHXPYHWRU&RPRPRVWUDRH[HPSORDEDL[R
int notas [ 5 ] = { , , 0, , } // ERRO
] = { , , 0, , } // ERRO
int notas [
),33 )$&8/'$'('(,1)250È7,&$'(35(6,'(17(358'(17(4
43
///,,,1
1
*
8
$
*
(
0
&
1*
*8
8$
$*
*(
(0
0&
&
int notas [ 5 ] =
{1, 2 }
int notas [ 5 ] =
{1, 2, 0, 0, 0 }
$GHFODUDomRDFLPDWHPRPHVPRHIHLWRGHVWDSUy[LPD
9HULILFDQGROLPLWHV
$ OLQJXDJHP & QmR UHDOL]D YHULILFDomR GH OLPLWHV HP DUUDQMRV RYHUIORZ QDGD LPSHGH R
DFHVVR DOpP GR ILP GR DUUDQMR HVVH DFHVVR SRGH FDXVDU UHVXOWDGRV LPSUHYLVtYHLV 'HYLGR D HVVH
SUREOHPDVHPSUHIDoDDYHULILFDomRGRVOL PLWHVGRVYHWRUHV
([HPSORV
#define TAM 100
int notas [ TAM ], quantidade;
do {
printf ( “quantas notas devo ler ?”);
scanf(“%d”, &quantidade);
} while ( quantidade > TAM );
),33 )$&8/'$'('(,1)250È7,&$'(35(6,'(17(358'(17(4
44
///,,,1
1
*
8
$
*
(
0
&
1*
*8
8$
$*
*(
(0
0&
&
675,1*6
6WULQJ pXPDGDVPDLV~WHLVHLPSRUWDQWHVIRUPDVGHGDGRVHP& HpXVDGDSDUDDUPD]HQDU
HPDQLSXODUWH[WRVFRPRSDODYUDVQRPHVHVHQWHQoDV
6WULQJ pXPDPDWUL]GRWLSR FKDU WHUPLQDGDSHORFDUDFWHU18//
?
RXVHMD VWULQJ pXPD
VpULH GH FDUDFWHUHV RQGH FDGD XP RFXSD XP E\WH GH PHPyULD DUPD]HQDGRV HP VHTrQFLD H
WHUPLQDGRV SRU XP E\WH GH YDORU ]HUR µ ?¶ &DGD FDUDFWHUp XP HOHPHQWR LQGHSHQGHQWH H SRGHVHU
DFHVVDGRDWUDYpVGHXPtQGLFH
([HPSORV
char nome[5]; ou
char nome[5]="Joao"; RX
char nome[5]="{'J','o','a','o'};
µM¶
µR¶
µD¶
µR¶
µ?¶
VHQGRTXH :
char vetor[]="abc";
vetor[0]='a'
vetor[1]='b'
vetor[2]='c'
vetor[3]='\0'
Ö LQGLFDILQDOGRYHWRU
Ö GXDVGLPHQV}HVPDWUL]
char matriz[10][20]
char nome[3][6] =
{{'V','í','l','m','a'},
{'D','i','r','c','e'},
{'G','i','l','d','o'}};
RX
char nome[3][6]={"Vilma","Dirce","Gildo"};
µ9¶
µ'¶
µ*¶
µt¶
µL¶
µL¶
µO¶
µU¶
µO¶
µP¶
µF¶
µG¶
µD¶
µH¶
µR¶
µ?¶
µ?¶
µ?¶
),33 )$&8/'$'('(,1)250È7,&$'(35(6,'(17(358'(17(4
45
///,,,1
1
*
8
$
*
(
0
&
1*
*8
8$
$*
*(
(0
0&
&
/HQGRVWULQJV
VFDQI
$ IXQomR VFDQI p EDVWDQWH OLPLWDGD SDUD D OHLWXUD GH VWULQJV $ IXQomR FRQVLGHUD R FDUDFWHU
>HVSDoR@FRPRILQDOGHVWULQJSRUH[HPSORDOHLWXUDGRQRPH $QW{QLR&RLPEUDGH-HVXV SHORVFDQI
VFDQIVQRPHUHVXOWDUiHPDSHQDV$QW{QLR
JHWV
)XQomRSUySULDSDUDOHLWXUDGHVWULQJDOHLWXUDpGHOLPLWDGDSHODWHFOD(17(5! ([HPSOR 6LQWD[H
JHWVVWULQJ
([HPSOR
gets(nome);
,PSULPLQGRVWULQJV
SXWV
SXWVQRPH
SXWVQRPH>@
Ö 6pUJLR)HUUHLUD
Ö JLR)HUUHLUD
SULQWI
SULQWIVQRPH Ö 6pUJLR)HUUHLUD
)XQo}HVGHPDQLSXODomRGHVWULQJV
VWUOHQ
5HWRUQDRWDPDQKRGDVWULQJDSDUWLUGHXPHQGHUHoRGDVWULQJDWpR
FDUDFWHUDQWHULRUD
?
6LQWD[H
LQWVWUOHQVWULQJ
([HPSOR
char nome[ ]="José Carlos";
Ö 11
strlen(nome);
Ö 09
strlen(&nome[2]);
),33 )$&8/'$'('(,1)250È7,&$'(35(6,'(17(358'(17(4
46
///,,,1
1
*
8
$
*
(
0
&
1*
*8
8$
$*
*(
(0
0&
&
VWUFDW
&RQFDWHQDGXDVVWUL QJV
6LQWD[H
VWUFDWVWULQJVWULQJ
([HPSOR
char nome[]="Patricia";
char prof[]="estuda";
strcat(nome,prof); Ö QRPH 3DWULFLDHVWXGD
Ö SURIFRQWLQXDVHQGRHVWXGD VWUFPS
&RPSDUDGXDVVWULQJV
6LQWD[H
LQWVWUFPSVWULQJVWULQJ
YDORUGHUHWRUQR
!
([HPSOR
Ö VWULQJVWULQJ
Ö VWULQJ VWULQJ
Ö VWULQJ!VWULQJ
SULQWIGVWUFPS$QD$OLFHÖ UHWRUQDUiDGLIHUHQoDHP$6&,,HQWUH
VWUFS\
HQWUHRVSULPHLURVGRLVFDUDFWHUHVGLIH UHQWHVQRFDVRXPYDORUQHJDWLYR &RSLDVWULQJV
6LQWD[H
YRLGVWUFS\VWULQJBGHVWLQRVWULQJBRULJHP
([HPSOR
VWUFS\QRPH´$1$´
VWUFS\QRPHQRPH
(6758785$6
),33 )$&8/'$'('(,1)250È7,&$'(35(6,'(17(358'(17(4
47
///,,,1
1
*
8
$
*
(
0
&
1*
*8
8$
$*
*(
(0
0&
&
$JUXSDPHQWRGHXPFRQMXQWRGHGDGRVQmRVLPLODUHVVREXP~QLFRQRPHRX VHMDHVWUXWXUDV
VmRWLSRVGHYDULiYHLVTXHDJUXSDPGDGRVJHUDOPHQWHGHVLJXDLV2VLWHQVGHGDGRVGHXPDHVWUXWXUD
VmRFKDPDGRVGHPHPEURV
QRPHGRWLSRUHFpPFULDGR
Ç
VWUXFW QRPH
^
WLSRYDULDYHO
` PHPEURVGDHVWUXWXUD
`
VWUXFW QRPHQRPH[ÎGHFODUDomRGDYDULiYHOQRPH[FRPRGRWLSR³QRPH
3RU PHLR GD SDODYUD FKDYH VWUXFW GHILQLPRV XP QRYR WLSR GH GDGR 'HILQLUXPWLSRGHG DGR
VLJQLILFD LQIRUPDU DR FRPSLODGRU R VHX QRPH WDPDQKR HP E\WHV H R IRUPDWR HP TXH HOH GHYH VHU
DUPD]HQDGRHUHFXSHUDGRQDPHPyULD
$SyV WHU VLGR GHILQLGR R QRYR WLSR H[LVWH H SRGH VHU XWLOL]DGR SDUD FULDU YDULiYHLV GH PRGR
VLPLODUDTXDOTXHUWLSRVLPS OHV
'HILQLU XPD HVWUXWXUD QmR FULD QHQKXPD YDULiYHO VRPHQWH LQIRUPD DR FRPSLODGRU DV
FDUDFWHUtVWLFDVGHXPQRYRWLSRGHGDGR1mRKiQHQKXPDUHVHUYDGHPHPyULD
([HPSOR
struct livro
{
int reg;
char titulo[30];
char autor[30];
}
struct livro livrox;
$FHVVDQGRD(VWUXWXUD
livrox.reg=10;
gets(livrox.titulo);
strcpy(livrox.autor,"Alvares de Azevedo");
0DWUL]HVGH(VWUXWXUDV
2SURFHVVRGHGHFODUDomRGHXPDPDWUL]GHHVWUXWXUDVpSHUIHLWDPHQWHDQiORJRjGHFODUDomR
GHTXDOTXHURXWURWLSRGH PDWUL]
Ö GHFODUDDHVWUXWXUDOLYUR[FRPRVHQGRXPDPDWUL]GH
HOHPHQWRV
struct livro livrox[50];
3DUDDFHVVDUD(VWUXWXUD
),33 )$&8/'$'('(,1)250È7,&$'(35(6,'(17(358'(17(4
48
///,,,1
1
*
8
$
*
(
0
&
1*
*8
8$
$*
*(
(0
0&
&
livrox[2].reg=1;
Ö UHIHUHVHDRPHPEUR UHJ GD HVWUXWXUDGDPDWUL]GHHVWUXWXUDV
OLYUR[
,QLFLDOL]DQGRXPD(VWUXWXUD
struct data
{
char nome[80];
int mes;
int dia;
int ano;
};
struct data aniversario[] = {“Ana”,12,30,73,
“Carlos”,5,13,66,
“Mara”,11,29,70};
),33 )$&8/'$'('(,1)250È7,&$'(35(6,'(17(358'(17(4
49
///,,,1
1
*
8
$
*
(
0
&
1*
*8
8$
$*
*(
(0
0&
&
3217(,526
eXPDGDVPDLVSRGHURVDVHVWUXWXUDVRIHUHFLGDVSHODOLQJXDJHP&
8PSRQWHLURSURSRUFLRQDXPPRGRGHDFHVVRDYDULiYHLVVHPUHIHUHQFLi ODVGLUHWDPHQWH
2 PHFDQLVPR XVDGR SDUD LVWR p R HQGHU HoR GD YDULiYHO VHQGR R SRQWHLUR D UHSUHVHQWDomR
VLPEyOLFDGHXPHQGHUHoR
8WLOL]DomRGRVSRQWHLURV
x 0DQLSXODUHOHPHQWRVGHPDWUL]HV
RULJLQDO
x 5HFHEHUDUJXPHQWRVHPIXQo}HVTXHQHFHVVLWHPPRGLILFDURDUJX PHQWR
x 3DVVDUVWULQJVGHXPDIXQomRSDU DRXWUDXViORVQROXJDUGHPDWUL ]HV
x &ULDUHVWUXWXUDVGHGDGRVFRPSOH[DVFRPROLVWDVHQFDGHDGDVHiUYR RQGHXPLWHPGHYHFRQWHUUHIHUrQFLDVDRXWUR
UHV ELQiULDV
x $ORFDUHGHVDORFDUPHPyULDGRVLVWHPD
$PHPyULDGRFRPSXWDGRUHGLYLGLGDHPE\W HVHHVWHVE\WHVVmRQXPHUDGRVGHDWpROLPLWH
GD PHPyULD GD PiTXLQD (VWHV Q~PHURV VmR FKDPDGRV HQGHUHoRV GH E\WHV 8P HQGHUHoR p D
UHIHUrQFLDTXHRFRPSXWDGRUXVDSDUDORFDOL]DUYDULiYHLV7RGDYDULiYHORFXSDXPDFHUWDORFDOL]DomR
QDPHPyULDHVHXHQ GHUHoRpRGRSULPHLURE\WHRFXSDGRSRUHOD
2 & RIHUHFH GRLV RSHUDGRUHV XQiULRV SDUD WUDEDOKDUHP FRPSRQWHLURV 8P p R RSHUDGRU GH
HQGHUHoRTXHUHWRUQDRHQGHUHoRGHPHPyULDGDYDULiYHO2VHJXQGRpRRSHUDGRULQGLUHWR TXH
pRFRPSOHPHQWRGH HUHWRUQDRFRQWH~GRGDYDULiYHOORFDOL]DGDQRHQGHUHoRSRQWHLURRSHUDQGR
LVWRpGHYROYHRFRQWH~GRGDYDULiYHODSRQWDGDSHORRSHUDQGR
'HFODUDomR
WLSRYDULiYHO
),33 )$&8/'$'('(,1)250È7,&$'(35(6,'(17(358'(17(5
50
///,,,1
1
*
8
$
*
(
0
&
1*
*8
8$
$*
*(
(0
0&
&
([HPSORVGHGHFODUDomR
char *nome, *sexo;
int *idade;
float *medida;
Ö GHFODUDTXHDVYDULiYHLVQRPHVH[RLGDGHHPHGLGDVmRGRWLSRFKDULQWH
IORDWUHVSHFWLYDPHQWHHVmRSRQWHLURV
HQGHUHoR
FKDU[ µ=¶\ µ.¶
FKDUS[S\
S[ [
S\ \
YDULiYHO
S[
FRQWH~GR
SULQWIXS[
Ö HQGGHS[ SULQWIXS[
Ö FRQWGHS[ SULQWIGS[
Ö FRQWRQGHS[DSRQWD µ=¶
SULQWIGS[
Ö FRQWRQGHS[DSRQWD µ.¶
S\
[
\
µ=¶
µ.¶
3URJUDPDH[HPSOR
void reajusta20(float *p, float *r);
void main(void)
{
float preco, val_reaj;
do
{
printf(“Digite o preco atual”);
scanf (“%f”,&preco);
reajusta20(&preco, &val_reaj); /*
envia o endereço dos
parâmetros preco e val_reaj,
que terão seu conteúdo
atualizados pelos ponteiros */
printf(“Preco novo : = %f”,preco);
printf(“\nAumento : = %f”,val_reaj);
}
while (preco != 0.0);
}
void reajusta20(float *p, float *r)
{
*r=*p*0.2;
*p=*p*1.2;
}
),33 )$&8/'$'('(,1)250È7,&$'(35(6,'(17(358'(17(5
51
///,,,1
1
*
8
$
*
(
0
&
1*
*8
8$
$*
*(
(0
0&
&
0DWUL]HVGH3RQWHLURV
2 XVR PDLV FRPXP GH PDWUL]HV GH SRQWHLURV p D FRQVWUXomR GH PDWUL]HV GH SRQWHLURV SDUD
VWULQJV8PDPDWUL]GHSRQWHLURVpGHVFULWDDVHJXLU
char *semana[7]={“Domingo”,“Segunda”,”Terça”,
”Quarta”,“Quinta”,“Sexta”,
“Sábado”};
µ'¶
µ6¶
µ7¶
µ4¶
µ4¶
µ6¶
µ6¶
µR¶
µH¶
µH¶
µX¶
µX¶
µH¶
µi¶
µP¶
µJ¶
µU¶
µD¶
µL¶
µ[¶
µE¶
µL¶
µX¶
µo¶
µU¶
µQ¶
µW¶
µD¶
µQ¶
µQ¶
µD¶
µW¶
µW¶
µD¶
µG¶
µJ¶
µG¶
µ?¶
µD¶
µD¶
µ?¶
µR¶
µR¶
µD¶
µ?¶
µ?¶
µ?¶
µ?¶
µ?¶
3RQWHLURVSDUD(VWUXWXUDV
struct livro *biblio Ö GHFODUDRSRQWHLURELEOLR FRPRGRWLSRVWUXFWOLYUR
biblio=&livro[0];
YUR
Ö DSRQWDRSRQWHLUR ELEOLR SDUDDSULPHLUDSRVLomRGDHVWUXWXUD OL
$FHVVDQGRRVPHPEURVDWUDYpVGRSRQWHLUR
livro->preço ou (*livro).preço
),33 )$&8/'$'('(,1)250È7,&$'(35(6,'(17(358'(17(5
52
///,,,1
1
*
8
$
*
(
0
&
1*
*8
8$
$*
*(
(0
0&
&
$5*80(172'(/,1+$'(&20$1'2
$OJXQV SURJUDPDV DR VHU DWLYDGR SHOR VLVWHPD RSHUDFLRQDO UHTXHU QmR DSHQDV R QRPH
GLJLWDGRPDVWDPEpPRXWURVLWHQVFRPRH[HPSOR
&?!)250$7$
&?!(',77(;727;7
1R H[HPSOR $ H 7(;727;7p XP DUJXPHQWR GH OLQKD GH FRPDQGR 2V LWHQV GLJLWDGRV QD
OLQKDGHFRPDQGRGR'26VmRFKDPDGRV DUJXPHQWRVGHOLQKDGHFRPDQGR
2VDUJXPHQWRVGLJLWDGRVQDOLQKDGHFRPDQGRVmRHQYLDGRVSHOR'26FRPRDUJXPHQWRVGD
IXQomRPDLQ3DUDTXHHVWDIXQomRSRVVDUHFRQKHFH ORVpQHFHVViULRGHFODUDURVDUJXPHQWRV DUJF
H DUJY
DUJFDUJXPHQWRLQWHLURTXHFRUUHVSRQGHDRQ~PHURGHDUJXPHQWRVGDOLQKDGHFRPDQGR
DUJY UHSUHVHQWD XPD PDWUL] GH SRQWHLURV SDUD VWULQJ RQGH FDGD VWULQJ UHSUHVHQWD XP
DUJXPHQWRGDOLQKDGHFRPDQGRV
([HPSOR
/* Programa teste */
void main(int argc,char *argv[])
{
int i;
printf("Nº de argumentos é %d",argc);
for(i=0;i<argc;i++)
printf("Argumento nº %d é %s",i,argv[i]);
}
3DUD([HFXWDU Ø
Ø
Ø
Ø
SURPSWSURJUDPDSULPHLURVHJXQGR
GR'26JHUDGRDUJXPHQWR
DUJXPHQWR
C:\> teste imprimindo argumentos
5HVXOWDGR
Nº de argumentos
Argumento nº 0 é
Argumento nº 1 é
Argumento nº 2 é
é 3
c:\> teste.exe
imprimindo
argumentos
),33 )$&8/'$'('(,1)250È7,&$'(35(6,'(17(358'(17(5
53
///,,,1
1
*
8
$
*
(
0
&
1*
*8
8$
$*
*(
(0
0&
&
$/2&$1'20(0y5,$
$)XQomRPDOORF
8VDGRHPSRQWHLURVDIXQomRPDOORFUHVHUYDHVSDoRGHPHPyULDOLYUH7RPDXPLQWHLURVHP
VLQDO FRPR DUJXPHQWR (VWH Q~PHUR UHSUHVHQWD D TXDQWLGDGH HP E\WHV GH PHPyULD UHTXHULGD $
IXQomRUHWRUQDXPSRQWHLURSDUDRSULPHLURE\WHGRQRYREORFRGHPHPyULDTXHIRLDORFDGR &DVRQmR
KDMD PHPyULD VXILFLHQWH SDUD VDWLVID]HU D H[LJrQFLD PDOORF GHYROYHUi XP SRQWHLUR 18// 1mR VH
HVTXHoDGHLQFOXLUR³KHDGHUILOH´ DOORFK!
([HPSOR
pont=malloc(sizeof(struct livro)) Ö UHVHUYDXPDiUHDFRUUHV SRQ
GHQWHDRWDPDQKRGD HVWUXWXUDOLYUR
pont=malloc(500) Ö UHVHUYDE\WHVGHPHPyULDSDUDRSRQWHLURSRQW
$)XQomRFDOORF
+iXPDJUDQGHVHPHOKDQoDHQWUH PDOORF HFDOORF TXHWDPEpPUHWRUQDXPSRQWHLUR SDUD
YRLG DSRQWDQGR SDUD R SULPHLUR E\WH GR EORFR VROLFLWDGR $ IXQomR DFHLWD GRLV DUJXPHQWRV GR WLSR
XQVLJQHGLQW
([HPSOR
long *mem;
mem = (long *) calloc(100,sizeof(long));
Ð
c
Ð
d
FDVWTXHWUDQVIRUPDSWLSRORQJ
Q~PHURGHFpOXODVGHPHPyULDGHVHMDGD
WDPDQKRGHFDGDFpOXODHPE\WHV
Ð
e
$)XQomRIUHH
eRFRPSOHPHQWRGH PDOORF HFDOORF$FHLWDFRPRDUJXPHQWRXPSRQWHLURSDUDXPDiUHD
GHPHPyULDSUHYLDPHQWHDORFDGDSRU PDOORF RXFDOORF HHQWmROLEHUDHVWD iUHDSDUDXPDSRVVtYHO
XWLOL]DomRIXWXUD
([HPSOR
free(mem); Ö /LEHUDRHVSDoRRXWURUDUHVHUYDGRSDUDRSRQWHLUR³PHP´
),33 )$&8/'$'('(,1)250È7,&$'(35(6,'(17(358'(17(5
54
///,,,1
1
*
8
$
*
(
0
&
1*
*8
8$
$*
*(
(0
0&
&
81,®(6
8QLRQ p VHPHOKDQWH j HVWUXWXUDV PDV H QTXDQWR RV PHPEURV GDV HVWUXWXUDV VmR
DUPD]HQDGRV HP HVSDoRV GLIHUHQ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HUWR HP PRGR WH[WR V mR VHTrQFLDV GH FDUDFWHUHV DJUXSDGDV HP
OLQKDV H HVVDV VmR VHSDUDGDV SRU GRLV FDUDFWHUHV R FDUDFWHU GHFLPDO RX &5 H R FDUDFWHU GHFLPDORX/)
2 FRPSLODGRU & FRQYHUWH R SDU &5/) HP XP ~QLFR FDUDFWHU GH ILQDO GH OLQKD TXDQGR XP
DUTXLYRDEHUWRHPP RGRWH[WRpOLGRHFRQYHUWHRFDUDFWHUGHILQDOGHOLQKDQRSDU&5/)TXDQGRR
DUTXLYRpJUDYDGRHPGLVFR
6HXPDUTXLYRpDEHUWRHPPRGRWH[WRHOHUHFRQKHFHDLQGLFDomRGHILPGHDUTXLYRHQYLDGD
SHOR'26
$EULUXP$UTXLYR
3DUDWUDEDOKDUFRPXPDUTXLY RGHGDGRVRSULPHLURSDVVRpHVWDEHOHFHUXP EXIIHURQGHDV
LQIRUPDo}HV VHUmR DUPD]HQDGDV WHPSRUDULDPHQWH HQWUH D PHPyULD GR FRPSXWDGRU H R DUTXLYR GH
),33 )$&8/'$'('(,1)250È7,&$'(35(6,'(17(358'(17(5
56
///,,,1
1
*
8
$
*
(
0
&
1*
*8
8$
$*
*(
(0
0&
&
GDGRV (VVH EXIIHU SHUPLWH TXH LQIRUPDo}HV VHMDP OLGDV GHRX HVFULWDV HP DUTXLYR GH GDGRV PDLV
UDSLGDPHQWH
FILE *fptr
),/(PDL~VFXORpXPDHVWUXWXUDSUpGHILQLGD),/(QR KHDGHUILOH VWGLRKTXHHVWDEHOHFHR
EXIIHUHISWU pXPDYDULiYHOSRQWHLURTXHLQGLFDRLQtFLRGHEXIIHU
3DUD JHUDU XP FyGLJR GH SURJUDPD TXH DEUH XP DUTXLYR R FRPSLODGRU SUHFLVD FRQKHFHU DVSHFWRV
ž2QRPHGRDUTXLYRTXHVHUiXVDGR
ž2WLSRGHDEHUWXUD
ž2QGHJXDUGDULQIRUPDo}HVVREUHRDUTXLYR
ISWU IRSHQDUTXLYRW[WZ
e
c
d
$EUH XP DUTXLYR FKDPDGR DUTXLYRW[W QR GLVFR FRUUHQWH SDUD HVFULWD Z D TXDO VHUi
DUPD]HQDGDQDYDULiYHO ISWU GHFODUDGDFRPRSRQWHLURSDUDRWLSR),/(
4XDQGRpQHFHVViULRFRORFDURFDPLQKRFRPSOHWRGRDUTXL YRHDFRQVHTHQWHSUHVHQoDGH
EDUUDVLQYHUWLGDV ? FRPRHPF?DOXQR?WHVWHW[WDRLQYpVGHFRORFDUXPDEDUUDGHYH VHFRORFDU??
SRUWDQWRILFDQGRDVVLPF ??DOXQR??WHVWHW[W
$IXQomRIRSHQUHWRUQDRYDORU18//FDVRRDUTXLYRQmRSRGHVHUDEHU WR
([HPSORV
FILE *cliente;
//Definição do buffer cliente
FILE *fornecedor;
//Definição do buffer fornecedor
cliente = fopen("clientes.txt", "w");
fornecedor = fopen("c:\\aluno\\fornec.txt", "r");
),33 )$&8/'$'('(,1)250È7,&$'(35(6,'(17(358'(17(5
57
///,,,1
1
*
8
$
*
(
0
&
1*
*8
8$
$*
*(
(0
0&
&
7LSRVGHDEHUWXUDGHDUTXLYR
&Ï'
'(6&5,d­2
Z
$EULUXPDUTXLYRWH[WRSDUDJUDYDomR6HRDUTXLYRHVWLYHUSUHVHQWHHOHVHUi
GHVWUXtGRHUHLQLFLDOL]DGR6HQmRH[LVWLUHOHVHUiFULDGR
U
D
U
Z
D
UE
ZE
DE
UE
$EULUXPDUTXLYRWH[WRSDUDOHLWXUD2DUTXLYRGHYHHVWDUSUHVHQWHQRGLVFR
$EULU XP DUTXLYR WH[WR SDUD LQFOXVmR DFUpVFLPR GH LQIRUPDo}HV 2V GDGRV
VHUmR DGLFLRQDGRV DR ILP GR DUTXLYR H[LVWHQWH RX XP QRYR DUTXLYR VHUi
FULDGR
$EULUXPDUTXLYRWH[WRSDUDOHLWXUDHJUDYDomR2DUTXLYRGHYHH[LVWLUHSRGH
VHUDWXDOL]DGR
$EULU XP DUTXLYR WH[WR S DUD OH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HV IJHWF HJHWF VmRXWLOL]DGDVSDUDDOHLWXUDGHFDUDFWHUHVGHXPDUTXLYRWH[WRRQGH
RV FDUDFWHUHV VmR OLGRV XP D XP $V GXDV IXQo}HV WUDEDOKDP GD PHVPD IRUPD p QHFHVViULD D
H[LVWrQFLD GDV GXDV SDUD D FRPSDWLELOLGDGH HQWUH VLVWHPDV $ IXQomR JHWF UHWRUQDRFDUDFWHUOLGRGR
DUTXLYR UHIHUHQFLDGR SRU QRPHEXI HVVH FDUDFWHU SRGH VHUDUPD]HQDGR HP XPD YDULiYHO LQWHLUD RX
FDUDFWHUeUHFRPHQGDGRDXWLOL]DomRGRLQWHLURSDUDDFRPSDUDomRFRPDFRQVWDQWHLQWHLUD (2)
2QGH
QRPHEXI p R QRPH GD YDULiYHO TXH HVWi VHQGR XWLOL]DGDFRPR SRQWHLUR SDUD R EXIIHUGR
DUTXLYRDVHUOLGR
YDULQWpDYDULiYHOLQWHLUDRXFDUDFWHUTXHLUiD UPD]HQDURGDGROLGR
*UDYDomR&DUDFWHUD&DUDFWHU SXWF
6LQWD[H
ISXWFFDUDFWHUQRPHEXI
SXWFFDUDFWHUQRPHEXI $V IXQo}HV ISXWF H SXWF VmR XWLOL]DGDV SDUD D JUDYDomR GH FDUDFWHUHVGH XP DUTXLYRWH[WR
RQGHRVFDUDFWHUHVVmRJUDYDGRVXPDX P
2QGH
QRPHEXI p R QRPH GD YDULiYHO TXH HVWi VHQGR XWLOL]DGDFRPR SRQWHLUR SDUD R EXIIHUGR
DUTXLYRDVHUJUDYDGROHPEUDUTXHHVWHDUTXLYRGHYHVHUDEHUWRSDUDJUDYDomRFRPZRXD
QRPHEXI
FDUDFWHU p D YDULiYHO FDUDFWHU TXH VHUi DUPD]HQDGD QR DUTXLYRV HVSHF LILFDGR SRU
),33 )$&8/'$'('(,1)250È7,&$'(35(6,'(17(358'(17(6
60
///,,,1
1
*
8
$
*
(
0
&
1*
*8
8$
$*
*(
(0
0&
&
)XQo}HVSDUD/HU*UDYDU6WULQJV
/HUVWULQJV IJHWV
6LQWD[H
FKDU IJHWVVWULQJOLGDWDPDQKR QRPHEXI
$IXQomRIJHWV OrXPDVWULQJGRDUTXLYRHVSHFLILFDGRSRU QRPHEXI(VVDIXQomROrRVFDUDFWHUHVGH
XP DUTXLYRV DWp TXH XP I LQDO GH OLQKD VHMD HQFRQWUDGR RX DWp TXH D VWULQJ GH UHWRUQR VWULQJOLGD
FRQWHQKDWDPDQKRFDUDFWHUHV2UHWRUQRGDIXQomRSRGHVHUFRPSDUDGRFRP18//SDUDYHULILFDU
VHMipILQDOGHDUTXLYRRXVHRFRUUHXXPHUURGXUDQWHDOHLWXUD
2QGH
QRPHEXI pRQRPHGD YDULiYHOTXHHVWiVHQGRXWLOL]DGDFRPRSRQWHLURSDUDREXIIHUGR
DUTXLYRDVHUOLGR
VWULQJOLGDpDYDULiYHOGRWLSRFDGHLDGHFDUDFWHUHVRXXPSRQWHLURSDUDFDUDFWHUHVRQGH
VHUmRDUPD]HQDGRVRVGDGRVOLGRVGRDUTXLYR
WDPDQKRpDTXDQWLGDGHPi[L PDGHFDUDFWHUHVTXHVHUmROLGRVGHXPDYH]
([HPSOR
FILE *fornecedor;
char lido[80];
fornecedor = fopen("c:\\aluno\\fornec.txt", "r");
if (fgets(lido, 80, fornecedor) == NULL)
printf("Ocorreu um erro na leitura do arquivo ou EOF");
else
printf("%s", lido);
),33 )$&8/'$'('(,1)250È7,&$'(35(6,'(17(358'(17(6
61
///,,,1
1
*
8
$
*
(
0
&
1*
*8
8$
$*
*(
(0
0&
&
*UDYDUVWULQJV ISXWV
6LQWD[H
ISXWVVWULQJJUDYD QRPHEXI
$ IXQomR ISXWV JUDYD D VWULQJ FRQWLGD HP VWULQJJUDYD GR DUTXLYR HVSHFLILFDGR SRU
QRPHEXI2ILQDOGHOLQKDpFRORFDGRRXQmRGHSHQGHQGRGRDPELHQWHXWLOL]DGR
2QGH
QRPHEXI p R QRPH GD YDULiYHO TXH HVWi VHQGR XWLOL]DGDFRPR SRQWHLUR SDUD R EXIIHUGR
DUTXLYRDVHUJUDYDGRQmRHVTXHFHQGRTXHHVWHDUTXLYRGHYHVHUDEHUWRSDUDDJUDYDomR
VWULQJJUDYD p D YDULiYHO GR WLSR FDGHLD GH FDUDFWHUHV RX XP SRQWHLUR SDUD FDUDFWHUHV
RQGHVHUiDUPD]HQDGDQRDUTXLYR
([HPSOR
FILE *fornecedor;
char gravar[80];
fornecedor = fopen("c:\\aluno\\fornec.txt", "w");
gets(gravar);
fputs(gravar, fornecedor);
)XQo}HVSDUD/HU*UDYDU6WULQJV)RUPDWDGDV
/HU6WULQJV)RUPDWDGDV IVFDQI
6LQWD[H
IVFDQIQRPHEXIIRUPDWDomRYDULiYHLV
$IXQomR IVFDQI OrXPDVWULQJIRUPDWDGDGRDUTXLYRHVSHFLILFDGRSRU QRPHEXI(VVDIXQomR
OrRVFDUDFWHUHVGHXPDUTXLYRGHDFRUGRFRPDIRUPDWDomRGHILQLGDSRU IRUPDWDomR HRVFRORFDQDV
YDULiYHLVGHILQLGDVSRUYDULiYHLV
2QGH
QRPHEXI pRQRPHGDYDULiYHOTXHHVWiVHQGRXWLOL]DGDFRPRSRQWHLURSDUDREXIIHUGR
DUTXLYRDVHUOLGR
IRUPDWDomRpXPDVWULQJGHIRUPDWDomRGHILQLQGRFRPRRVGDGRVVHUmROLGRVGRDUTXLYR
$IRUPDWDomRpGHILQLGDQDPHVP DIRUPDGRVFDQI
),33 )$&8/'$'('(,1)250È7,&$'(35(6,'(17(358'(17(6
62
///,,,1
1
*
8
$
*
(
0
&
1*
*8
8$
$*
*(
(0
0&
&
*UDYDU6WULQJV)RUPDWDGDV *UDYDU ISULQWI
6LQWD[H
FKDU IVFDQIQRPHEXIIRUPDWDomRYDULiYHLV
$IXQomR IVFDQI OrXPDVWULQJIRUPDWDGDGRDUTXLYRHVSHFLILFDGRSRU QRPHEXI(VVDIXQomR
OrRVFDUDFWHUHVGHXPDUTXLYRGHDFRUGRFR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GHWHUPLQDDSDUWLUGHRQGHRGHVORFDPHQWRFRPHoDUiDVHUDFHVVDGR
6((.B6(7 FRPHoRGRDUTXLYR
6((.B&85 SRVLomRFRUUHQWHGRDUTXLYR
6((.B(1' ILPGRDUTXLYR
IWHOO
),33 )$&8/'$'('(,1)250È7,&$'(35(6,'(17(358'(17(6
64
///,,,1
1
*
8
$
*
(
0
&
1*
*8
8$
$*
*(
(0
0&
&
6LQWD[H
ORQJIWHOOSRQWWLSR),/(
5HWRUQD D SRVLomR GR SRQWHLUR GH XP DUTXLYR ELQiULR HP UHODomR DR VHX FRPHoR (VWD
IXQomRDFHLWDXP~QLFR DUJXPHQWRTXHpRSRQWHLURSDUDDHVWUXWXUD),/(GRVHXDUTXLYRHUHWRUQD
XPYDORUGRWLSRORQJTXHUHSUHVHQWDRQ~PHURGHE\WHVGRFRPHoRGRDUTXLYRDWpDSRVLomRDWXDO
UHZLQGILOH
$YDQoDRSRQWHLURSDUDRLQtFLRGRDUTXLYR
&RQGLo}HVGH(UUR
IHUURU
'HWHUPLQD VH RFRUUHX DOJXP HUUR QD OHLWXUDJUDYDomR UHWRUQD QmR ]HUR VH RFRUUHX DOJXP
HUURHVHQHQKXPHUURRFRUUHX
6LQWD[H
LQW IHUURUSRQWHLURGRWLSR),/(
SHUURU
,PSULPHDPHQVDJHPGRHUURIRUQHFLGDSHORVLVWHPD
6LQWD[H
SHUURU6WULQJ
([HPSOR
7HQWDWLYDGHDEULUSDUDHVFULWDXPDUTXLYRSURWHJLGR
FILE *fp;
fp=fopen(“io.sys”,”r”);
if (ferror(fp))
{
printf(“Arquivo não pode ser aberto”);
perror(“Causa do Erro : “);
}
5HVXOWDHP
Arquivo nao pode ser aberto
Causa do Erro : Permission Denied
),33 )$&8/'$'('(,1)250È7,&$'(35(6,'(17(358'(17(6
65
///,,,1
1
*
8
$
*
(
0
&
1*
*8
8$
$*
*(
(0
0&
&
$1(;2± )81d®(6*5È),&$6
✎
)81d¯(6*5É),&$6 785%2&
&21752/('$3/$&$*5È),&$
LQLFLDOL]DRPRGRJUiILFR
LQLWJUDSK
void far initgraph(int *graphdriver, int *graphmode, char *pathtodriver)
*UDSKLFVGULYHUV
&*$
(*$
+(5&0212
3&
*UDSKLFVPRGHV
0RGR
&*$&2
&*$&
&*$&
&*$&
&*$+,
0&*$&2
0&*$&/
0&*$&
0&*$&
0&*$0('
0&*$+,
0&*$
(*$0212
$77
'(7(&7$XWRGHWHFomR
5HVROXomR
[SDOHWWH
[SDOHWWH
[SDOHWWH
[SDOHWWH
[
[SDOHWWH
[SDOHWWH
[SDOHWWH
[SDOHWWH
[
[
0RGR
(*$/2
(*$+,
(*$/2
(*$+,
(*$0212+,
+(5&0212+,
9*$/2
9*$0('
9*$+,
(*$
,%0
9*$
5HVROXomR
[FRUHV
[FRUHV
[FRUHV
[ FRUHV
[
[
[
[
[FRUHV
'(7(&7'HWHFWDRWLSRGHSODFDJUiILFDGR+DUGZDUH
([
int a=DETECT
int b;
initgraph(&a,&b);
GHWHFWJUDSKGHWHUPLQDDSODFDJUiILFDJUDSKLFGULYHUHRPRGRGHXVRJUDSKLFPRGHFKHFDQGRRKDUGZDUH
void far detectgraph(int far *graphddver, int far *graphmode);
FOHDUGHYLFHOLPSDDWHODJUiILFD
void far cleardevice(void);
FORVHJUDSKGHVDWLYDRPRGRJUiILFR
void far closegraph(void);
VHWYLHZSRUWGHWHUPLQDXPYLHZSRUWSDUDDVVDtGDVJUiILFDV
void far setviewport(int esq, int acima,
int direita, int abaixo, int dip);
Þ QmRUHFRUWD
UHFRUWD
FOHDUYLHZSRUWDSDJDRYLHZSRUWFRUUHQWH
void far clearviewport(void);
),33 )$&8/'$'('(,1)250È7,&$'(35(6,'(17(358'(17(6
66
///,,,1
1
*
8
$
*
(
0
&
1*
*8
8$
$*
*(
(0
0&
&
JHWPD[[UHWRUQDDPi[LPDFRQGHQDGDQRHL[R[
JHWPD[\UHWRUQDDPi[LPDFRRUGHQDGDQRHL[R\
int far getmaxx(void);
int far getmaxy(void);
JHW[UHWRUQDDFRRUGHQDGD[FRUUHQWH
JHW\UHWRUQDDFRRUGHQDGD\FRUUHQWH
int far getx(void);
int far gety(void);
VHWFRORUVHWDRFRUGHGHVHQKR
void far setcolor (int cor);
VHWENFRORUVHWDDFRUGHIXQGR
void far setbkcolor(int cor);
VHWILOOVW\OHVHWDFRUHWH[WXUDSDUDSUHHQFKLPHQWRGHILJXUDV
void far setfillstyle(int padrão, int cor);
3DGU}HV
(037<B),//
62/,'B),//
6/$6+B),//
%.6/$6+B),//
;+$7&+B),//,17(5/($9(B),//
&RUHV
&RQVWDQWH
%/$&.
%/8(
*5((1
&<$1
5('
0$*(17$
%52:1
/,*+7*5$<
'$5.*5$<
,G
&RU
3UHWR
$]XO
9HUGH
5R[R
9HUPHOKR
0DJHQWD
0DUURP
&LQ]D&ODUR
&LQ]D(VFXUR
/,1(B),//
/7%.6/$6+B),//
:,'(B'27B),//
&RQVWDQWH
/,*+7%/8(
/,*+7*5((1
/,*+7&<$1
/,*+75('
/,*+70$*(17$
<(//2:
:+,7(
%/,1.
,G
/76/$6+B),//
+$7&+B),//
&/26(B'27B),//
&RU
$]XO&ODUR
9HUGH&ODUR
5R[R&ODUR
9HUPHOKR&ODUR
0DJHQWD&ODUR
$PDUHOR
%UDQFR
),*85$6 *(20e75,&$6
SXWSL[HOGHVHQKDXPSRQWRQDWHOD
void far putpixel (int x1, int y1, int cor);
PRYHWRPRYHRFXUVRUJUiILFR
void far moveto(int x, int y);
OLQHGHVHQKDXPDOLQKDHQWUHGRLVSRQWRVHVSHFLILFDGRV
void far line(int xl , int yl , int x2, int y2);
OLQHWR GHVHQKDXPDOLQKDGDSRVLomRFRUUHQWHGRFXUVRU DWpDSRVLomR[\
void far lineto(int x, int y);
DUFGHVHQKDXPDUFR
void far arc(int x, int y, int inic_angulo, int fim_angulo, int raio);
FLUFOHGHVHQKDXPFtUFXOR
void lar circle(int x, int y, int raio);
HOOLSVHGHVHQKDXPDHOLSVH
void far ellipse(int x, int y, int inic_angulo, int fim angulo,
),33 )$&8/'$'('(,1)250È7,&$'(35(6,'(17(358'(17(6
67
///,,,1
1
*
8
$
*
(
0
&
1*
*8
8$
$*
*(
(0
0&
&
int xraio, int yraio);
ItOOHOOLSVHGHVHQKDHSUHHQFKHXPDUFR
void far fillellipse(int x, int y, int xradius, int yradius);
SLHVOLFHGHVHQKDHSUHHQFKHXP³SHGDoRGHSL]]D
void far pieslice(int x, int y, int inic_angulo, int fim_angulo, int raio);
EDUGHVHQKDXPDEDUUD³UHWkQJXORSUHHQFKLGR´
void far bar(int esq, int topo, int direita, int base);
EDUGGHVHQKDXPDEDUUDHP'
void far bar3d(int esq, int topo, int direita,
int base int profundidade, int topflag);
UHFWDQJOHGHVHQKDXPUHWkQJXOR
void far rectangle(int esq, int topo, int direita, int base);
GUDZSRO\ GHVHQKDXPSROtJRQRDSDUWLUGHXPYHWRUGHSRQWRV1XPBSRQWRVGHYHUHSUHVHQWDUDTXDQWLGDGHGH
SRQWRVGRSROtJRQR
void far drawpoly(int num_pontos, int *pontos);
ILOOSRO\GHVHQKDHSUHHQFKHXPSROtJRQRDSDUWLUGHXPYHWRUGHSRQWRV3UHHQFKHRSROtJRQRXVDQGRDFRUH
WH[WXUDFRUUHQWH
void far fillpoly(int numpoints, int far *polypoints);
IORRGILOOH[SDQGHXPSRQWRDWpHQFRQWUDUXPDFRUGHERUGDHVSHFLILFDGD8VDDVFRUHVGHSUHHQFKLPHQWR
FRUUHQWH5HWRUQDRYDORUFDVRQmRSRVVDVHUDWLYDGR
void far floodfill(int x, int y, int border);
7(;726*5È),&26
VHWWH[WVW\OHVHWDDVFDUDFWHUtVWLFDVGRWH[WR
void far settextstyle(int fonte,int direçao,int tamanho);
IRQWHV
'()$8/7)217
75,3/(;)217
6$16B6(5,)B)217
*27+,&B)217
6,03/(;B)217
75,3/(;B6&5B)217
(8523($1B)217
%2/'B)217
GLUHomR
+25,=B',5HVTXHUGDSGLUHLWD
9(57B',5
WDPDQKR
O [ O[O[
60$//)217
6&5,37B)217
&203/(;B)217
EDVHSDUDRWRSR
RXWWH[WLPSULPHXPDVWULQJQRYLHZSRUWWHODJUiILFD
void far outtext(char *textstring);
RXWWH[W[\LPSULPHXPDVWULQJDSDUWLUGHFRRUGHQDGDHVSHFLILFDGD
void far outtextxy(int x, int y, char *textstring);
WH[WKHLJKWUHWRUQDDDOWXUDGDVWULQJHPSL[HOV
int far textheight(char *textstring)e,
WH[WZLGWKUHWRLQDRWDPDQKRGHXPDVWULQJHPSL[HOV
int far textwidth(char far *textstring);
),33 )$&8/'$'('(,1)250È7,&$'(35(6,'(17(358'(17(6
68
///,,,1
1
*
8
$
*
(
0
&
1*
*8
8$
$*
*(
(0
0&
&
VHWWH[WMXVWLI\DOLQKDXPWH[WRJUiILFRDSDUWLUGHXPSRQWRFRQILJXUDGRSRUHVWDIXQomR2GHIDXOWpXPSRQWR
VXSHULRUHVTXHUGR
7(;72
YRLGIDUVHWWH[WMXVWLI\LQWKRUL]LQWYHUW
/()7B7(;7%27720B7(;7
&(17(5B7(;7&(17(5B7(;7
5,*+7B7(;7723B7(;7
287526
JHWLPDJH 6DOYDXPDUHJLmRGDWHODHPXPYHWRUGHFDUDFWHUHV
void far getimage(int esq, int topo, int direita, int base, char *imagem);
SXWLPDJH 5HVWDXUDXPDWHODFDSWXUDGDSHODIXQomRJHWLPDJH
void far putimage(int esq, int topo, char far *imagem, int op);
Ø
&23<B387
1RUPDO
;25B387
2UH[FOXVLYR
25B387
2U
$1'B387
$QG
127B387
,QYHUVR
LPDJHVL]HUHWRUQDRWDPDQKRHPE\WHVQHFHVViULRSDUDDUPD]HQDUXPDUHJLmRGDWHODHVSHFLILFDGD2WDPDQKR
GDUHJLmRGHYHVHUPHQRUTXH.VHQmRRUHWRUQRVHUi
unsigned far imagesize(int esq, int topo, int direita, int base);
([HPSOR
#include <graphics.h>
void main(void)
{
int a,b,i;
char *palavra="Teste";
a=DETECT,
initgraph(&a,&b,");
setcolor(l4);
setbkcolor(2)
rectangle(O,O,639,479);
setcolor(4);
for (i=5O;i<3OO;i=i+50)
{
bar3d(i+9O,i,i+60,200,30,5);
}
bar3d(50,50,50,400,1,1 OO);
getch();
setcolor(BLUE);
settextstyle(GOTHIC_FONT,HORIZ_DIR,5);
outtextxy(300,32O,palavra);
pieslice(l00,350,1,100,45);
line(10,10,400,400);
getch();
closegraph();
}
),33 )$&8/'$'('(,1)250È7,&$'(35(6,'(17(358'(17(6
69
///,,,1
1
*
8
$
*
(
0
&
1*
*8
8$
$*
*(
(0
0&
&
%,%/,2*5$),$
*RWWIULHG%\URQ6WXDUW3URJUDPDQGR HP &7UDG$QD%HDWUL]&RUUHDGD
&RVWD3DUUD6mR3DXOR0DNURQ%RRNV
0D\HU5&/LQJXDJHP&$16,*XLDGR8VXiULR6mR3DXOR0F*UDZ+LOO
0L]UDKL9LFWRULQH9LYLDQH7UHLQDPHQWR HP /LQJXDJHP &YRO,H,,6mR
3DXOR0F*UDZ+LOO
0L]UDKL9LFWRULQH9LYLDQH7UHLQDPHQWR HP /LQJXDJHP &YRO,H,,6mR
3DXOR0F*UDZ+LOO
6FKLOGW+HUEHUW*XLD GR 8VXiULR7UDG0DULD&OiXGLDGH2OLYHLUD6DQWRV
6mR3DXOR0F*UDZ+LOO
6FKLOGW+HUEHUW*XLD 3UiWLFR H ,QWHUDWLYRWUDG/DUV*XVWDY(ULN8QRQLXV6mR
3DXOR0F*UDZ+LOO
6ZDQ7RP$SUHQGHQGR& 7UDG&DUORV0RQWH]H+HOFLR7RQQHUD-U5LR
GH-DQHLUR&DPSXV
7XUER& 8VHU *XLGH
7XUER& 8VHU 5HIHUHQFH
:HLVNDPS.HLWK3URJUDPDomR2ULHQWDGDSDUDREMHWRFRP7XUER&6mR
3DXOR0DNURQ%RRNV
:LHQHU5LFKDUG7XUER&3DVVRD3DVVR5LRGH-DQHLUR(GLWRUD&DPSXV
),33 )$&8/'$'('(,1)250È7,&$'(35(6,'(17(358'(17(7
70
Download

LINGUAGEM