当前位置:网站首页>C language programming (Third Edition)
C language programming (Third Edition)
2022-07-27 16:09:00 【std i hurt o love】
Catalog
11 page
Third question
(1)
#include<stdio.h>
int main()
{
int a_mxy,b,c;
printf(" Please enter the value of the two numbers to be exchanged :\n");
scanf("%d %d",&a_mxy,&b);
c=a_mxy;
a_mxy=b;
b=c;
printf(" The value after exchange is %d %d\n",a_mxy,b);
return 0;
}(2)
#include<stdio.h>
int main()
{
double s_mxy=0;
int i=0;
while(++i<=100)
{
s_mxy+=1.0/i;
}
printf(" Calculation results :%lf\n",s_mxy);
return 0;
}57 page
The first question is
#include<stdio.h>
int main()
{
double l1_mxy,l2,h;
printf(" Please enter trapezoidal upper bottom , Bottom , high :\n");
scanf("%lf %lf %lf",&l1_mxy,&l2,&h);
printf(" The area of the trapezoid is :%lf\n",(l1_mxy+l2)*h/2);
return 0;
}The second question is
#include<stdio.h>
int main()
{
double lenth_mxy,width,x;
printf(" Please enter the length and width of the rectangular lawn , And the speed of mowing the lawn x:\n");
scanf("%lf %lf %lf",&lenth_mxy,&width,&x);
printf(" The time required for mowing the lawn is :%lf\n",lenth_mxy*width/x);
return 0;
}Third question
#define PI 3.14
#include<stdio.h>
int main()
{
double r_mxy,h;
printf(" Please enter the radius and height of the cylinder :\n",&r_mxy,&h);
scanf("%lf %lf",&r_mxy,&h);
printf(" The volume of the cylinder is :%lf, The surface area of the cylinder is :%lf\n",PI*r_mxy*r_mxy*h,2*PI*r_mxy*(h+r_mxy));
return 0;
}Fourth question
#include<stdio.h>
#include<math.h>
int main()
{
double x1_mxy,y1,x2,y2;
printf(" Please enter the coordinates of two points :\n");
scanf("%lf %lf %lf %lf",&x1_mxy,&y1,&x2,&y2);
printf(" The distance between two points is :%lf\n",sqrt((x1_mxy-x2)*(x1_mxy-x2)+(y1-y2)*(y1-y2)));
return 0;
}Fifth question
#include<stdio.h>
int main()
{
float B_mxy,S,P,T;
printf(" Please enter the basic salary , Basic turnover of this month , Percentage of turnover Commission :\n");
scanf("%f %f %f",&B_mxy,&S,&P);
T=B_mxy+S*P;
printf(" The actual salary is :%f\n",T);
return 0;
}Sixth question
#include<stdio.h>
int main()
{
int n_mxy,sum=0;
printf(" Please enter a number :\n");
scanf("%d",&n_mxy);
while(n_mxy)
{
sum+=n_mxy%10;
n_mxy/=10;
}
printf(" The sum of digits is :%d\n",sum);
return 0;
}Question seven
#include<stdio.h>
int main()
{
double A1_mxy,B1,C1,A2,B2,C2,x,y;
printf(" Please enter the coefficient constant :\n");
scanf("%lf %lf %lf %lf %lf %lf",&A1_mxy,&B1,&C1,&A2,&B2,&C2);
x=(C1*B2-C2*B1)/(A1_mxy*B2-A2*B1);
y=(C1*A2-C2*A1_mxy)/(B1*A2-B2*A1_mxy);
printf(" Explain x=%lf,y=%lf\n",x,y);
return 0;
}95 page
The first question is
#include<stdio.h>
int main()
{
double x_mxy,y;
printf(" Please enter x Value \n");
scanf("%lf",&x_mxy);
if(x_mxy<0)
y=2*x_mxy-1;
else if(x_mxy<10)
y=2*x_mxy+10;
else if(x_mxy<100)
y=2*x_mxy+100;
else
y=x_mxy*x_mxy;
printf("y=%lf\n",y);
return 0;
}The second question is
#include<stdio.h>
int Judge(int n)
{
if(n%6&&n%9&&n%14)
return 0;
else
return 1;
}
int main()
{
int n_mxy;
printf(" Please enter a number :\n");
scanf("%d",&n_mxy);
if(Judge(n_mxy))
printf("%d Can be 6、9、14 to be divisible by \n",n_mxy);
else
printf("%d Can not be 6、9、14 to be divisible by \n",n_mxy);
return 0;
}Third question
#include<stdio.h>
int Judge(int n)
{
if(n==n%100)
return 1;
else
return 0;
}
int main()
{
int m_mxy;
printf(" Please enter a number :\n");
scanf("%d",&m_mxy);
if(Judge(m_mxy))
printf("%d Shou form number \n",m_mxy);
else
printf("%d Not conformal number \n",m_mxy);
return 0;
}Fourth question
#inclue<stdio.h>
int main()
{
int dB_mxy;
printf(" Please enter a value in decibels :\n");
scanf("%d",&dB_mxy);
if(dB_mxy<=50)
printf(" quiet \n");
else if(dB_mxy<=70)
printf(" Make a noise , Harmful to nerves \n");
else if(dB_mxy<=90)
printf(" Very noisy. , Nerve cells are destroyed \n");
else if(dB_mxy<=100)
printf(" The noise intensified , Hearing loss \n");
else if(dB_mxy<=120)
printf(" Unbearable , Take one minute to temporarily deafen \n");
else
printf(" Extremely deaf or totally deaf \n");
return 0;
}Fifth question
#include<stdio.h>
int getprice(int a,int b)
{
int tnum,sump=0;
if(a&&b)
{
if(a>b)
{
tnum=b;
if(tnum<50)
sump+=tnum*90+(a-tnum)*60;
else
sump+=tnum*80+(a-tnum)*60;
}
else
{
tnum=a;
if(tnum<50)
sump+=tnum*90+(b-tnum)*45;
else
sump+=tnum*80+(b-tnum)*45;
}
}
else
{
if(a)
sump=a*60;
else
sump=b*60;
}
return sump;
}
int main()
{
int a_mxy,b;
printf(" Please enter the number of tops and bottoms purchased :\n");
scanf("%d %d",&a_mxy,&b);
printf(" The total amount of collection is %d\n",getprice(a_mxy,b));
return 0;
}Sixth question
#include<stdio.h>
#include<math.h>
double getY(double a,double b)
{
double Y;
if(a>0)
{
if(b>0)
Y=cos(a)+cos(b);
else
Y=sin(a)+sin(b);
}
else
{
if(b>0)
Y=cos(a)+sin(b);
else
Y=sin(a)+cos(b);
}
return Y;
}
int main()
{
double a_mxy,b,Y;
printf(" Please enter a,b Value \n");
scanf("%lf %lf",&a_mxy,&b);
Y=getY(a_mxy,b);
printf("Y The value of is %lf\n",Y);
return 0;
}Question seven
#include<stdio.h>
int main()
{
double p_mxy,w,s,d,f;
printf(" Please enter the basic freight , The weight of the goods , distance :\n");
scanf("%lf %lf %lf",&p_mxy,&w,&s);
if(s<250)
d=0;
else if(s<500)
d=0.02;
else if(s<1000)
d=0.05;
else if(s<2000)
d=0.08;
else if(s<3000)
d=0.1;
else
d=0.15;
f=p_mxy*w*s*(1-d);
printf(" The total freight is %lf\n",f);
return 0;
}122 page
The first question is
#include<stdio.h>
int main()
{
int x=1,sum=0;
for(x=1;x<=20;x++)
sum+=2*x*x+3*x+1;
printf(" The result is %d\n",sum);
return 0;
}The second question is
#include<stdio.h>
int main()
{
int n,i=1;
double sum=0;
printf(" Please enter n Value (n<=1600):\n");
scanf("%d",&n);
for(i=1;i<=n;i++)
sum+=(double)(4*i*i)/(2*i-1)*(2*i+1);
printf(" The result is :%lf\n",sum);
return 0;
}Third question
#include<stdio.h>
double getmoney(double t,double r,int n)
{
while(n--)
{
t=t*(1+r);
}
return t;
}
int main()
{
double t,r;
int n;
printf(" Please enter the principal , The interest rate , Deposit years :\n");
scanf("%lf %lf %d",&t,&r,&n);
printf(" The principal and interest are :%lf\n",getmoney(t,r,n));
return 0;
}Fourth question
#include<stdio.h>
int Isyear(int n)
{
if(n%4==0&&n%100||n%400==0)
return 1;
else
return 0;
}
int main()
{
int i=1;
for(i=1;i<=10000;i++)
{
if(Isyear(i))
printf("%-5d",i);
}
return 0;
}Fifth question
#include<stdio.h>
int main()
{
int i=1,n=20,s=2;
double sum=0;
while(n--)
{
sum+=(double)s/i;
s+=i;
i=s-i;
}
printf(" The result is :%lf\n",sum);
return 0;
}Sixth question
#include<stdio.h>
int main()
{
int i=1;
double sum=0,ret=1;
while(ret>1.0E-6)
{
ret=1.0/(i*i+1);
sum+=ret;
i++;
}
printf(" The result is :%lf\n",sum);
return 0;
}Question seven
#include<stdio.h>
int main()
{
int i=1;
double sum=0,ret=1;
while(ret>1.0E-6)
{
ret=1.0/i;
sum+=ret;
i+=i+1;
}
printf(" The result is :%lf\n",sum);
return 0;
}The eighth question
#include<stdio.h>
int main()
{
int count=0;
double n=14,r=0.008;
while(n<26)
{
n=n*(1+r);
count++;
}
printf(" need %d reach 26 Billion \n",count);
return 0;
}Question 9
#include<stdio.h>
int main()
{
double temp=1,ret=1,sum=1,i=1;
while(temp>1.0E-5)
{
temp=1.0/ret;
sum+=temp;
i++;
ret*=i;
}
printf(" The result is :%lf\n",sum);
return 0;
}Question 10
#include<stdio.h>
int main()
{
int n=1,sum=0,ret=1;
while(n++<=20)
{
sum+=ret;
ret*=n;
}
printf(" The result is :%d\n",sum);
return 0;
}Eleventh questions
#include<stdio.h>
#include<math.h>
int wfnum(int n)
{
int sum=0,ret=n;
while(ret)
{
sum+=(int)pow(ret%10,3.0);
ret/=10;
}
if(sum==n)
return 1;
else
return 0;
}
int main()
{
int i=100;
for(i=100;i<1000;i++)
{
if(wfnum(i))
printf("%d ",i);
}
return 0;
}Twelfth questions
#include<stdio.h>
int Istnum(long long n)// Here, you can use string to find the number of hands of any bit
{
int i = 0;
while (n / pow(10, i) >= 10)
{
i++;
}
if (n == pow(n%pow(10, i)), 2)
return 1;
else
return 0;
}
int main()
{
long long n;
printf(" Please enter a number :\n");
scanf("%lld", &n);
if (Istnum(n))
printf("%lld Shou form number \n",n);
else
printf("%lld Not conformal number \n");
return 0;
}Thirteenth questions
#include<stdio.h>
long long Snum(long long a, int n)
{
long long sum = 0,ret = a;
while (n--)
{
sum += a;
a = a * 10 + ret;
}
return sum;
}
int main()
{
long long a;
int n;
printf(" Please enter a and n\n");
scanf("%lld %d", &a, &n);
printf(" The result is %lld\n", Snum(a, n));
return 0;
}Fourteenth questions
#include<stdio.h>
int Comnum(int n)
{
int sum = 0, i = 0;
while (sum != n)
{
sum += ++i;
if (sum > n)
return 0;
}
return 1;
}
int main()
{
int i = 1;
for (i = 1; i <= 1000; i++)
{
if (Comnum(i))
printf("%d ", i);
}
return 0;
}Question 15
#include<stdio.h>
int main()
{
int grade = 0, c_1 = 0, c_2 = 0, c_3 = 0, c_4 = 0, c_5=0, n = 20;
printf(" Please enter 20 Achievements \n");
while (scanf("%d", &grade) && n--)
{
if (grade >= 90)
c_1++;
else if (grade >= 80)
c_2++;
else if (grade >= 70)
c_3++;
else if (grade >= 60)
c_4++;
else
c_5++;
}
printf("90 The number of people with more than points is :%d,80~89 For the :%d,70~79 For the :%d,60~69 For the :%d, Less than 60 Divided into :%d\n", c_1, c_2, c_3, c_4, c_5);
return 0;
}Sixteen
#include<stdio.h>
int main()
{
int count = 0, grade;
double sum = 0;
printf(" Please enter the grade \n");
while (scanf("%d", &grade) && grade != -99)
{
count++;
sum += grade;
}
printf(" The average student grade is :%lf\n",sum/count);
return 0;
}Seventeen
#include<stdio.h>
int Dtnum(int m, int n)
{
int i = 1, sum = 0;
for (i = 1; i <= n; i++)
{
if (m%i == 0 && n%i == 0)
sum += i;
}
return sum;
}
int main()
{
int m, n;
printf(" Please enter two numbers :\n");
scanf("%d %d", &m, &n);
printf(" The sum of the common divisors is :%d\n", Dtnum(m, n));
return 0;
}Question 18
#include<stdio.h>
int main()
{
int boy, girl, child;
for (boy = 0; boy < 10; boy++)
{
for (girl = 0; girl < 13; girl++)
{
for (child = 0; child < 37; child++)
{
if (4 * boy + 3 * girl+child ==36&& boy + girl + child == 36)
printf(" Need a man %d people , Woman %d people , pediatric %d people .\n", boy, girl, child);
}
}
}
}Question 19
#include<stdio.h>
int main()
{
int x, y, z;
for (x = 1; x <= 600; x++)
{
for (y = x + 1; y <= 800; y++)
{
for (z = y + 1; z <= 1000; z++)
{
if (x*x + y * y == z * z)
printf(" A set of Pythagorean numbers :%d %d %d\n", x, y, z);
}
}
}
}Twenty questions
#include<stdio.h>
#include<math.h>
double calu(double n)
{
double sum=1;
while(n)
{
sum*=n;
n--;
}
return sum;
}
double f(double n,double x)
{
return pow(-1.0,n-1)*pow(x,2*n-1)/calu(2*n-1);
}
double Mysin(double x)
{
double sum=0,ret=x;
double i=1;
while(fabs(ret)>1.0E-5)
{
ret=f(i,x);
sum+=ret;
i++;
}
return sum;
}
int main()
{
double x;
printf(" Please enter x Value :\n");
scanf("%lf",&x);
printf("Mysin(%lf)=%lf\n",x,Mysin(x));
return 0;
}Twenty one questions
#include<stdio.h>
int Fibonacci(int n)
{
if(n==1||n==2)
return 1;
else
return Fibonacci(n-1)+Fibonacci(n-2);
}
int main()
{
int n;
printf(" Please enter n Value :\n");
scanf("%d",&n);
printf(" Fibonacci number one %d Item is :%d\n",n,Fibonacci(n));
return 0;
}Question 22
#include<stdio.h>
double p(int n,int x)
{
if(n==0)
return 1;
else if(n==1)
return x;
else
return (2*n-1)*x-p(n-1,x)-(n-1)*p(n-2,x)/n;
}
int main()
{
int n,x;
printf(" Please enter n,x Value \n");
scanf("%d %d",&n,&x);
printf(" The result is :%lf\n",p(n,x));
return 0;
}166 page
The first question is
#include<stdio.h>
#include<string.h>
#include<ctype.h>
int main()
{
char a[100];
printf(" Please enter the string \n");
gets(a);
int bc = 0, sc = 0, digit = 0, len = strlen(a), i;
for (i = 0; i < len; i++)
{
if (isupper(a[i]))
bc++;
if (islower(a[i]))
sc++;
if (isdigit(a[i]))
digit++;
}
printf(" Capital %d individual , Lowercase letters %d individual , Numbers %d individual \n", bc, sc, digit);
return 0;
}The second question is
#include<stdio.h>
#include<string.h>
#include<ctype.h>
int main()
{
char str1[100], str2[100];
printf(" Please enter the string \n");
gets(str2);
int i, j = 0;
for (i = 0; i < strlen(str2); i++)
{
if (islower(str2[i]))
str1[j++] = str2[i];
}
str1[j] = '\0';
printf("%s\n", str1);
}Third question
#include<stdio.h>
#include<string.h>
int _upr_len(char str[])
{
int count = 0, i;
for (i = 0; i < strlen(str); i++)
{
if (str[i] >= 'A'&&str[i] <= 'Z')
count++;
}
}
int main()
{
char a[100];
printf(" Please enter the string \n");
gets(s);
printf(" The number of capital letters is :%d\n", _upr_len(a));
return 0;
}Fourth question
#include<stdio.h>
#include<string.h>
#include<ctype.h>
void fun(char*s)
{
int i;
for (i = 0; i < strlen(s); i++)
{
if(isupper(s[i]))
s[i]=tolower(s[i]);
else if (islower(s[i]))
s[i]=toupper(s[i]);
}
}
int main()
{
char a[100];
printf(" Please enter the string \n");
gets(a);
fun(a);
printf(" Converted String \n");
printf("%s",a);
return 0;
}Fifth question
#include<stdio.h>
#include<string.h>
void str_inv(char*s)
{
int i = 0, len = strlen(s);
while (i < len/2)
{
char ret = s[i];
s[i] = s[len - i-1];
s[len - i-1] = ret;
i++;
}
}
int main()
{
char a[100];
printf(" Please enter the string \n");
gets(a);
str_inv(a);
printf(" The string in reverse order \n");
printf("%s", a);
return 0;
}Sixth question
#include<stdio.h>
#include<string.h>
int str_cmp(char s1[], char s2[])
{
while (*s1++==*s2++&&*s1!='\0'&&*s2!='\0')
{
;
}
return *s1 - *s2;
}
int main()
{
int s1[100], s2[100];
printf(" Please enter the string s1\n");
gets(s1);
printf(" Please enter the string s2\n");
gets(s2);
if (!str_cmp(s1, s2))
printf(" Two strings are equal \n");
else
printf(" Two strings are not equal \n");
return 0;
}Question seven
#include<stdio.h>
#include<string.h>
void replace(char s[], char c1, char c2)
{
int i;
for (i = 0; i < strlen(s); i++)
{
if (s[i] == c1)
s[i] = c2;
}
}
int main()
{
char s[100], c1, c2;
printf(" Please enter the string \n");
gets(s);
printf(" Please enter the replaced character \n");
scanf("%c", &c1);
printf(" Please enter replacement characters \n");
getchar();
scanf("%c", &c2);
replace(s, c1, c2);
printf(" Replaced string \n");
printf("%s", s);
return 0;
}
The eighth question
#include<stdio.h>
#include<string.h>
#include<ctype.h>
void str_encrypt(char str[])
{
int i;
for (i =0; i < strlen(str); i++)
{
if (isupper(str[i]))
{
if (isalpha(str[i] + 4))
str[i] += 4;
else
str[i] = 'D' - 'Z' + str[i];
}
else if (islower(str[i]))
{
if(isalpha(str[i] + 4))
str[i] += 4;
else
str[i] = 'd' - 'z' + str[i];
}
}
}
int main()
{
char s[100];
printf(" Please enter the string \n");
gets(s);
str_encrypt(s);
printf(" The encrypted string \n");
printf("%s", s);
return 0;
}边栏推荐
- 单机高并发模型设计
- 2.2 JMeter基本元件
- Breaking through soft and hard barriers, Xilinx releases Vitis unified software platform for developers
- [sword finger offer] interview question 39: numbers that appear more than half of the time in the array
- Flask连接mysql数据库已有表
- Mlx90640 infrared thermal imager temperature sensor module development notes (VII)
- 初识MySQL数据库
- 测试新手学习宝典(有思路有想法)
- Penetration test - dry goods | 80 + network security interview experience post (interview)
- 快速高效删除node_modules
猜你喜欢

flume增量采集mysql数据到kafka

centos上mysql5.7主从热备设置

解决MT7620不断循环uboot(LZMA ERROR 1 - must RESET board to recover)

Text capture picture (Wallpaper of Nezha's demon child coming to the world)

测试新手学习宝典(有思路有想法)

判断数据的精确类型
![[sword finger offer] interview question 45: arrange the array into the smallest number](/img/d1/e2e21c95ecf5b8e3854f134cc47228.png)
[sword finger offer] interview question 45: arrange the array into the smallest number

Addition, deletion, query and modification of MySQL table data

解决flink启动后无法正常关闭

Clickhouse 20.x distributed table testing and chproxy deployment (II)
随机推荐
Vant UI toast and dialog use
Network principle (1) - overview of basic principles
[regular expression] matches multiple characters
openwrt 编译驱动模块(在openwrt源代码外部任意位置编写代码,独立模块化编译.ko)
无线网络分析有关的安全软件(aircrack-ng)
[sword finger offer] interview question 53-i: find the number 1 in the sorted array -- three templates for binary search
drf使用:get请求获取数据(小例子)
Hematemesis finishing c some commonly used help classes
Division of entity classes (VO, do, dto)
突发!海康/大华/商汤/旷视/依图/科大讯飞等28家中国实体被美列入黑名单
移动端h5常见问题
Have you ever used the comma operator?
使用transform:translate()出现内容模糊问题
项目优化个人感悟
编码技巧——全局日志开关
Constraints, design and joint query of data table -- 8000 word strategy + Exercise answers
Openwrt增加对 sd card 支持
解决flink启动后无法正常关闭
: 0xc0000005: an access conflict occurs when writing position 0x01458000 - to be solved
Openwrt new platform compilation