It serves to send usually text-based information on the monitor (in currently running application, window), for instance:
...
int myVariable;
cout >> "Please enter a number: ";
cin >> myVarible;
//You entered number 5
cout << "You entered the number: " << myVariable;
...
In the application window you will see:
Please enter a number:
5
You entered the number: 5
An object of type iostream, represents the standard output of the program.
#include<iostream.h> main() { int C,D,E; cout<<"Number at location C="; cin>>C; cout<<"Number at location D="; cin>>D; E=C; C=D; D=E; cout<<"New Number At Location C="<<C<<endl; cout<<"New Number At Location D="<<D<<endl; }
#include<iostream> #include<string> #include<algorithm> bool compare_no_case (const char a, const char b) { return tolower(a) < towlower (b); } int main() { std::string s {"This is the string to be sorted!"}; std::cout << "Unsorted:\t"" << s << ""\n"; std::sort (s.begin(), s.end(), compare_no_case); std::cout << "Sorted\t:"" << s << ""\n"; }
#include<iostream.h> #include<conio.h> void main() { clrscr(); int i,k,a[10],c[10],n,l; cout<<"Enter the no. of elements\t"; cin>>n; cout<<"\nEnter the sorted elments for optimal merge pattern"; for(i=0;i<n;i++) { cout<<"\t"; cin>>a[i]; } i=0;k=0; c[k]=a[i]+a[i+1]; i=2; while(i<n) { k++; if((c[k-1]+a[i])<=(a[i]+a[i+1])) { c[k]=c[k-1]+a[i]; } else { c[k]=a[i]+a[i+1]; i=i+2; while(i<n) { k++; if((c[k-1]+a[i])<=(c[k-2]+a[i])) { c[k]=c[k-1]+a[i]; } else { c[k]=c[k-2]+a[i]; }i++; } }i++; } k++; c[k]=c[k-1]+c[k-2]; cout<<"\n\nThe optimal sum are as follows......\n\n"; for(k=0;k<n-1;k++) { cout<<c[k]<<"\t"; } l=0; for(k=0;k<n-1;k++) { l=l+c[k]; } cout<<"\n\n The external path length is ......"<<l; getch(); }
#include <iostream.h> main() { int a; cout<<"enter a number : "; cin>>a; cout<<endl; if (a%2-1) cout<<"it is a prime number"; else cout<<"it is not a prime number" return 0; } ------------------------------------------ output: enter a number : 30 it is a not a prime number
#include<iostream> #include<stdio.h> #include<conio.h> using namespace std; int main() { int a[20][20],b[20][20],c[20][20],i,j,k,m,n,f; cout << "Input row and column of A matrix \n\n"; cin >> n >> m; cout << "\n\nInput A - matrix \n\n"; for(i=0;i<n;++i) for(j=0;j<m;++j) cin >> a[i][j]; cout << "\n\nMatrix A : \n\n"; for(i=0;i<n;++i) { for(j=0;j<m;++j) cout << a[i][j] << " "; cout << "\n\n"; } for(i=0;i<m;++i) for(j=0;j<n;++j) b[i][j]=a[j][i]; cout << "\n\nTranspose of matrix A is : \n\n"; for(i=0;i<m;++i) { for(j=0;j<n;++j) cout << b[i][j] << " "; cout << "\n\n"; } for(i=0;i<m;i++) { for(j=0;j<m;j++){ c[i][j]=0; for(k=0;k<=m;k++) c[i][j]+=a[i][k]*b[k][j]; } } for(i=0;i<m;i++) { for(j=0;j<m;j++) { if((int)c[i][i]==1&&(int)c[i][j]==0) f=1; } } cout<<"\n\n Matrix A * transpose of A \n\n"; for(i=0;i<m;i++) { for(j=0;j<m;j++) cout << c[i][j]; cout << "\n\n"; } if(f==1) cout << "\n\nMatrix A is Orthogonal !!!"; else cout << "\n\nMatrix A is NOT Orthogonal !!!"; getch(); return 0; } -ALOK
#include<iostream.h> #include<conio.h> void main() { int a,b,c; cout<<"enter the value of a"<<endl; cin>>a; cout<<"enter the value of b"<<endl; cin>>b; cout<<"enter the value of c"<<endl; cin>>c; if(a>b) { if(b>c) { cout<<"the middle number is b:"<<endl; } else { if(a>c) { cout<<"the middle is c:"<<endl; } else { cout<<"the middle number is b:"<<endl; } } if(a<b) { if(b<c) { cout<<"the middle number is b:"<<endl; } else { if(a<c) { cout<<"the middle number is c:"<<endl; } else { cout<<"the middle number is a:"<<endl; } } }
COUT is an inbuilt function in c++ language. Cout is used to print something on to the standard output.
It means that you are writing code computer generates different names for x and X, also it will understand commands or will not under stand it at all (c++: cout and Cout are different).
#include<iostream.h> main() { int C,D,E; cout<<"Number at location C="; cin>>C; cout<<"Number at location D="; cin>>D; E=C; C=D; D=E; cout<<"New Number At Location C="<<C<<endl; cout<<"New Number At Location D="<<D<<endl; }
#include<iostream.h> #include<conio.h> void main() { clrscr(); int marks; cout<<"Enter Marks of Student="; cin>>marks; cout<<"Grade\n"; if(marks>0 && marks<50) cout<<"F"; else if(marks>=50 && marks<55) cout<<"C-"; else if(marks>=55 && marks<60) cout<<"C"; else if(marks>=60 && marks<65) cout<<"c+"; else of(marks>=65 && marks<69) cout<<"B-"; else if(marks>=69 && marks<71) cout<<"B"; else if(marks>=71 && marks<75) cout<<"B+"; else if(marks>=75 && marks<79) cout<<"B"; else if(marks>=79 && marks<84) cout<<"A"; else cout<<"A"; getch(); }
#include<iostream.h> void main() { cout<<' '<<' '<<"a"<<'\n'; cout<<' '<<"a"<<"b"<<"a"<<'\n'; cout<<'a'<<'b'<<'c'<<'b'<<'a'<<"\n"; }
I am a student of class 10. I doesn't know C Language but I can tell such a program in C++ Language.... //------------------------------------ #include <iostream.h> #include <conio.h> void main() { int a,b,c,m; clrscr(); cout<<"Enter First Number: "; cin>>a; cout<<"Enter Second Number: "; cin>>b; if (a<b) m=a; if (a>b) m=b; cout<<"Enter Third Number: "; cin>>c; if (c<m) cout<<"The Largest Number is "<<m; else cout<<"The Largest Number is "<<c; getch(); }
most basicaly if I tell, cout is the printing statement in c++. cout<<"Hello world"; The above statement will print the sentence "hello wold". with the expression cout <<variable, the contents of variable is printed to the standard output. int variable=10; cout<<variable; The o/p will be 10..... Hope this will help u.... :)
Heres something i whipped up in a hurry... This uses the Bubble Sort method found (related links) #include <iostream> using namespace std; int main(int argc, const char* argv) { int arraysize = 5; //Unsorted array size int array [] = { 5, 3, 4, 2, 1 }; //The array of numbers itself //Display the unsorted array cout << "Before: {"; for (int c=0; c <= arraysize; c++) { cout << array[c]; if (c != arraysize) { cout << ","; } } cout << "}" << endl; //Acctually sort the array int tmp=0; //Used for swaping values for (int loop=0; loop <= (arraysize - 1); loop++) { for (int c=0; c <= (arraysize - 1); c++) //The sort loop { if (array[c] > array[c + 1]) { //Swaps the two values in the array tmp = array[c]; array[c] = array[c + 1]; array[c + 1] = tmp; //Cleanup tmp = 0; } } } //Display the sorted array cout << "After: {"; for (int c=0; c <= arraysize; c++) { cout << array[c]; if (c != arraysize) { cout << ","; } } cout << "}" << endl; return 0; }
#include<iostream> int main() { using namespace std; char c='A'; do { cout<<c; }while(c++<'Z'); cout<<endl; }
cout<<"______": cin >>__>>__; [example cout<<"enter no."; cin>>a>>b; ]
cout << "sup" << endl; Well, it's not C