#include <iostream>
#include <iomanip>
#include<stdio.h>
#include<string>
#include <fstream>
using namespace std;
int main()
{
double r, s, l;
cin >> r;
s = 3.14 * r * r;
l = 2 * 3.14 * r;
cout << "面积=" << s << endl;
cout <<"\n" << endl;
cout << "周长=" << l << endl;
system("pause");
return 0;
}
int main()
{
float r = 3.0, s, l;
l = 2 * PI * r;
s = PI * r * r;
cout << "l=" << l << "\ns=" << s << endl;
system("pause");
return 0;
}
int main()
{
double f, c;
cout << "华氏温度=" << endl;
cin >> f;
c = 5 / 9.00 * (f - 32);
cout << "换算的摄氏温度=" << c << endl;
system("pause");
return 0;
}
int main() {
int i = 3, j;
j = ++i;
cout << "i+" << i << '\t' << "j=" << j << endl;
i = 3;
j = i++;
cout << "i=" << i << "\t" << "j=" << j << endl;
system("pause");
return 0;
}
int main() {
int a = 38;
float b;
b = float(a);
cout << b << endl;
system("pause");
return 0;
}
int main() {
double a, b, c, p, s;
cin >> a >> b >> c;
p = (a + b + c) / 2;
s = sqrt(p * (p - a) * (p - b) * (p - c));
cout << "三角形面积为:" << s << endl;
system("pause");
return 0;
}
int main() {
double a, b, c, p, s;
cin >> a >> b >> c;
if (a + b > c && a + c > b && b + c > a)
{
p = (a + b + c) / 2;
s = sqrt(p * (p - a) * (p - b) * (p - c));
cout << "三角形面积:" << s << endl;
}
else
cout << "输入数值不能组成三角形" << endl;
}
int main() {
double a, b, c, p, s;
cin >> a >> b >> c;
while (!(a + b > c && a + c > b && b + c > a))
{
cout << "输入有误,再次输入" << endl;
cin >> a >> b >> c;
}
p = (a + b + c) / 2;
s = sqrt(p * (p - a) * (p - b) * (p - c));
cout << "三角形面积:" << s << endl;
}
int main() {
char sex, group;
int age;
cout << "input sex(f or m )and age:" << endl;
cin >> sex >> age;
if (sex == 'm')
if (age < 40) group = 'A'; else group = 'B';
else
if (age < 40) group = 'C'; else group = 'D';
cout << "group=" << group << endl;
}
int main() {
int mark;
char grade;
cout << "input mark (0-100);" << endl;
cin >> mark;
switch (mark / 10) {
case 10:
case 9: grade = 'A'; break;
case 8: grade = 'B'; break;
case 7: grade = 'C'; break;
case 6: grade = 'D'; break;
default: grade = 'E';
}
cout << "mark=" << mark << ",grade=" << grade << endl;
system("pause");
return 0;
}
int main() {
int i(1), sum(0);
while (i < 100) {
sum = sum + i;
i = i + 2;
}
cout << "s=" << sum << endl;
system("pause");
return 0;
}
int main() {
int i(1), sum(0);
do {
sum = sum + i;
i =i + 2;
} while (i < 100);
cout << "sum=" << sum << endl;
system("pause");
return 0;
}
int main() {
int i(1), sum(0);
for (i; i < 100;i=i+2) {
sum = sum + i;
}
cout << "sum=" << sum << endl;
system("pause");
return 0;
}
int main() {
int i(1), sum(0);
for ( ; ;) {
if (i >= 100)
break;
sum = sum + i;
i = i + 2;
}
cout << "sum=" << sum << endl;
system("pause");
return 0;
}
int main() {
int m,n,r;
do
{
cout << "input m,n" << endl;
cin >> m >> n;
} while (m <= 0 || n <0);
while((r=m%n)!=0){
m = n; n = r;
}
cout << "最大公约数为" << n << endl;
system("pause");
return 0;
}
int main() {
int k, m;
cin >> m;
for (k = 2; k < m; k++)
if (m % k == 0)
break;
if (k==m)
cout << m << "是素数" << endl;
else
cout << m << "不是素数" << endl;
system("pause");
return 0;
}
int main() {
cout << "\t九九乘法表" << endl;
for (int i = 1; i <= 9; i++) {
for (int j = 1; j <= i; j++)
cout << i << "x" << j << "=" << i * j << "\t";
cout << endl;
}
system("pause");
return 0;
}
int main() {
int k, m,number(0);
for(k=2;k<=100;k++)
{
for (m = 2; m < k; m++)
if (k % m == 0)
break;
if (k == m)
{
cout << m << "是素数" << "\t";
number++;
if (number%5==0)
cout << endl;
}
}
system("pause");
return 0;
}
int main() {
int i, k = 0;
float s[3], ave, sum=0;
for (i=0; i < 3; i++) {
cin >> s[i];
sum = sum + s[i];
}
ave = sum / 3;
for (i = 0; i < 3; i++)
if (s[i] > ave)
k++;
cout << "总成绩=" << sum <<"平均成绩="<<ave<< endl;
system("pause");
return 0;
}
int main() {
int i = 0, r, n, a[10];
char b[16] = { '0','1','3','4','5','6','7','8','9','A','B','C','D','E','F' };
cin >> n >> r;
do {
a[i] = n % r;
n = n / r;
i++;
} while (n != 0);
for (--i; i >= 0; --i) {
n = a[i];
cout << b[n];
}
system("pause");
return 0;
}
int main() {
int a[10], i, max;
for (i = 0; i < 10; i++) {
a[i] = rand() % 101;
cout << a[i] << endl;
}
max = a[0];
for (i = 1; i < 10; i++)
if (max<a[i])
max=a[i];
cout << "max=" << max << endl;
system("pause");
return 0;
}
int main() {
int arr[10],k,t,imax;
for (int i = 0; i < 10; i++) {
arr[i] = rand() % 101;
}
for (int j = 0; j < 10; j++)
{
imax = j;
for (int k = j + 1; k < 10; k++)
if (arr[k] > arr[imax])
imax = k;
t = arr[imax];
arr[imax] = arr[j];
arr[j] = t;
}
for (int h = 0; h < 10; h++)
{
cout << arr[h] << "\t";
}
cout << endl;
system("pause");
return 0;
}
int main() {
int arr[10],t;
for (int i = 0; i < 10; i++) {
arr[i] = rand() % 101;
}
for (int k=0; k < 9; k++) {
for (int j = 0; j < (9 - k); j++)
if (arr[j] >= arr[j + 1])
{
t = arr[j];
arr[j] = arr[j + 1];
arr[j + 1] = t;
}
}
for (int h = 0; h < 10; h++)
{
cout << arr[h] << "\t";
}
cout << endl;
system("pause");
return 0;
}
int main() {
int arr[10], t;
int x, f, post;
for (int i = 0; i < 10; i++) {
arr[i] = rand() % 101;
}
for (int k = 0; k < 9; k++) {
for (int j = 0; j < (9 - k); j++)
if (arr[j] >= arr[j + 1]){
t = arr[j];
arr[j] = arr[j + 1];
arr[j + 1] = t;
}
}
cout << "输入要插入的数据=";
cin >> x;
for (f = 0; f < 10; f++)
if (x < arr[f])
break;
post = f;
for (f = 9; f >= post; f--)
arr[f + 1] = arr[f];
arr[post] = x;
for (int h = 0; h < 11; h++)
{
cout << arr[h] << "\t";
}
cout << endl;
system("pause");
return 0;
}
int main() {
int arr[10],low(0), high(9),mid,x;
for (int i = 0; i < 10; i++) {
arr[i] = rand() % 101;
}
for (int k = 0; k < 9; k++) {
for (int j = 0; j < (9 - k); j++)
if (arr[j] >= arr[j + 1])
{
int t = arr[j];
arr[j] = arr[j + 1];
arr[j + 1] = t;
}
}
for (int h = 0; h < 10; h++)
{
cout << arr[h] << "\t";
}
cout << endl;
cout << "输入要查找的数据=";
cin >> x;
while (low<=high) {
mid = (low + high) / 2;
if (x == arr[mid])
break;
else if (x > arr[mid])
low = mid + 1;
else
high = mid - 1;
}
if (low > high)
cout << "没找到" << endl;
else
cout << "找到的数字下标为=" << mid << endl;
system("pause");
return 0;
}
int main() {
int arr[10][10];
for (int i = 0; i < 10; i++)
arr[i][0] = arr[i][i] = 1;
for (int i=2;i<10;i++)
for (int j=1;j<i;j++)
arr[i][j] = arr[i - 1][j - 1] + arr[i - 1][j];
for (int i = 0; i < 10; i++) {
for (int j = 0; j < i; j++)
cout << arr[i][j] << ' ';
cout << endl;
}
system("pause");
return 0;
}
int main() {
int e[4][4],N(4),M(8), MAX(9999),i, j, k, st, en, d;
for (i = 0; i < N; i++)
for (j=0; j < N; j++)
if (i==j)
e[i][j] = 0;
else
e[i][j]=MAX;
for (i = 1; i <= M; i++)
{
cin >> st >> en >> d;
e[st][en]=d;
}
for (k = 0; k < N; k++)
for (i = 0; i < N; i++)
for (j = 0; j < N; j++)
if (e[i][j] > e[i][k] + e[k][j])
e[i][j] = e[i][k] + e[k][j];
for (i = 0; i < N; i++)
{
for (j = 0; j < N; j++)
cout << (char)('A' + i) << "->" << (char)('A' + j) << ";" << e[i][j] << "\t";
cout << endl;
}
system("pause");
return 0;
}
int main() {
char s[100];
cin >> s;
cout << s << endl;
system("pause");
return 0;
}
int main() {
char s[100];
gets_s(s);
puts(s);
system("pause");
return 0;
}
int main() {
char s[10];
int i;
gets_s(s);
for (i = 0; s[i] != '\0'; i++)
if (s[i] >= 'a' && s[i] <= 'z')
s[i] = s[i] - 'a' + 'A';
puts(s);
system("pause");
return 0;
}
int main() {
int a[10],i, *p = a;
for (i = 0; i < 5; i++)
cin >> *p++;
for (i = 0; i < 5; i++)
cout << p[i] <<' ';
system("pause");
return 0;
}
int main() {
int a[3] = { 10,20,30 }, * p;
p = a;
cout << *p++ << endl;
cout << *p << endl;
system("pause");
return 0;
}
int main() {
int a[3] = { 10,20,30 }, * p;
p = a;
cout << ( * p)++ << endl;
cout << *p << endl;
system("pause");
return 0;
}
int main() {
char *p, *q;
p = new char[100];
gets(p);
q = p;
cout << "输入每个字符;";
while (*p!='\0')
cout << *P++ << ' ';
cout << "\n字符串长度;"<<p-q <<endl;
system("pause");
return 0;
}
float area(float x, float y, float z)
{
float c, s;
c = (x + y + z) / 2;
s = sqrt(c * (c - x) * (c - y) * (c - z));
return s;
}
int main() {
float a, b, c, d, e, f, g, s;
cin >> a >> b >> c >> d >> e >> f >> g >> s;
s = area(a, b, c) + area(c, d, e) + area(e, f, g);
cout << s << endl;
system("pause"); return 0;
}
void pic() {
for (int i=0;i<5;i++)
{
cout << setw(10 - i);
for (int j = 0; j < 2 * i + 1; j++)cout << "*";
cout << endl;
}
return;
}
int main() {
pic(); pic();
system("pause"); return 0;
}
bool drop(int n,int &sum) {
int x = n;
bool flag = 1;
while (n >= 10 && flag)
if (n / 10 % 10 < n % 10)
flag = 0; else n /= 10;
while (x)
{
sum += x % 10; x /= 10;
}
return flag;
}
int main() {
int m, sum1 = 0;
cin >> m;
if (drop(m, sum1))
cout << m << "___yes" << endl;
else
cout << m << "___no" << endl;
cout << "各位数之和;" << sum1 << endl;
}
void sort(int a[],int n) {
int i, j, k, w;
for (i = 0; i < n - 1; i++)
{
k = i;
for (j = i + 1; j < n; j++) if (a[k] < a[j])k = j;
if (i != k) { w = a[i]; a[i] = a[k]; a[k] = w; }
}
}
int Binary_Search(int low, int high, int key) {
if (low > high) return -1;
int mid = (low + high)/2;
if (key==a[mid])
return mid;
else if (key < a[mid])
return Binary_Search(low, mid -1,key);
else
return Binary_Search(mid + 1, high,key);
}
#define N 2
struct Student {
char name[10];
char no[7];
double Chinese, English, Math, avg;
};
int main() {
int i, j;
Student s[N], t;
for (i = 0; i < N; i++)
{
cin >> s[i].name >> s[i].no >> s[i].Chinese >> s[i].English >> s[i].Math;
s[i].avg = (s[i].Chinese + s[i].English + s[i].Math) / 3;
};
for(i=0;i<N-1;i++)
for(j=0;j<N-1-i;i++)
if (s[j].avg > s[j + 1].avg)
{
t = s[j];
s[j] = s[j + 1];
s[j + 1] = t;
}
for (i = 0; i < N; i++) {
cout << s[i].name << " " << s[i].no << " "<<s[i].Chinese << " ";
cout << s[i].English << " " << s[i].Math << " " << s[i].avg << endl;
}
system("pause");
return 0;
}
struct node* create(int n) {
struct node *head = NULL;
struct node *tail, *newnode;
for (int i = 0; i < n; i++)
{
newnode = new node;
cin >> newnode->data;
if (head == NULL)
head = newnode;
else
tail->next = newnode;
tail = newnode;
}
tail->next = NULL;
return(head);
}
void print(struct node, *head)
{
struct node *p = head;
while (p != NULL)
{
cout << p->data << "\t";
p = p->next;
}
}
void search(tructnode *head, int i){
int j = 1;
struct node* p = head;
if (i < 1)
cout << "illegal index\n";
else
{
while (j!=i&&p!=NULL)
{
j++;
p = p->next;
}
if (j == i && p != NULL)
cout << p->data;
else
cout << "illegal index \n";
}
}
int main() {
FILE *fp1, *fp2;
char ch;
fp1 = fopen("c:\\text.txt", "r");
if (fp1 == NULL)
{
cout << "can't open filel.txt"; exit(1);
}
if ((fp2 = fopen("c:\\texr2.txt", "w")) == NULL)
{
cout << "can't open file2"; fclose(fp1); exit(1);
}
while (!feof(fp1))
{
ch = fgetc(fp1);
putchar(ch);
if (ch >= '0' && ch <= '9')fputc(ch, fp2);
}
fclose(fp1); fclose(fp2);
system("pause");
return 0;
}
#define N 3
#include <iostream>
using namespace std;
struct student {
char name[20];
char num[8];
double score;
};
int main() {
struct student s[N], t[N];
int i;
FILE* fp;
if ((fp = fopen("student.dat", "wb")) == NULL)
{
cout << "can't open student.dat";
exit(1);
}
for (i = 0; i < N; i++)
{
cin >> s[i].name >> s[i].num >> s[i].score;
fwrite(&s[i], sizeof(student), 1, fp);
}
fclose(fp);
if ((fp = fopen("student.dat", "rb")) == NULL)
{
cout << "can't open student.dat";
exit(1);
}
fread(t, sizeof(t), 1, fp);
for (i = 0; i < N; i++)
cout << t[i].name << " " << t[i].num << " " << t[i].score << endl;
fclose(fp);
system("pause");
return 0;
}
class Circle {
private:
double x, y, r;
public:
void set(double x1, double y1, double r1)
{
x = x1; y = y1; r = r1;
}
void print() {
cout << "圆心;(" << x << "," << y << ")" << "半径:" << r << endl;
}
double gettarea() {
return 3.14 * r * r;
}
double getgirth()
{
return 2 * 3.14 * r;
}
};
int main() {
Circle c;
c.set(0, 0, 2);
c.print();
cout << c.gettarea() << endl;
cout << c.getgirth() << endl;
return 0;
}
class Time {
private:
int hour, minute, second;
public:
Time()
{}
Time(int h, int m, int s)
{
hour = h; minute = m; second = s;
}
void settime(int h, int m, int s)
{
hour = h; minute = m; second = s;
}
void print() const
{
cout << hour << ":" << minute << ":" << second << endl;
}
};
int main() {
int h, m, s;
Time t1;
const Time t2(10, 23, 34);
cin >> h >> m >> s;
t1.settime(h, m, s);
t1.print();
t2.print();
system("pause");
return 0;
}