#include <iostream> #include <map> using namespace std; int main() { cout << "Hello World" << endl; map<int,int> x; //x[1]= 2; map<int,int>::iterator a = x.end(); --a; if(a == x.end()){ cout << "They matched" << endl; } else { cout << "They missed" << endl; } return 0; }
#include <iostream> #include <string> #include <algorithm> using namespace std; int func(std::string str){ cout << "in bef: "<< str << " : " << str.size() << endl; str.clear(); cout << "in aft: "<< str << " : " << str.size() << endl; return 0; } int main() { std::string str("qwertyuiop"); cout << "bef:" << str << " : " << str.size() << " : " << sizeof(str) << endl; func(str); cout << "aft:" << str << " : " << str.size() << endl; return 0; }
#include <iostream> using namespace std; struct Node { int data; struct Node *next; }; struct Node* head = NULL; void insert(int new_data) { struct Node* new_node = (struct Node*) malloc(sizeof(struct Node)); new_node->data = new_data; new_node->next = head; head = new_node; } void display() { struct Node* ptr; ptr = head; while (ptr != NULL) { cout<< ptr->data <<" "; ptr = ptr->next; } } int main() { insert(3); insert(1); insert(7); insert(2); insert(9); cout<<"The linked list is: "; display(); return 0; }
#include <iostream> using namespace std; int main() { cout << "Hello World" << endl; return 0; }
#include<stdio.h> #include<stdlib.h> #include<math.h> #include<GL/glut.h> int count=0; float mat[3][16],trans[3][3],res[3][16]; float x; typedef struct pixel { GLubyte red,green,blue; }pixel; pixel c, boundary,fill; void Init() { glClearColor(1,1,1,0); glClear(GL_COLOR_BUFFER_BIT ); glColor3ub(0,0,0); gluOrtho2D(0 , 1020 , 0 , 660); } void mult() { int i,j,k; for(i=0;i<3;i++) { for(j=0;j<16;j++) { res[i][j]=0; for(k=0;k<3;k++) { res[i][j]+=trans[i][k]*mat[k][j]; } } } } int sign(int a) { if(a>=0) return 1; else return -1; } void breshnam(int xp1,int yp1,int xp2,int yp2) { int x,y,dx,dy,dx2,dy2,sdx,sdy,steps,pk,i; char str[10]; dx=xp2-xp1; dy=yp2-yp1; if(abs(dy)>abs(dx)) { steps=abs(dy); if(yp1<yp2) { x=xp1;y=yp1; } else { x=xp2;y=yp2; dx=xp1-xp2;dy=yp1-yp2; } dx2=2*abs(dx); dy2=2*abs(dy); sdx=sign(dx); sdy=sign(dy); pk=dx2-abs(dy); glBegin(GL_POINTS); glVertex2i(x,y); for(i=0;i<steps;i++) { if(pk<0) { y++; pk=pk+dx2; } else { y++;x=x+sdx; pk=pk+dx2-dy2; } glVertex2i(x,y); } glEnd(); glFlush(); } else { steps=abs(dx); if(xp1<xp2) { x=xp1;y=yp1; } else { x=xp2;y=yp2; dx=xp1-xp2;dy=yp1-yp2; } dx2=2*abs(dx); dy2=2*abs(dy); sdx=sign(dx); sdy=sign(dy); pk=dy2-abs(dx); glBegin(GL_POINTS); glVertex2i(x,y); for(i=0;i<steps;i++) { if(pk<0) { x++; pk=pk+dy2; } else { y=y+sdy;x++; pk=pk+dy2-dx2; } glVertex2i(x,y); } glEnd(); glFlush(); } } void initmat() { int ymax=glutGet(GLUT_WINDOW_HEIGHT),xmax=glutGet(GLUT_WINDOW_WIDTH); int a=xmax/2+100,b=100-200,i; for(i=0;i<5;i++) { mat[0][i]=a; mat[1][i]=b; mat[2][i]=1; a+=30; } a=xmax/2+220;b=130-200; for(i=5;i<9;i++) { mat[0][i]=a; mat[1][i]=b; mat[2][i]=1; b+=30; } a=xmax/2+190;b=220-200; for(i=9;i<13;i++) { mat[0][i]=a; mat[1][i]=b; mat[2][i]=1; a-=30; } a=xmax/2+100;b=190-200; for(i=13;i<16;i++) { mat[0][i]=a; mat[1][i]=b; mat[2][i]=1; b-=30; } trans[0][0]=cos(x); trans[0][1]=-sin(x); trans[1][0]=sin(x); trans[1][1]=cos(x); trans[2][1]=trans[2][0]=trans[0][2]=trans[1][2]=0; trans[2][2]=1; } void drawcb(float mat[3][16]) { int i; breshnam(mat[0][0],mat[1][0],mat[0][4],mat[1][4]); for(i=0;i<5;i++) { breshnam(mat[0][i],mat[1][i],mat[0][12-i],mat[1][12-i]); } for(i=5;i<9;i++) { breshnam(mat[0][i],mat[1][i],mat[0][20-i],mat[1][20-i]); } } void boundary_fill(int x,int y,pixel b,pixel f) { glReadPixels(x,y,1,1,GL_RGB,GL_UNSIGNED_BYTE,&c); if(c.red!=b.red && c.green!=b.green && c.blue!=b.blue && c.red!=f.red && c.green!=f.green && c.blue!=f.blue) { glColor3ub(f.red,f.green,f.blue); glBegin(GL_POINTS); glVertex2i(x,y); glEnd(); boundary_fill(x+1,y,b,f); boundary_fill(x-1,y,b,f); boundary_fill(x,y+1,b,f); boundary_fill(x,y-1,b,f); glFlush(); } } void mouse(int btn,int state,int x,int y) { int ymax=glutGet(GLUT_WINDOW_HEIGHT); if(btn==GLUT_LEFT_BUTTON && state==GLUT_DOWN) { boundary_fill(x,ymax-y,boundary,fill); } } void draw() { initmat(); //drawcb(mat); mult(); drawcb(res); } int main(int argc,char ** argv) { int p; fill.red = 0.647059; fill.green = 0.164076; fill.blue = 0.164076; boundary.red = 10; boundary.green = 10; boundary.blue = 10; printf("ENTER THE ANGLE FOR ROTATION : "); scanf("%d",&p); x=(p*3.14)/180; glutInit(&argc,argv); glutInitDisplayMode(GLUT_SINGLE | GLUT_RGB); glutInitWindowPosition(0,0); glutInitWindowSize(1020,660); glutCreateWindow("chess board"); Init(); glutDisplayFunc(draw); glutMouseFunc(mouse); glutMainLoop(); return 0; } mult(); drawcb(res); }
#include <iostream> using namespace std; int main() { cout << "Hello World" << endl; return 0; } #include <iostream> // best version int main() { std::cout << "Enter an integer: "; int num{ 0 }; std::cin >> num; std::cout << "Double that number is: " << num * 2 << '\n'; // use an expression to multiply num * 2 at the point where we are going to print it return 0; }
#include <iostream> using namespace std; int main() { std::cout << "Enter an integer: " << '\n'; int num{ 0 }; // defines the integer as a variable std::cin >> num; // gets the integer value from user's keyboard int end{ num * 2 }; std::cout << "Double of that is: " << end << '\n'; // multiplies the integer by 2 std::cout << "Adding 2 to the product will give us: " << end + 2; return 0; }
#include <iostream> // best version int main() { std::cout << "Enter an integer: 4 "; int num{ 4 }; std::cin >> num; std::cout << "Double that number is: " << num * 2 << '\n'; std::cout << "Triple that number is: " << num * 3 << '\n'; return 0; }
#include <iostream> int main() { // If you want to triple the number instead, you can change this to 3 int multiplier = 2; std::cout << "Enter an integer:\n"; int ; std::cin >> input; std::cout << "Double of that number (" << input << ") is " << input * multiplier << '\n'; return 0; }
We use cookies to provide and improve our services. By using our site, you consent to our Cookies Policy. Accept Learn more