1. Compile in VS2017 environment. When using scanf, write scanf as scanf_s and you can input from the keyboard.
When using VS2017, the debug window will flash and you need to write a header file #include <; stdlid.h> , and then in return 0; Before writing system ("pause"); This phenomenon can be avoided. Three, the following is a few classic examples 1. Can receive keyboard characters, if it is lowercase, then output uppercase; If it is uppercase, output lowercase; If it is a number, it is not printed
When using VS2017, the debug window will flash and you need to write a header file #include <; stdlid.h> , and then in return 0; Before writing system ("pause"); This phenomenon can be avoided. Three, the following is a few classic examples 1. Can receive keyboard characters, if it is lowercase, then output uppercase; If it is uppercase, output lowercase; If it is a number, it is not printed
#include <stdio.h>
#include <stdlib.h>
int main()
{
int ch = 0;
while ((ch = getchar()) != EOF)
{
if (ch >= 65 && ch <= 90)
{
ch = ch + 32;
putchar(ch);
}
else if (ch >= 97 && ch <= 122)
{
ch = ch - 32;
putchar(ch);
}
else if (ch >= '0' && ch <= '9')
{
;
}
else
{
putchar(ch);
}
}
system("pause");
return 0;
}
2. For example
Output a diamond
#include<stdio.h>
#include<stdlib.h>
int main()
{
int line = 0;
int i = 0;
scanf_s("%d", &line);
for (i = 0; i < line; i++)
{
int j = 0;
for (j = 0; j < line-1-i ; j++)
{
printf(" ");
}
for (j = 0; j < 2 * i + 1; j++)
{
printf("*");
}
printf("\n");
}
for (i = 0; i < line-1; i++)
{
int j = 0;
for (j = 0; j <=i; j++)
{
printf(" ");
}
for (j = 0; j < (line-1-i)*2 - 1; j++)
{
printf("*");
}
printf("\n");
}
system("pause");
return 0;
}