2-1
#include
#include
int main(void)
{
system("title 1211111");
system("color 0c");
system("ipconfig");
printf("hello\n");
system("pause");
return 0;
}
2-2
#include
#include
void printf1();
int main()
{
system("color 0D");
printf1();
system("pause");
return 0;
}
void printf1()
{
printf(" *\n");
printf(" ***\n");
printf(" *****\n");
printf("*******\n");
}
2-3
#include
#include
int main(void)
{
//system("title Hello World");
//system("color 14");
//system("systeminfo");
//system("pause");
//return 0;
//int a, b, temp;
//a = 100;
//b = 200;
//int c = 65;
//char c1 = 'A';
//printf("变化前:a=%d,b=%d\n", a, b);
//temp = a;
//a = b;
//b = temp;
//
//printf("变化后:a=%d,b=%d\n", a, b);
//printf("a的十进制表示为:%d\na的八进制表示为:%o\na的十六进制表示为:0x%x\n", a, a, a);
//printf("65的字符表示:%c\n", c);
//printf("A的十进制表示:%d\n", c1);
//system("pause");
int a, b, c;
scanf_s("%d", &a);
scanf_s("%d", &b);
c = a + b;
printf("%d\n", c);
c = a - b;
printf("%d\n", c);
c = a*b;
printf("%d\n", c);
c = a / b;
printf("%d\n", c);
system("pause");
return 0;
}
2-4
// day2-04.cpp : 定义控制台应用程序的入口点。
//
#include "stdafx.h"
#include
int _tmain(int argc, _TCHAR* argv[])
{
char szCommandLine[] = "cmd";
STARTUPINFO si = { sizeof(si) };
PROCESS_INFORMATION pi;
si.dwFlags = STARTF_USESHOWWINDOW;//指定wShowWindow成员有效
si.wShowWindow = TRUE;//此成员设为TURE的话则显示新建进程的主窗口,为FALSE的话不显示
BOOL bRet = ::CreateProcess(
NULL, //不在此指定可执行文件的文件名
szCommandLine, //命令行参数
NULL, //默认进程安全性
NULL, //默认线程安全性
FALSE, //指定当前进程内的句柄不可以被子进程继承
CREATE_NEW_CONSOLE, //为新进程创建一个新的控制台窗口
NULL, //使用本进程的环境变量
NULL, //使用本进程的驱动器和目录
&si, //
&pi //
);
if (bRet)
{//不使用的句柄应当立即关闭
::CloseHandle(pi.hThread);
::CloseHandle(pi.hProcess);
printf("新进程的进程ID号:%d\n",pi.dwProcessId);
printf("新进程的主线程ID号:%d\n", pi.dwThreadId);
}
return 0;
}
2-5
// printf函数.cpp : 定义控制台应用程序的入口点。
//
#include "stdafx.h"
#include
#include
int _tmain(int argc, _TCHAR* argv[])
{
int _int=5;
double int_=5.0;
char For='5';
float USS=5.0;
int a = 20;
printf("%d\n", a);
printf("%10d%d\n", a);
printf("%-10d%d\n", a);
printf("%p", &a);
printf("\n————————————————————————————————\n");
int nNumb = 10;
printf("%d\n",nNumb);
printf("%4d\n", nNumb);
printf("%-4d\n", nNumb);
long long int nNumbA = 10;
printf("%ld\n",nNumbA);
printf("%o\n",nNumbA);
printf("%x\n",nNumbA);
unsigned char nNumbB = 254;
printf("%u\n", nNumbB);
printf("%c\n", nNumbB);
printf("%d\n",nNumbB);
char ch[] = "he";
printf("%5s\n", ch);
printf("%-5s\n", ch);
float fNumbC = 127665.4986;
printf("%15.2f\n", fNumbC);
printf("0x%p\n",ch);
printf("\n————————————————————————————————\n");
printf("\n————————————————————————————————\n");
printf("%d,%f,%c,%f",_int,int_,For,USS);
system("pause");
return 0;
}
2-6 作业
#include
#include
void timu1()
{
system("cls");
printf("题目1.判断是否是奇数\n");
int a;
printf("请输入一个数用来判断是否为奇数\n");
scanf_s("%d", &a);
if (a % 2 == 0)
printf("%d不是奇数\n", a);
else
printf("%d是奇数\n", a);
system("pause");
}
void timu2()
{
system("cls");
printf("题目2.判断是否是闰年\n");
int a;
printf("请输入一个年份\n");
scanf_s("%d", &a);
if (a % 4 == 0 && a % 100 != 0 || a % 400 == 0)
{
printf("%d是闰年", a);
}
else
printf("%d不是闰年", a);
system("pause");
}
void timu3()
{
system("cls");
printf("题目3.输出两个数中较大的\n");
int a, b;
printf("请输入两个整数,中间用空格间隔,输入完成后敲回车确认\n");
scanf_s("%d%d", &a, &b);
//if (a > b)
// printf("二者中较大的值为:%d", a);
//else
//{
// printf("二者中较大的值为:%d", b);
//}
printf("二者中较大的值为:%d\n", a > b ? a : b);
system("pause");
}
void timu4()
{
system("cls");
printf("题目4.判断字符\n");
char b;
printf("请输入一个字符\n");
b = getchar();
scanf_s("%c", &b, 1);
if (48 <= b&&b <= 57)
{
printf("是一个数字\n");
}
if (65 <= b&&b <= 90)
{
printf("是一个大写英文字母\n");
}
if (97 <= b&&b <= 122)
{
printf("是一个小写英文字母\n");
}
system("pause");
}
void timu5()
{
system("cls");
int a, b, c;
printf("题目5.输入三个整数,中间用空格间隔,输入完成后敲回车确认");
scanf_s("%d%d%d", &a, &b, &c);
if (a > b&&b > c)
printf("max=%d,mid=%d,min=%d", a, b, c);
if (a > b&&b < c&&a < c)
printf("max=%d,mid=%d,min=%d", c, a, b);
if (a > b&&bc)
printf("max=%d,mid=%d,min=%d", a, c, b);
if (a < b&&b < c)
printf("max=%d,mid=%d,min=%d", c, b, a);
if (ac&&a>c)
printf("max=%d,mid=%d,min=%d", b, a, c);
if (ac&&aprintf("max=%d,mid=%d,min=%d", b, c, a);
system("pause");
}
void timu6()
{
system("cls");
char ch='s';
printf("转换大小写\n转换前字母为:%c\n",ch);
ch = ch - 32;
printf("转换后字母为:%c\n", ch);
system("pause");
}
void timu7()
{
system("cls");
int a, b, c;
float avg;
printf("题目.7请输入三个成绩,中间用空格间隔,输入完成后敲回车确认\n");
scanf_s("%d%d%d", &a, &b, &c);
printf("三个人的总成绩为:%d\n", a + b + c);
avg = (float)(a + b + c) / 3;
printf("三个人的平均成绩为:%f\n", avg);
system("pause");
}
void timu8()
{
system("cls");
int year, month, day,days;
days = 0;
char months_ping[12] = { 31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31 };
char months_run[12] = { 31, 29, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31 };
printf("题目.8请输入一个年份\n");
scanf_s("%d", &year);
printf("请输入一个月份\n");
scanf_s("%d", &month);
printf("请输入一个日期\n");
scanf_s("%d", &day);
if (year % 4 == 0 && year % 100 != 0 || year % 400 == 0)
{
if (month==1)
{
days = day;
}
else
{
for (int i = 0; i < month-1; i++)
{
days += months_run[i];
}
days = days + day;
}
}
else
{
if (month ==1)
{
days = day;
}
else
{
for (int i = 0; i < month-1; i++)
{
days += months_ping[i];
}
days = days + day;
}
}
printf("你输入的日期是%d年%d月%d日,是该年的第%d天",year,month,day,days);
system("pause");
}
void timu9()
{
system("cls");
int a;
printf("题目.9请输入一个数\n");
scanf_s("%d", &a,1);
if (a % 5 == 0 && a % 7 == 0)
{
printf("Yes");
}
else
{
printf("No");
}
system("pause");
}
void timu10()
{
int a, b,re;
char c;
printf("题目10.请输入运算表达式:\n");
scanf_s("%d%c%d", &a, &c, 1, &b);
switch (c)
{
case '+':
re = a + b;
break;
case '-':
re = a - b;
break;
case '*':
re = a*b;
break;
case '/':
re = a / b;
break;
default:
printf("符号错误");
break;
}
printf("%d",re);
system("pause");
}
int main()
{
while (1)
{
int i;
system("cls");
system("color 0a");
printf("-----------15pb作业002----------\n");
printf("请输入想要查看的题目序号:\n");
scanf_s("%d", &i,1);
scanf_s("%*[^\n]%*c"); //清空输入缓冲区 放在scanf_s 后面
printf("--------------------------------\n");
switch (i)
{
case 1:
timu1();
break;
case 2:
timu2();
break;
case 3:
timu3();
break;
case 4:
timu4();
break;
case 5:
timu5();
break;
case 6:
timu6();
break;
case 7:
timu7();
break;
case 8:
timu8();
break;
case 9:
timu9();
break;
default:
timu10();
break;
}
}
return 0;
}