C++/C语言程序代码

时间:2021-12-31 04:01:48
 //-----------------------------------1
#include <stdio.h>
#include<stdlib.h>
void main()
{
int value = ; printf("%01d\n", value);
printf("%02d\n", value);
printf("%03d\n", value);
printf("%04d", value);
getchar();
getchar();
getchar();
getchar();
}
//--------------------------------2
 #include <stdio.h>
int main(void)
{
double a = 50.00, b = 3.00, y = 0.00, m = 0.00, u = 0.00, c = 0.00;
scanf("%lf", &c);
y = a + c;
m = y/b;
u = a/m;
printf("%lf\n", u);
return ;
}
 graphics代码
#include "graphics.h"
#include "conio.h"
#include "easyx.h"
ht(int x,int y)
{
setcolor(YELLOW);
setfillcolor(BLUE);
fillcircle(x,y,);
Sleep();
setcolor(BLACK);
setfillcolor(BLACK);
fillcircle(x,y,);
}
void main()
{
initgraph(,); //(x,y) 只要有一个变量等于定值时开始反弹、x=0、x=460、y=620、y=0
int flagx=,flagy=; //用来标记 球走的方向 (0,0)向右下、(1,0)左下、(0,1)右上、(1,1)左上
int x=,y=;
while ()
{ switch(flagx)
{
case :
{
switch(flagy)
{
case :{ x+=;
y+=;
ht(x,y);
if (x=)
{
flagx=;
flagy=;
}
if (y=)
{
flagy=;
flagx=;
}
}break;
case :{
x+=;
y-=;
ht(x,y);
if (x=)
{
flagy=;
flagx=;
} if (y=)
{
flagy=;
flagx=;
}
}break;
}
}
case :
{
switch(flagy)
{
case :{ x+=;
y-=;
ht(x,y);
if (y=)
{
flagx=;
flagy=;
}
if (x=)
{
flagy=;
flagx=;
}
}break;
case :{
x-=;
y-=;
ht(x,y);
if (x=)
{
flagy=;
flagx=;
} if (y=)
{
flagy=;
flagx=;
}
}break;
} } }
}
getch();
closegraph();
}
 //-----------------------------------1
#include <stdio.h>
#include<stdlib.h>
void main()
{
int value = ; printf("%01d\n", value);
printf("%02d\n", value);
printf("%03d\n", value);
printf("%04d", value);
getchar();
getchar();
getchar();
getchar();
}
//--------------------------------2
#include <stdio.h>
#include <ctype.h>
#include <conio.h> void main()
{
char letter; // Letter typed by the user printf("Do you want to continue? (Y/N): "); letter = getch(); // Get the letter
letter = toupper(letter); // Convert letter to uppercase while ((letter != 'Y') && (letter != 'N'))
{
putch(); // Beep the speaker
letter = getch(); // Get the letter
letter = toupper(letter); // Convert letter to uppercase
} printf("\nYour response was %c\n", letter);
/*putch()向屏幕输出字符的函数
使用方式:
① putch('转义字符');
② putch('单个字符');
③ putch(字符变量);
注:③需先定义 char 字符变量='单个字符';
头文件:conio.h
-----
putchar()在stdout上输出字符的宏
原形:int putchar(int c)
返回值:成功返回字符c,失败返回EOF。
头文件:stdio.h,7是响铃的意思*/
}
//-------------------------------------------3
#include <stdio.h> void main()
{
char letter; int vowel_count = ; for (letter = 'A'; letter <= 'Z'; letter++)
switch (letter) {
case 'A':
case 'E':
case 'I':
case 'O':
case 'U': vowel_count++;
}; printf("The number of vowels is %d\n", vowel_count);
}
//------------------------------------------4
#include <stdio.h> void main()
{
int counter; for (counter = ; counter <= ; counter++)
{
if (counter == )
break; printf("%d ", counter);
} printf("\nNext loop\n"); for (counter = ; counter >= ; counter--)
{
if (counter == )
break; printf("%d ", counter);
}
}