0% found this document useful (0 votes)
42 views10 pages

#Include Using Namespace Int Int

The documents discuss various C++ operators and input/output functions. Specifically: 1) It examines logical operators like &&, arithmetic operators like +=, relational operators like >, equality operators like ==, and !=. 2) It demonstrates the use of input functions like getchar(), gets(), scanf(), and cin to take user input. 3) It shows output functions like printf(), puts(), putchar(), and cout for printing output with formatting options. Escape characters and newline formatting are also covered.

Uploaded by

addang13
Copyright
© Attribution Non-Commercial (BY-NC)
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
42 views10 pages

#Include Using Namespace Int Int

The documents discuss various C++ operators and input/output functions. Specifically: 1) It examines logical operators like &&, arithmetic operators like +=, relational operators like >, equality operators like ==, and !=. 2) It demonstrates the use of input functions like getchar(), gets(), scanf(), and cin to take user input. 3) It shows output functions like printf(), puts(), putchar(), and cout for printing output with formatting options. Escape characters and newline formatting are also covered.

Uploaded by

addang13
Copyright
© Attribution Non-Commercial (BY-NC)
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 10

Operator Logika operator && #include <iostream.

h> #include <conio> using namespace std; int main() { int a = 5, b = 10, c = 15; //cout << boolalpha; cout << "a < b && b < c menghasilkan : "<< (a < b && b < c) << endl; cout << "a > b && b < c menghasilkan : "<< (a > b && b < c) << endl; getch(); }

operator += -= &=
#include <iostream> using namespace std; int main() { int a=4; a=4; cout<<"Nilai Variabel a : "<<a<<endl; cout<<" operator += "<<endl; a+=5; cout<<"nilai variabel a : "<<a<<endl; cout<<" operator *= "<<endl; a*=5; cout<<"nilai variabel a : "<<a<<endl; cout<<" operator &= "<<endl; a&=5; cout<<"nilai variabel a : "<<a<<endl; }

operator >

#include <iostream> using namespace std; int main() { int a = 7; cout << (a > 5 ? "benar" : "salah"); cout <<endl; if(a > 5) cout <<"benar"; else cout <<"salah"; }

operator ==

dan !=

#include <iostream> using namespace std; int main() { //operator == cout<<"operator =="<<endl; int a = 2; if(a==2) cout <<"nilai variabel a sama dengan 2"; else cout <<"nilai variabel a tidak sama dengan 2"; cout<<endl<<endl; //operator != cout<<"operator !="<<endl; if(a!=2) cout <<"nilai variabel a tidak sama dengan 2"; else cout <<"nilai variabel a sama dengan 2"; }

operator ==

dan !=

#include <iostream> using namespace std; int main() { //operator == cout<<"operator =="<<endl; int a = 2; if(a==2) cout <<"nilai variabel a sama dengan 2"; else cout <<"nilai variabel a tidak sama dengan 2"; cout<<endl<<endl; //operator != cout<<"operator !="<<endl; if(a!=2) cout <<"nilai variabel a tidak sama dengan 2"; else cout <<"nilai variabel a sama dengan 2"; }

getchar;
#include <cstdio> #include <iostream> using namespace std; int main() { char a_char; a_char=getchar(); cout<<"yang diinput = "<<a_char; }

get
#include <stdio.h> #include <iostream> #include <conio.h> int main() { char kalimat[30]; cout<<"input kalimat = "; gets(kalimat); cout<<"kalimat yang di input ialah = "<<kalimat; getch(); }

get
#include <stdio.h> #include <conio.h> int main () { char str [80]; int i; printf ("Nama : "); scanf ("%s",str); printf ("Umur : "); scanf ("%d",&i); printf ("nama anda %s ,umur %d tahun.\n",str,i); getch(); return 0; }

#include <stdio.h> #include <conio.h> main() { float a,b,hasil; printf ("Masukkan nilai panjang = "); scanf ("%f",&a); printf ("Masukkan nilai lebar ="); scanf ("%f",&b); hasil = a*b; printf ("Luas = %.2f\n",hasil); getch(); }

Cin #include <iostream.h> #include <conio.h> main() { char nama[20]; int umur; cout<<"masukkan nama : "; cin>>nama; cout<<"umur anda : "; cin>>umur; cout<<"\nnama anda : "<<nama<<endl; cout<<"umur anda : "<<umur<<endl; getch(); }

Escape karakter #include <iostream.h> #include <conio.h> main()

{ cout<<"tanpa \\t tanda "<<endl; getch(); cout<<"dengan \\t \t \t tanda"<<endl; cout<<"\a \a \a"<<endl; cout<<"\n \n \n pindah baris"; getch(); }

Printf #include <stdio.h> #include <conio.h> int main() { printf ("Characters: %c %c \n", 'a', 65); printf ("Decimals: %d %ld\n", 1977, 650000L); printf ("diawali dengan blank: %10d \n", 1977); printf ("diawali dengan angka 0 : %010d \n", 1977); printf ("floats: %4.2f %+.2e %E \n", 3.1416, 3.1416, 3.1416); printf ("Width trick: %*d \n", 5, 10); printf ("%s \n", "A string"); getch(); }

Puts & putchar #include <stdio.h> #include <conio.h> int main() { char a='q'; putchar(a);

puts("STMIK Dipanegara Makassar"); char nama[30] = "Jusuf Kalla"; puts(nama); getch(); }

Puts & putchar #include <stdio.h> #include <iostream.h> #include <conio.h> #include <iomanip.h> int main() { float a2=1254334.3333; cout<<setprecision(5)<<a2; getch(); }

You might also like