บทที่ 6

แนะนำ สอบถาม ภาษา C สำหรับผู้เริ่มต้น

Moderator: phpbb, mindphp, ผู้ดูแลกระดาน

ตอบกลับโพส
ภาพประจำตัวสมาชิก
icphysics
phpBBThailand Full Member
phpBBThailand Full Member
โพสต์: 38
ลงทะเบียนเมื่อ: 01 ม.ค. 1970, 07:00
ติดต่อ:

บทที่ 6

โพสต์ โดย icphysics »

/*บทที่ 6 ข้อ 6.ก*/
#include<stdio.h>
void main()
{
int k=0;
while(k++ <=20)
printf("\tk=%3d \n",k);
printf(" befor while loop k===%3d\n",k);
}

/* ตอบ k=21 */
ภาพประจำตัวสมาชิก
icphysics
phpBBThailand Full Member
phpBBThailand Full Member
โพสต์: 38
ลงทะเบียนเมื่อ: 01 ม.ค. 1970, 07:00
ติดต่อ:

โพสต์ โดย icphysics »

/* ข้อ บทที่ 6 ข้อ 6ข */
#include<stdio.h>
void main()
{
int k=0;
while(++k <=20)
printf("\tk=%3d \n",k);
printf(" befor while loop k===%3d\n",k);
}
/* ค่า k=20*/
ภาพประจำตัวสมาชิก
icphysics
phpBBThailand Full Member
phpBBThailand Full Member
โพสต์: 38
ลงทะเบียนเมื่อ: 01 ม.ค. 1970, 07:00
ติดต่อ:

โพสต์ โดย icphysics »

/* ข้อ บทที่ 6 ข้อ 6ค */
#include<stdio.h>
void main()
{
int k=0,w;
for(k=0,w=k++;k<20;++k)
printf("\tk=%3d \n",k);
printf(" befor for loop k===%3d\n",k);
}
/* ค่า k=20*/
ภาพประจำตัวสมาชิก
icphysics
phpBBThailand Full Member
phpBBThailand Full Member
โพสต์: 38
ลงทะเบียนเมื่อ: 01 ม.ค. 1970, 07:00
ติดต่อ:

โพสต์ โดย icphysics »

/*ข้อ บทที่ 6 ข้อ 6ง */
#include<stdio.h>
void main()
{
int k=0;
do {
printf("\t befor k++ k=%3d \n",k);
++k;
printf("\tk=%3d \n",k);
}
while (k++<20);

printf(" befor for loop k===%3d\n",k);
}
/*total= 55
k=11
*อ
ภาพประจำตัวสมาชิก
icphysics
phpBBThailand Full Member
phpBBThailand Full Member
โพสต์: 38
ลงทะเบียนเมื่อ: 01 ม.ค. 1970, 07:00
ติดต่อ:

โพสต์ โดย icphysics »

/* ข้อ บทที่ 6 ข้อ 6จ */
#include<stdio.h>
void main()
{
int k=0,total;
for(total=0,k=1;k<=10;total+=k++)
printf("\tk=%3d \n",k);
printf("\total =%3d \n",total);
printf(" befor for loop k==%3d\n",k);
}
/* total =55
k=11
*/
ภาพประจำตัวสมาชิก
icphysics
phpBBThailand Full Member
phpBBThailand Full Member
โพสต์: 38
ลงทะเบียนเมื่อ: 01 ม.ค. 1970, 07:00
ติดต่อ:

โพสต์ โดย icphysics »

/*บทที่ 6 ข้อ 7 */
/*เขียนใหม่เป็นดังนี้*/
while((chr=getchar())!='\n')
{
if(chr!=chr)
contunue;
putchar(chr);
}
ตอบกลับโพส

ย้อนกลับไปยัง

ผู้ใช้งานขณะนี้

กำลังดูบอร์ดนี้: 13 และ บุคคลทั่วไป 0 ท่าน