โค้ดภาษา C++ อย่างง่าย

8 ม.ค. 58 14:38 น. / ดู 3,862 ครั้ง / 1 ความเห็น / 5 ชอบจัง / แชร์

---วันนี้จะมาแจกโค้ดภาษา C++ เป็นโค้ดคำสั่งง่าย ๆ ที่เคยเรียนมาแล้ว (บางตัวลองผิดลองถูก) 
-.•*´¨`*•.¸¸.•*´¨`*•.¸¸.•*´¨`*•.¸¸.•*´¨`*•.¸¸.•.•*´¨`*•.¸¸.•*´¨`*•.¸¸.•*´¨`*•.¸¸.•*´¨`*•.¸¸.•*´¨`*•.¸¸.•.•*´¨

EX CODE ( 1 )
#include<stdio.h>
#include<conio.h>
void main()
{
------char ab;
------char name[15];
------int age;
------float weight;
------printf("Enter Charcter;");
------scanf("%c",&ab);
------printf("Enter Name:");
------scanf("%s"&name);
------printf("Enter Age:");
------Scanf("%d",&age);
------printf("Enter Weight;");
------Scanf("%f",&weight);
------printf(Charcter is %c\nName is %s\nAge is &d\nweight is %f,ab,name,age,weight);
------getch();
}


EX CODE ( 2 )
/*Program Convert inches to centimetre*/
#include<stdio.h>
#include<conio.h>
void main()
{
------float inch,cent; /*Declared Variable*/
------inch = 5.5; /*Assign Value*/
------cent = inch*2.54;      /*Convert Value*/
------printf("Centimetre = %2f\n",cent); /*Output Statement*/
------getch();
}


EX CODE ( 3 )
#include<stdio.h>
#include<conio.h>
void main()
{
------clrscr();
------char a[15],b[15],c[15];
------printf("Enter My Name :");
------scanf("%s",&a);
------printf("Enter Surname :");
------scanf("%s",&surname);
------printf("Enter My ID : ");
------scanf("%s",&id);
------clrscr();
}


EX CODE ( 4 )
#include<stdio.h>
#include<conio.h>
void main()
{
------int a,b = 0;
------a=1/b;
------printf("%d\n",a);
------getch();
}


EX CODE ( 5 )
#include<stdio.h>
#include<conio.h>
void main()
{
------int kilo;
------int total,bag;
------kilo=10;
------bag=20;
------total=bag*kilo;
------printf("Total weight of coins=%d\n",total);
------getch();
}

EX CODE ( 6 )
#include<stdio.h>
#include<conio.h>
void main()
{
------clrscr();
------printf("10+3=%d\n",10+3);
------printf("10-3=%d\n",10-3);
------printf("10*3=%d\n",10*3);
------printf("10/3=%d\n",10/3);
------printf("10 mod 3 =%d\n",10%3);
------getch();
}


EX CODE ( 7 )
#include<stdio.h>
#include<conio.h>
void main()
{
------clrscr();
------int a=1,b=5;
------printf("a=1\n");
------printf("b=5\n");
------printf("a+1 by a++ = %d\n",a++);
------printf("a+1 by ++a = %d\n",++a);
------printf("Current a = %d\n",a);
------printf("b-1 by b-- = %d\n",b--);
------printf("b-1 by --b = %d\n",--b);
------printf("Current b = %d\n",b);
------getch();
}

EX CODE ( 8 )
#include<stdio.h>
#include<conio.h>
void main()
{
------int a=10,b=5,c=7;
------clrscr();
------printf("a=%d\n",a);
------printf("b=%d\n",b);
------printf("c=%d\n",c);
------printf("a>b %d\n",a>b);
------printf("a<c %d\n",a<c);
------printf("b>=c %d\n",b>=c);
------printf("c<=a %d\n",c<=a);
------printf("a==b %d\n",a==b);
------printf("a!=c %d\n",a!=c);
------getch();
}


EX CODE ( 9 )
#include<stdio.h>
#include<conio.h>
#define rate 0.5
#define position 5000
#define show "Hello Constant"
void main()
{
------clrscr();
------int salary=7500, total;
------float tax;
------total=salary+position;
------tax=total*rate/100;
------printf("<<<Program %s >>>\n",show);
------printf("Income = salary + Position\n",position);
------printf("%d = %d + %d \n",total, salary, position);
------printf("TAX = %.2f\n",tax);
------printf("Net Income = &.2f\n",total-tax);
------getch();
}


EX CODE ( 10 )
#include<stdio.h>
#include<conio.h>
void main()
{
------char alpha;
------char name[15];
------int salary;
------float tax;
------clrscr();
------printf("Enter Character :=");scanf("%c",&alpha);
------printf("Enter Name :=");scanf("%s",&name);
------printf("Enter Salary :=");scanf("%d",&salary);
------printf("Enter Tax :=");scanf("%f",&tax);
------printf("--------Report------\n");
------printf("%c\n%s\n%d\n%.2f",alpha,name,salary,tax);
------getch();
}


EX CODE ( 11 )
#include<stdio.h>
#include<conio.h>
void main()
{
------int a;
------clrscr();
------for (a=1; a<=5; ++a)
------{
------printf("Loop No.%d I love C Language\n",a);
------}
------getch();
}


EX CODE ( 12 )
#include<stdio.h>
#include<conio.h>
void main()
{
------int a,b;
------clrscr();
------printf("Enter Number : ");
------scanf("%d",&b);
------printf("===== : Sutkun : =====\n");
------for (a=1;a<=12;++a)
------{
------------printf("%d x %d = %d\n",b,a, b*a);
------}
------getch();
}


EX CODE ( 13 )
#include<stdio.h>
#include<conio.h>
void main()
{
------int a=1;
------clrscr();
------while (a<=5);
------{
------printf("Loop No.%d I love C Language\n",a);
------a++;
------}
------getch();
}


EX CODE ( 14 )
#include<stdio.h>
#include<conio.h>
void main()
{
------int a=1;
------clrscr();
------do
------{
------printf("Loop No.%d I love C Language\n",a);
------a++;
------}
------while (a<5)
------getch();
}


EX CODE ( 15 )
#include<stdio.h>
#include<conio.h>
void main
{
------char score;
------clrscr();
------printf("Enter Score :=");scanf("%d",&score);
------if(score>50)
------{
------------printf("You Score is greater than 50\n");
------}
------getch();
}


EX CODE ( 16 )
#include<stdio.h>
#include<conio.h>
void main
{
------char score;
------clrscr();
------printf("Enter Score :=");scanf("%d",&score);
------if(score>=50)
------{
------------printf("You Score is greater than 50\n");
------}
------else
------{
------------printf("You Score is equal or less than 50\n");
------}
------getch();
}


EX CODE ( 17 )
#include<stdio.h>
#include<conio.h>
void main
{
------char score;
------clrscr();
------printf("Enter Score :=");scanf("%d",&score);
------if(score>100)
------{
------printf("You Score is over 100\n");
------}
------else if(score>=50)
------{
------printf("You Score is in 50-100\n");
------}
------else
------{
------printf("You Score is less than 50\n");
------}
------getch();
}


EX CODE ( 18 )
#include<stdio.h>
#include<conio.h>
void main(void)
{
------char choice;
------clrscr();
------printf("<<<=:= Main Menu =:=>>>\n\n");
------printf("1. Sale Product\n");
------printf("2. Buy Product\n");
------printf("3. Report Today\n");
------printf("4. Exit\n\n");
------printf("Select Menu :=>>");scanf("%d",choice);
------switch (choice)
------{
------------case 1:
------------printf("You want to Sale Product\n");
------------break;
------------case 2:
------------printf("You want to Buy Product\n");
------------break;
------------case 3:
------------printf("You want to Report Today\n");
------------break;
------------case 4:
------------printf("You want to Exit\n");
------------break;
------------default:
------------printf("You Select Choice is Wrong\n");
------------break;
------}
------------getch();
}


EX CODE ( 19 )
#include<stdio.h>
#include<conio.h>
void main(void)
{
char name[5];
int salary[5];
int a,total;
clrscr();
for(a=1;a<=5;a++)
{
gotoxy(10,2);printf("<<<< Input Data >>>>");
gotoxy(10,3);printf("Employee %d.\n",a);
gotoxy(10,4);printf("Name :=");scanf("%s",name[a-1]);
gotoxy(10,5);printf("Salary :=");scanf("%d",salary[a-1]);
total=total+salary[a-1];
clrscr();
}
clrscr;
gotoxy(10,2);printf("========= Report =========");
gotoxy(14,3);printf("Name");
gotoxy(25,3);printf("Salary");
gotoxy(10,4);printf("=========");
for(a=1;a<=5;a++);
{
gotoxy(10,5+a);printf("%d.%s",a,name[a-1]);
gotoxy(27,5+a);printf("%d",salary[a-1]);
}
gotoxy(10,6);printf("=========");
gotoxy(16,7);printf("Totol :=");

gotoxy(27,7+a);printf("%d",total);
gotoxy(10,8+a);printf("=========")
getch();
}


EX CODE ( 20 )
#include <stdio.h>
int main()
{
    //step 1
    float input[5];
    float sum;
    int i = 0;
    //step 2
    do{
        printf("Enter float number : ");
        scanf("%f", &input);
        i++;
    }while(i<5);
   
    printf("\n\n");
   
    //step 3
    for(i=0; i<5; i++){
        printf("output : %.2f \n", input);
        sum += input;
    }
   
    //step 4
    printf("\nSum total is %.2f \n\n", sum);

    return 0;
}


EX CODE ( 21 )
#include<stdio.h>
#include<conio.h>
void main()
{
int number=50,devide=8;
float value;
value=number/devide;
bag=20;
total=bag*kilo;
printf("Answer=%f\n",value);
getch();
}


EX CODE ( 22 )
#include<stdio.h>
#include<conio.h>
void main()
{
------int number=50,devide=8;
------float value;
------value=number/devide;
------printf("Answer=%f\n",value);
------getch();
}


EX CODE ( 23 )
#include<stdio.h>
#include<conio.h>
void main()
{
------float number,devide;
------float value;
------printf("Enter Number:");
------scanf("%f",&number);
------printf("Devide:");
------scanf("%f",&devide);
------value=number/devide;
------printf("\nNumber=%f\tDevider=%f\t\nAnswer=%f\n",number,devide,value);
------getch();
}


EX CODE ( 24 )
#include<stdio.h>
#include<conio.h>
void main()
{
------float value;
------value=1.0+2.0*3.0/4.0;
------printf("Value1=%f\n",value);
------value=1.0+2.0+3.0;
------printf("Value2=%f\n",value);
------value=(1.0+2.0)/3.0;
------printf("Value3=%f\n",value);
------value=(1.0+2.0/3.0)+4.0;
------printf("Value4=%f\n",value);
------getch();
}


EX CODE ( 25 )
?#?include?<stdio.h>
#include<conio.h>
void main()
{
------char ab;
------char name[15],surname[15];
------int age;
------float weight;
------printf("Enter Character : ");
------scanf("%c",&ab); \*surname*\
------printf("Enter Name : ");
------scanf("%s",&name);
------printf("Enter Surname : ");
------scanf("%s",&surname);
------printf("Enter Age : ");
------scanf("%d",&age);
------printf("Enter Weight : ");
------scanf("%f",&weight);
------printf("Character is %c\nName is %s %s\nAge is %d\nWeight is %.2f",ab,name,surname,age,weight);
------getch();
}


EX CODE ( 26 )
#include<stdio.h>
#include<conio.h>
void main()
{
------clrscr();
------printf("sarawut autumporn ton\n");
------printf("0811111111");
------getch();
}


EX HEART CODE ( 27 )
#include<stdio.h>
#include<conio.h>
void main()
{
clrscr();
char name[15],surname[15];
char id[15];
printf("Enter My Name :");
scanf("%s",&name);
printf("Enter Surname :");
scanf("%s",&surname);
printf("Enter My ID : ");
scanf("%s",&id);
clrscr();
textbackground(7);
textcolor(2);
gotoxy(18,1);cprintf("KhunHan Industrial and Community Education College");
gotoxy(41,7);cprintf("o");
gotoxy(42,6);cprintf("o");
gotoxy(43,5);cprintf("o");
gotoxy(44,4);cprintf("o");
gotoxy(45,3);cprintf("o");
gotoxy(46,3);cprintf("o");
gotoxy(47,3);cprintf("o");
gotoxy(48,4);cprintf("o");
gotoxy(49,5);cprintf("o");
gotoxy(50,6);cprintf("o");
gotoxy(51,7);cprintf("o");
gotoxy(52,8);cprintf("o");
gotoxy(52,9);cprintf("o");
gotoxy(52,10);cprintf("o");
gotoxy(52,11);cprintf("o");
gotoxy(52,12);cprintf("o");
gotoxy(51,13);cprintf("o");
gotoxy(50,14);cprintf("o");
gotoxy(49,15);cprintf("o");
gotoxy(48,16);cprintf("o");
gotoxy(47,17);cprintf("o");
gotoxy(46,18);cprintf("o");
gotoxy(45,19);cprintf("o");
gotoxy(44,20);cprintf("o");
gotoxy(43,21);cprintf("o");
gotoxy(42,22);cprintf("o");
gotoxy(41,23);cprintf("o");
gotoxy(40,22);cprintf("o");
gotoxy(39,21);cprintf("o");
gotoxy(38,20);cprintf("o");
gotoxy(37,19);cprintf("o");
gotoxy(36,18);cprintf("o");
gotoxy(35,17);cprintf("o");
gotoxy(34,16);cprintf("o");
gotoxy(33,15);cprintf("o");
gotoxy(32,14);cprintf("o");
gotoxy(31,13);cprintf("o");
gotoxy(30,12);cprintf("o");
gotoxy(30,11);cprintf("o");
gotoxy(30,10);cprintf("o");
gotoxy(30,9);cprintf("o");
gotoxy(30,8);cprintf("o");
gotoxy(31,7);cprintf("o");
gotoxy(32,6);cprintf("o");
gotoxy(33,5);cprintf("o");
gotoxy(34,4);cprintf("o");
gotoxy(35,3);cprintf("o");
gotoxy(36,3);cprintf("o");
gotoxy(37,3);cprintf("o");
gotoxy(38,4);cprintf("o");
gotoxy(39,5);cprintf("o");
gotoxy(40,6);cprintf("o");
gotoxy(41,23);cprintf("o");
gotoxy(31,25);printf("My name is %s %s",name,surname);
gotoxy(31,27);printf("My ID is %s",id);
getch();
}


EX HEART CODE ( 28 )
#include<stdio.h>
#include<conio.h>
void main()
{
clrscr();
textbackground(4);
textcolor(15);
gotoxy(41,7);cprintf("o");
gotoxy(42,6);cprintf("o");
gotoxy(43,5);cprintf("o");
gotoxy(44,5);cprintf("o");
gotoxy(45,5);cprintf("o");
gotoxy(46,5);cprintf("o");
gotoxy(47,5);cprintf("o");
gotoxy(48,5);cprintf("o");
gotoxy(49,5);cprintf("o");
gotoxy(50,5);cprintf("o");
gotoxy(51,6);cprintf("o");
gotoxy(52,7);cprintf("o");
gotoxy(53,8);cprintf("o");
gotoxy(53,9);cprintf("o");
gotoxy(53,10);cprintf("o");
gotoxy(52,11);cprintf("o");
gotoxy(51,12);cprintf("o");
gotoxy(50,13);cprintf("o");
gotoxy(49,14);cprintf("o");
gotoxy(48,15);cprintf("o");
gotoxy(47,16);cprintf("o");
gotoxy(46,17);cprintf("o");
gotoxy(45,18);cprintf("o");
gotoxy(44,19);cprintf("o");
gotoxy(43,20);cprintf("o");
gotoxy(42,21);cprintf("o");
gotoxy(41,22);cprintf("o");
gotoxy(40,22);cprintf("o");
gotoxy(39,21);cprintf("o");
gotoxy(38,20);cprintf("o");
gotoxy(37,19);cprintf("o");
gotoxy(36,18);cprintf("o");
gotoxy(35,17);cprintf("o");
gotoxy(34,16);cprintf("o");
gotoxy(33,15);cprintf("o");
gotoxy(32,14);cprintf("o");
gotoxy(31,13);cprintf("o");
gotoxy(30,12);cprintf("o");
gotoxy(29,11);cprintf("o");
gotoxy(29,10);cprintf("o");
gotoxy(29,9);cprintf("o");
gotoxy(30,8);cprintf("o");
gotoxy(31,7);cprintf("o");
gotoxy(32,6);cprintf("o");
gotoxy(33,5);cprintf("o");
gotoxy(34,5);cprintf("o");
gotoxy(35,5);cprintf("o");
gotoxy(36,5);cprintf("o");
gotoxy(37,5);cprintf("o");
gotoxy(38,5);cprintf("o");
gotoxy(39,6);cprintf("o");
gotoxy(40,7);cprintf("o");
getch();
}

◆ โค้ดตัวไหนติด error ให้ลองเปรียบเทียบแล้วแก้ไขดู
เลขไอพี : ไม่แสดง

อ่านต่อ คุณอาจจะสนใจเนื้อหาเหล่านี้ (ความคิดเห็นกระทู้ อยู่ด้านล่าง)

ความคิดเห็น

#1 | -n95xyz. | 8 ม.ค. 58 14:38 น.


ตัวนี้เป็นการออกแบบให้เป็นรูปหัวใจโดยใช้ excel พอออกแบบเสร็จก็นำ x,y ที่เราได้มาเขียนในโปรแกรม

EX HEART CODE ( 30 )
#include<stdio.h>
#include<conio.h>
void main()
{
clrscr();
textcolor(4);
cprintf("Khunhan Industrial and Community Education College")
textbackground(7);
textcolor(2);
gotoxy(41,7);cprintf("o");
gotoxy(42,6);cprintf("o");
gotoxy(43,5);cprintf("o");
gotoxy(44,4);cprintf("o");
gotoxy(45,3);cprintf("o");
gotoxy(46,3);cprintf("o");
gotoxy(47,3);cprintf("o");
gotoxy(48,4);cprintf("o");
gotoxy(49,5);cprintf("o");
gotoxy(50,6);cprintf("o");
gotoxy(51,7);cprintf("o");
gotoxy(52,8);cprintf("o");
gotoxy(52,9);cprintf("o");
gotoxy(52,10);cprintf("o");
gotoxy(52,11);cprintf("o");
gotoxy(52,12);cprintf("o");
gotoxy(51,13);cprintf("o");
gotoxy(50,14);cprintf("o");
gotoxy(49,15);cprintf("o");
gotoxy(48,16);cprintf("o");
gotoxy(47,17);cprintf("o");
gotoxy(46,18);cprintf("o");
gotoxy(45,19);cprintf("o");
gotoxy(44,20);cprintf("o");
gotoxy(43,21);cprintf("o");
gotoxy(42,22);cprintf("o");
gotoxy(41,23);cprintf("o");
gotoxy(40,22);cprintf("o");
gotoxy(39,21);cprintf("o");
gotoxy(38,20);cprintf("o");
gotoxy(37,19);cprintf("o");
gotoxy(36,18);cprintf("o");
gotoxy(35,17);cprintf("o");
gotoxy(34,16);cprintf("o");
gotoxy(33,15);cprintf("o");
gotoxy(32,14);cprintf("o");
gotoxy(31,13);cprintf("o");
gotoxy(30,12);cprintf("o");
gotoxy(30,11);cprintf("o");
gotoxy(30,10);cprintf("o");
gotoxy(30,9);cprintf("o");
gotoxy(30,8);cprintf("o");
gotoxy(31,7);cprintf("o");
gotoxy(32,6);cprintf("o");
gotoxy(33,5);cprintf("o");
gotoxy(34,4);cprintf("o");
gotoxy(35,3);cprintf("o");
gotoxy(36,3);cprintf("o");
gotoxy(37,3);cprintf("o");
gotoxy(38,4);cprintf("o");
gotoxy(39,5);cprintf("o");
gotoxy(40,6);cprintf("o");
gotoxy(41,23);cprintf("o");

char ab; gotoxy(1,22);
char name[15],surname[15];
int age;
float weight;
printf("Enter Character : ");
scanf("%c",&ab);
printf("Enter Name : ");
scanf("%s",&name);
printf("Enter Surname : ");
scanf("%s",&surname);
printf("Enter Age : ");
scanf("%d",&age);
printf("Enter Weight : ");
scanf("%f",&weight);
clrscr();
printf("Character is%c\nName is %s %s\nAge is %d\nWeight is %.2f",ab,name,surname,age,weight");
getch();
}


EX HEART CODE ( 29 )
#include<stdio.h>
#include<conio.h>
void main()
{
clrscr();
textcolor (4);
gotoxy(35,1);
cprintf("<<<Hello my Student>>>");
char name[15],surname[15];
char id[15];
printf("\nEnter My Name :");
scanf("%s",&name);
printf("Enter My Surname :");
scanf("%s",&surname);
printf("Enter My ID :");
scanf("%s",&id);
clrscr();


textcolor(2);
gotoxy(18,1);cprintf("Khunhan Industrial and Community Education College");
textcolor(5);
gotoxy(41,7);cprintf("o");
gotoxy(42,6);cprintf("o");
gotoxy(43,5);cprintf("o");
gotoxy(44,4);cprintf("o");
gotoxy(45,3);cprintf("o");
gotoxy(46,3);cprintf("o");
gotoxy(47,3);cprintf("o");
gotoxy(48,4);cprintf("o");
gotoxy(49,5);cprintf("o");
gotoxy(50,6);cprintf("o");
gotoxy(51,7);cprintf("o");
gotoxy(52,8);cprintf("o");
gotoxy(52,9);cprintf("o");
gotoxy(52,10);cprintf("o");
gotoxy(52,11);cprintf("o");
gotoxy(52,12);cprintf("o");
gotoxy(51,13);cprintf("o");
gotoxy(50,14);cprintf("o");
gotoxy(49,15);cprintf("o");
gotoxy(48,16);cprintf("o");
gotoxy(47,17);cprintf("o");
gotoxy(46,18);cprintf("o");
gotoxy(45,19);cprintf("o");
gotoxy(44,20);cprintf("o");
gotoxy(43,21);cprintf("o");
gotoxy(42,22);cprintf("o");
gotoxy(41,23);cprintf("o");
gotoxy(40,22);cprintf("o");
gotoxy(39,21);cprintf("o");
gotoxy(38,20);cprintf("o");
gotoxy(37,19);cprintf("o");
gotoxy(36,18);cprintf("o");
gotoxy(35,17);cprintf("o");
gotoxy(34,16);cprintf("o");
gotoxy(33,15);cprintf("o");
gotoxy(32,14);cprintf("o");
gotoxy(31,13);cprintf("o");
gotoxy(30,12);cprintf("o");
gotoxy(30,11);cprintf("o");
gotoxy(30,10);cprintf("o");
gotoxy(30,9);cprintf("o");
gotoxy(30,8);cprintf("o");
gotoxy(31,7);cprintf("o");
gotoxy(32,6);cprintf("o");
gotoxy(33,5);cprintf("o");
gotoxy(34,4);cprintf("o");
gotoxy(35,3);cprintf("o");
gotoxy(36,3);cprintf("o");
gotoxy(37,3);cprintf("o");
gotoxy(38,4);cprintf("o");
gotoxy(39,5);cprintf("o");
gotoxy(40,6);cprintf("o");
gotoxy(41,23);cprintf("o");
gotoxy(31,25);
textcolor(12);
gotoxy(25,25);
cprintf("My name is %s ",name);
textcolor(11);
gotoxy(45,25);
cprintf("Surname%s ",surname);
textcolor(8);
gotoxy(25,27);
cprintf("My ID is %s ",id);
getch();
}

แก้ไขล่าสุด 8 ม.ค. 58 14:47 | ไอพี: ไม่แสดง

แสดงความคิดเห็น

จะต้องเป็นสมาชิกจึงจะแสดงความคิดเห็นได้
เป็นสมาชิกอยู่แล้ว ลงชื่อเข้าใช้ระบบ
ยังไม่ได้เป็นสมาชิก สมัครสมาชิกใหม่
หรือจะลงชื่อเข้าใช้ระบบด้วย Google หรือ Facebook ก็ได้
ลงชื่อเข้าใช้ระบบด้วย Facebook
ลงชื่อเข้าใช้ระบบด้วย Google