C
#include
int main()
{
char st[100];
printf("请输入字符串:");
scanf_s("%s", st, 100);
int i = 0, num = 0;
while (st[i] != '\0')
{
if (st[i] >= 'a' and st[i] <= 'z')
num=num+1;
i++;
}
printf("%d",num);
}
C++
#include
using namespace std;
int main()
{
char s[100];
cin.getline(s,100);
int i = 0, num = 0;
while (s[i]!='\0')
{
if (s[i] >= 'a' and s[i] <= 'z')
num++;
i++;
}
cout << num;
}
C
#include
int main()
{
char s[100];
scanf_s("%s", s, 100);
int i = 0, num = 0;
while (s[i] != '\0')
{
if (s[i] >= 'A' and s[i] <= 'Z')
s[i] += 32;
i++;
}
i = 0;
while (s[i]!='\0')
{
printf("%c", s[i]);
i++;
}
}
C++
#include
using namespace std;
int main()
{
char s[100];
cin.getline(s, 100);
int i = 0, num = 0;
while (s[i] != '\0')
{
if (s[i] >= 'A' and s[i] <= 'Z')
s[i]+=32;
i++;
}
cout << s<<endl;
}
C
#include
int main()
{
int a[10][10] = { 0 };
for (int i = 0; i < 10; i++)
{
a[i][0] = 1;
a[i][i] = 1;
}
for (int i = 1; i < 10; i++)
for (int j = 1; j < i; j++)
a[i][j] = a[i - 1][j - 1] + a[i - 1][j];
for (int i = 0; i < 10; i++)
{
for (int j = 0; j <= i; j++)
printf("%d \t", a[i][j]);
printf("\n");
}
}
C++
#include
#include
using namespace std;
int main()
{
int a[10][10] = { 0 };
for (int i = 0; i < 10; i++)
{
a[i][0] = 1;
a[i][i] = 1;
}
for (int i = 1; i < 10; i++)
for (int j = 1; j < i; j++)
a[i][j] = a[i - 1][j - 1] + a[i - 1][j];
for (int i = 0; i < 10; i++)
{
for (int j = 0; j <= i; j++)
cout << setw(4) << a[i][j];
cout << endl;
}
}
C
#include
int main()
{
int i, j;
for (i = 1; i < 10; i++)
{
for (j = 1; j <= i; j++)
{
printf("i*j=%d\t", i * j);
}
printf("\n");
}
return 0;
}
C++
#include
using namespace std;
int main()
{
int i, j;
for (i = 1; i < 10; i++)
{
for (j = 1; j <= i; j++)
{
cout << i<<"*"<< "="<< i*j<< " ";
}
cout << endl;
}
}
C
#include
#include
#include
int main()
{
int a[7] = { 0 };
srand(time(0));
for (int i = 1; i <= 10000; ++i)
a[1 + rand() % 6]++;
for (int i = 1; i <= 6; i++)
printf("%d : %d\n", i, a[i]);
}
C++
#include
using namespace std;
#include
#include
int main()
{
int a[7] = { 0 };
srand(time(0));
for (int i = 1; i <= 10000; ++i)
a[1 + rand() % 6]++;
for (int i = 1; i <= 6; ++i)
cout << i << ": " << a[i] << endl;
}
C
#include
#include
double dis(double, double, double, double);
int main()
{
double(d);
double x1 = 0, x2 = 4, y1 = 0, y2 = 3;
d = dis(x1, x2, y1, y2);
printf("%lf",d);
}
double dis(double x1, double x2, double y1, double y2)
{
double d = sqrt((y1 - y2) * (y1 - y2) + (x1 - x2) * (x1 - x2));
return d;
}
C++
#include
using namespace std;
double dis(double, double,double, double);
int main()
{
double(d);
double x1 = 0, x2 = 4, y1 = 0, y2 = 3;
d = dis(x1, x2, y1, y2);
cout << d;
}
double dis(double x1, double x2, double y1,double y2)
{
double d = sqrt((y1 - y2) * (y1 - y2) + (x1 - x2) * (x1 - x2));
return d;
}
C
#include
int main()
{
int a, max1, min1;
float total, ave;
printf("请输入十位评委的分数");
scanf_s("%d",&a);
max1 = min1 = total = a;
for (int i = 0; i < 9; i++)
{
scanf_s("%d", &a);
if (max1 < a) max1 = a;
if (min1 > a) min1 = a;
total = total + a;
}
total = total - min1 - max1;
ave = total / 8;
printf( "%lf",ave);
return 0;
}
C++
#include
using namespace std;
int main()
{
float a,max, min, total, ave;
cout << "请输入十位评委的分数" << endl;
cin >> a;
max = min =total= a;
for (int i=0;i<9;i++)
{
cin >> a;
if (max < a) max = a;
if (min > a) min = a;
total = total + a;
}
total = total - min - max;
ave = total / 8;
cout << ave;
}
C
#include
void reverse(int*, int);
int main()
{
int a[10] = { 1,2,3,4,5,6,7,8,9,10 };
int n = sizeof(a) / sizeof(a[0]);
reverse(a, n);
for (int i = 0; i < 10; i++)
printf("%d ",a[i]);
}
void reverse(int* a, int n)
{
int temp;
for (int i = 0; i < n / 2; i++)
{
temp = a[i];
a[i] = a[n - 1 - i];
a[n - 1 - i] = temp;
}
}
C++
#include
using namespace std;
void reverse(int *,int);
int main()
{
int a[10] = { 1,2,3,4,5,6,7,8,9,10 };
int n = sizeof(a)/sizeof(a[0]);
reverse(a,n);
for (int i = 0; i < 10; i++)
cout << a[i]<<" ";
}
void reverse(int* a,int n)
{
int temp;
for (int i = 0; i < n / 2; i++)
{
temp = a[i];
a[i] = a[n - 1 - i];
a[n - 1 - i] = temp;
}
}
C++
#include
using namespace std;
void findmax(int*, int);
int main()
{
int a[10] = { 1,2,3,4,25,16,97,8,9,10 };
int n = sizeof(a) / sizeof(a[0]);
findmax(a, n);
}
void findmax(int * a,int n)
{
int max = a[0];
int k=0;
for (int i = 1; i < n; i++)
{
if (a[i] > max)
{
max = a[i];
k = i;
}
}
cout << "位置在第" << k + 1<<"个";
}
C
#include
#include
int main()
{
int a[3][3];
int i, j, k, p, q, max, min;
for (i = 0; i < 3; i++) {
for (j = 0; j < 3; j++)
scanf_s("%d", &a[i][j]); //输入数组
}
for (i = 0; i < 3; i++) {
for (j = 0, max = 0, p = 0; j < 3; j++) { //判断出该行元素的最大值
if (a[i][j] > max) {
max = a[i][j];
p = j;
}
else {
max = max;
p = p;
}
}
for (k = 0, min = a[i][p], q = i; k < 3; k++) { //判断最大值在该列是否为最小值
if (a[k][p] < min) {
min = a[k][p];
q = k;
}
else {
min = min;
q = q;
}
}
if (i == q) {
printf("%d is the saddle point!\n", a[i][p]); //如果该最大值行号没有改变,输出鞍点
break;
}
}
if (i == 3 && i != q)
printf("There is no saddle point!\n"); //输出没有鞍点
system("pause");
return 0;
}
C++
#include
using namespace std;
int main()
{
int a[3][3];
int i, j, k, p, q, max, min;
for (i = 0; i < 3; i++) {
for (j = 0; j < 3; j++)
cin>>a[i][j]; //输入数组
}
for (i = 0; i < 3; i++) {
for (j = 0, max = 0, p = 0; j < 3; j++) { //判断出该行元素的最大值
if (a[i][j] > max) {
max = a[i][j];
p = j;
}
else {
max = max;
p = p;
}
}
for (k = 0, min = a[i][p], q = i; k < 3; k++) { //判断最大值在该列是否为最小值
if (a[k][p] < min) {
min = a[k][p];
q = k;
}
else {
min = min;
q = q;
}
}
if (i == q) {
cout << a[i][p] <<" is the saddle point!"; //如果该最大值行号没有改变,输出鞍点
break;
}
}
if (i == 3 && i != q)
cout<<"There is no saddle point!"<<endl; //输出没有鞍点
}