C
#include
using namespace std;
void strcpy1(char*, const char*);
void strcpy1(char* p, const char* q)
{
while (*p++ = *q++);
}
int main()
{
char p[20] = {};
char q[20] = { "as456iiiiiihjkd" };
strcpy1(p, q);
int i = 0;
while (p[i]!='\0')
{
printf("%c", p[i]);
i++;
}
return 0;
}
C++
#include
using namespace std;
void strcpy1(char*, const char*);
void strcpy1(char* p, const char* q)
{
while (*p++ = *q++);
}
int main()
{
char p[20] = {};
char q[20] = { "as456iiiiiihjkd" };
strcpy1(p, q);
cout << p;
}
C
#include
int strcmp1(char*, const char*);
int strcmp1(char* str1, const char* str2)
{
while (*str1 && *str2 && *str1 == *str2)
{
str1++; str2++;
}
return *str1 - *str2;
}
int main()
{
char str1[] = "aerttydfgs";
char str2[] = "wertyyyyyg";
printf( "%d",strcmp1(str1, str2));
}
C++
#include
using namespace std;
int strcmp1(char*, const char*);
int strcmp1(char* str1, const char* str2)
{
while (*str1 && *str2 && *str1 == *str2)
{
str1++; str2++;
}
return *str1 - *str2;
}
int main()
{
char str1[] = "werttydfgs";
char str2[] = "wertyyyyyg";
cout << strcmp1(str1, str2);
}
C
#include
int com(char*, char*);
int main()
{
char str1[50] = "werttydfgs";
char str2[20] = "wertyyyyyg\0";
com(str1, str2);
int i = 0;
printf("%s\n", str1);
}
int com(char* str1, char* str2)
{
char* p = str1;
while (*str1 != '\0') str1++;
while (*str1++ = *str2++);
return 0;
}
C++
#include
using namespace std;
char com(char*, char*);
int main()
{
char str1[50] = "werttydfgs";
char str2[20] = "wertyyyyyg";
com(str1, str2);
cout << str1<<endl;
cout << str2;
}
char com(char *str1,char *str2)
{
char * p = str1;
while (* str1 != '\0') str1++;
while (*str1++ = *str2++);
return *p;
}
C
#include
int getlenth(char*);
int main()
{
char str1[50] = "wertt34555ydfgs";
char str2[20] = "wertyyyyyg";
int k = getlenth(str1);
printf("%d",k);
}
int getlenth(char* str1)
{
int i = 0;
while (*str1 != '\0')
{
str1++;
i++;
}
return i;
}
C++
#include
using namespace std;
int getlenth(char*);
int main()
{
char str1[50] = "werttydfgs";
char str2[20] = "wertyyyyyg";
int k =getlenth(str1);
cout << k << endl;
}
int getlenth(char* str1)
{
int i = 0;
while(*str1!='\0')
{
str1++;
i++;
}
return i;
}
C
#include
int findv(int*, int);
int main()
{
int a[50] = { 12,23,45,78,9,54,85,45,7,78,45,63,45,78,78 };
int need = 78;
int k = findv(a, need);
if (k)
printf("%d",a[k]);
else
printf("false");
}
int findv(int* a, int b)
{
int i = 0;
while (*a != '\0')
{
if (*a != b)
{
a++;
i++;
}
else
return i;
}
return false;
}
C++
#include
using namespace std;
int findv(int *,int);
int main()
{
int a[50] = {12,23,45,78,9,54,85,45,7,78,45,63,45,78,78};
int need = 89;
int k = findv(a,need);
if (k)
cout << a[k] << endl;
else
cout << false;
}
int findv(int* a, int b)
{
int i=0;
while (*a!='\0')
{
if (*a != b)
{
a++;
i++;
}
else
return i;
}
return false;
}
pass 。主要是程序太长了,csdn老是卡住。
C
#include
bool isLeapYear(int y) //判断某一年是否闰年
{
return (y % 4 == 0 && y % 100 != 0) || (y % 400 == 0);
}
int main()
{
int year, month, day, i, s = 0;
int a[13] = { 0, 31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31
};
scanf_s("%d%d%d", &year, &month, &day);
for (i = 1; i < month; i++)
s = s + a[i];
s = s + day;
if (isLeapYear(year) && month > 2) s++;
printf("%d",s);
}
C++
#include
using namespace std;
bool isLeapYear(int y) //判断某一年是否闰年
{
return (y % 4 == 0 && y % 100 != 0) || (y % 400 == 0);
}
int main()
{
int year, month, day, i, s = 0;
int a[13] = {0, 31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31
};
cin >> year >> month >> day;
for (i = 1; i < month; i++)
s = s + a[i];
s = s + day;
if (isLeapYear(year) && month > 2) s++;
cout << s;
}
C
#include
#include
#include
int main()
{
int x, y, z;
srand(time(0));
x = rand() % 100;
y = rand() % 100;
printf("输入0结束\n");
printf("%d+%d=", x, y);
scanf_s("%d", &z);
while (z != 0)
{
while (z != x + y)
{
printf( " × 错误!请重做");
printf("%d+%d=", x, y);
scanf_s("%d", &z);
}
printf( " √ 正确!\n");
x = rand() % 100;
y = rand() % 100;
printf("%d+%d=", x, y);
scanf_s("%d", &z);
}
}
C++
#include
#include
using namespace std;
#include
int main()
{
int x, y, z;
srand(time(0));
x = rand() % 1000;
y = rand() % 1000;
cout << x << " + " << y << " = ";
cin >> z;
while (z != '\0')
{
while (z != x + y)
{
cout << " × 错误!请重做\n";
cout << x << " + " << y << " = ";
cin >> z;
}
cout << " √ 正确!\n";
x = rand() % 1000;
y = rand() % 1000;
cout << x << " + " << y << " = ";
cin >> z;
}
}
C
#include
#include
#include
int main()
{
int i, k, a[52], b[13];
for (i = 0; i < 52; i++) a[i] = i + 1;
srand(time(0));
for (i = 0; i < 13; i++)
{
k = rand() % (52 - i);
b[i] = a[k];
swap(a[k], a[51 - i]);
}
for (i = 0; i < 13; i++) printf("%d ",b[i]);
}
C++
#include
#include
using namespace std;
#include
int main()
{
int i, k, a[52], b[13];
for (i = 0; i < 52; i++) a[i] = i + 1;
srand(time(0));
for (i = 0; i < 13; i++)
{
k = rand() % (52 - i);
b[i] = a[k];
swap(a[k], a[51 - i]);
}
for (i = 0; i < 13; i++) cout << b[i] << " ";
}
#include
using namespace std;
int main() {
double k=1;
for (int i = 1; i <= 100; i++)
k = k * i;
cout << k;
}