急求解两道不难的C语言编程题目

作者&投稿:城岚 (若有异议请与网页底部的电邮联系)
两道C语言编程题,求解~

1
#include "stdio.h"
int main()
{
int m,l;
double r=1.0;
printf("please input m: ");
scanf("%d",&m);
for(l=2;l<=m;l++)
{
r=r-(1.0/(l*l));
}
printf("
t=%f
",r);
return 0;
}

2:
#include "stdio.h"
int main()
{
int l1,l2;
int matrix[4][4];

int diagonal[4];

for(l1=0;l1<4;l1++)//输入
for(l2=0;l2<4;l2++)
{
printf("
please input Row %d Column %d: ",l1,l2);
scanf("%d",matrix[l1]+l2);
}
printf("
main diagonal is:
");
for(l1=0;l1<4;l1++)//取主对角线上的数
{
diagonal[l1]=matrix[l1][l1];
}

for(l1=0;l1<3;l1++)//排序
for(l2=l1+1;l2<4;l2++)
{
if(diagonal[l2]<diagonal[l1])
{
diagonal[l2]=diagonal[l2]^diagonal[l1];
diagonal[l1]=diagonal[l2]^diagonal[l1];
diagonal[l2]=diagonal[l2]^diagonal[l1];

}
}
for(l1=0;l1<4;l1++)//输出
{
printf("%d",diagonal[l1]);
}

printf("
");
return 0;
}

4:
#include "stdio.h"

void main()
{

int cocks,hens,chicks;
printf("-----------------------------------
");
printf("cocks hens chicks
");
printf("-----------------------------------
");
for(cocks=0;cocks<21;cocks++)
for(hens=0;hens<33;hens++) {
chicks=100-cocks-hens;
if((5*cocks+3*hens+hens/3==100)&&(hens%3==0))
printf("%-2d%-2d%-2d
",cocks,hens,chicks);
}
printf("-----------------------------------
");
}
5:
#include "stdio.h"
#define N 100

void main()
{
int array[N],n,i,j;
int a=0,b=0,c=0,d=0;
int max,min,temp1,temp2;
printf("请输入学生数
");
scanf("%d",&n);
for(i=0;i<n;i++) {
printf("输入第%d个学生的分数",i+1);
scanf("%d",&array[i]);
}
for(min=max=array[0],i=0;i<n;i++) {
if(max<array[i]) max=array[i];
if(min>array[i]) min=array[i];
}
for(i=0,j=0;i<n;i++) {
if(max<=array[i]) j++;
}
printf("第一的分数%d有%d人
",max,j);
for(i=0,j=0,temp1=min;i<n;i++) {
if(temp1<array[i])
if(array[i]!=max) temp1=array[i],j++;
}
printf("第二的分数%d有%d人
",temp1,j);
for(i=0,j=0,temp2=min;i<n;i++) {
if(temp2<array[i])
if(array[i]!=max)
if(array[i]!=temp1) temp2=array[i], j++;
}
printf("第三的分数%d有%d人
",temp2,j);
for(i=0;i<n;i++) {
if((array[i]>=90)&&(array[i]<=100)) a++;
if((array[i]>=75)&&(array[i]<=89)) b++;
if((array[i]>=60)&&(array[i]<=74)) c++;
if((array[i]>=0)&&(array[i]<60)) d++;
}
printf("成绩为优的百分率为:%f%
",(a/1.0/n*100));
printf("成绩为良的百分率为:%f%
",(b/1.0/n*100));
printf("成绩为中的百分率为:%f%
",(c/1.0/n*100));
printf("成绩为不及格的百分率为:%f%
",(d/1.0/n*100));
}

1
#include <stdio.h>
#include <malloc.h>

int *g_n;
int g_num;

void output()
{
int i=1;
if (g_n[0] != g_num)
{
printf("%d = %d", g_num, g_n[0]);
while(g_n[i]!=0 && i<g_num)
printf(" + %d", g_n[i++]);
printf("\n");
}
}

void decompose(int num, int *n, int max)
{
int i;

if (num<=max)
{
n[0] = num;
output();
}

for (i=(max<num? max: num-1); i>0; i--)
{
n[0] = i;
decompose(num - i, &n[1], i);
}

n[0] = 0;
}

int main()
{
int i;

printf("Please input a integer: ");
scanf("%d", &g_num);

g_n = (int*)malloc(sizeof(int) * g_num);

if (g_n)
{
for (i=0; i<g_num; i++) g_n[i] = 0;

decompose(g_num, g_n, g_num);

free(g_n);
}
else
{
printf("Out memory\n");
}

return 0;
}

http://zhidao.baidu.com/question/53075196.html

判断字符串是否是回文
#include <stdio.h>
#include <string.h>
void main()
{
char str[100],temp[100];
printf("输入字符串:");
scanf("%s",str);

strcpy(temp,str);
strrev(temp);//将字符串反转后比较
if(strcmp(temp,str)==0)
printf("是回文.\n");
else printf("不是回文.\n");

}


我有两道c语言题要做,应该不难,请各位大神帮忙
一、下面是C语言实现以上四个功能的代码,函数包括 find_max、average、greater_than_average 和 sort,具体细节可以查看注释:include <stdio.h> void find_max(int arr[], int len, int *max) { \/\/ 找出数组中的最大数 max = arr[];for (int i = 1; i < len; i++) { if (arr[...

c语音,初学者求解两道简单的题目,尽量详细点~
第一个题目应该这样理解,首先a是一个二维数组,第一维可以认为为指针,指向字符串(或字符数组),Teacher按道理后面应该有个\\0,不过这个在初始赋值时应该被覆盖了,而且变成连续的了,其长度若按字符串(strlen)理解确实大于7(为10),按数组理解当然不能超过7了,但是打印的时候是按字符串打印的。

我刚刚学C语言.求解两道题.
} 第二题:#include<iostream.h> define n 3 \/\/这个宏定义可以实现任意数量的浮点数排序 只要你改动n的值就可以了 void sort(float a[n]);void main(){ float a[n];cout<<"请依次输入三个浮点数:"<<endl;for(int i=0;i<n;i++){ cin>>a[i];} sort(a);} void sort(float a...

问两道简单的C语言题
for(int b=0;b<30-a;b++){ if(a*2+b*4==90){ System.out.println(a+"只鸡,"+b+"只兔");} } } } }

初学者请教 两道简单的c语言编程题目
1. 用C语言自己的时间函数 difftime(time_t time1, time_t time0) \/ 86400 这样做得缺点是,这里的time_t类型,只支持到2037年 2. 自己定义函数 楼主用的方法,在实际编程里不常用,变化比较大。下面这个方法是直接计算两个日期到公元元年的天数 然后相减,这个是实际编程时的算法,经过很多程...

C语言两道小题
func((x--,y++,x+y),z--)语句里(x--,y++,x+y)是个逗号表达示,每一条都会运算,但结果只取最后一条:X先-1得5,Y再+1得8,最后 x+y=((x-1)+(y-1))=((6-1)+(7+1))=13 所以括号内的最终值是13,就有func(13,8)给传递过去得结果 13+8=21(被输出)第二题就是个纯粹...

两道C语言的题,求解(高分)
void main(){ float x,y,s,c;printf("请输入两个浮点数: ");scanf("%f%f",&x,&y);s=he(x,y);c=cha(x,y);printf("两个浮点数的和值是%.2f\\n",s);printf("两个浮点数的差值是%.2f\\n",c);} float he(float a,float b){ return a+b;} float cha(float a,float b){...

c语言2道选择题求解!最好复解析,方便理解!~
每行2个数字,所以,A、B都不对。输出是i+j,所以每行第一个数字是从大到小,每行第二个数字比第一个数字大1.所以C是错的 2选B I=1,输出第一行,i=2是输出第二行 所以 c是错的 j是从i开始,所以第一行第一个应该是1*1 ...,第二行第一个应该是2*2,A、D都是错的 ...

帮看看两道c语言编程题目吧,或者直接给翻译一下也行。。
交换加数的等式不算。比如集合{1, 2, 3}有一个加法等式1 + 2 = 3,其中1,2,3都是该集合的元素,符合要求(2 + 1 = 3不算)。有的集合可能找不到加法等式,比如{1, 2, 5}。有的集合可能有多个加法等式,比如{1, 2, 3, 5, 6}有4个:1 + 2 = 3, 2 + 3 = 5, 1 + ...

C语言程序两道题目
for(;a>b;++b)i++;没有初始条件,当a=b时结束循环,a与b之间相差5,因此会执行5次循环,也就是i有5次自加1的机会,因此i=5,因为在for语句中++b和a>b属于不同两条语句,因此++b的自增和b++的自增效果是一样的。while(a>++c)j++;当a大于C时结束循环,在此语句中++c和判断语句在...

内江市15834114691: 有两道C语言编程题,不难,求答案!!!!!!!
骑伯尼为: #include<stdio.h>int main(){ float x; scanf("%f",&x); if( x < 1) printf("-1"); else if(x >=1 && x <= 10) printf("%f",2*x + 1); else printf("%f",3*x + 2); return 0;} 第二题题意不明啊

内江市15834114691: 两道简单的C语言程序题,请那个大侠赐教,谢谢了!!
骑伯尼为: 1. #include <stdio.h> #include <stdlib.h> int main() { char c; char data[100]; int index=0,i; while((c=getchar())!='\n') { if(c>='A'&&c<='Z') data[index++]=c; if(c>='a'&&c<='z') { c-=32; data[index++]=c; } } while(index--) { printf("%c",data[index]); } printf(...

内江市15834114691: 两道非常简单的编程题(C语言)!!
骑伯尼为: 这俩题与其说是C语言题 不如说是数学题了 第一道题很著名 当n无穷大时候 S = ln(n) + c c是欧拉常数 C语言的话 #include <cstdlib> #include <iostream> #include <iomanip> using namespace std; int main() { double result = 0; int n; cin >> n; for (...

内江市15834114691: 两道简单的C语言题目 -
骑伯尼为: 一、首先分析这段函数实现的功能 main() {int op1,op2,res; char opertor; scanf ("%d",&op1); //op1为输入的整数 opertor=getchar(); //opertor为输入的字符 while(opertor!='=') //如果输入的字符不是'='则继续 { scanf ("%d",&op2); //op2 为输...

内江市15834114691: 急!急!急!急!两道C语言程序题,请大家赐教,谢谢了!! -
骑伯尼为: 1. #include void main() { int i,j,n...

内江市15834114691: 我有两道c语言题要做,应该不难,请各位大神帮忙
骑伯尼为: #include &lt;stdio.h&gt; #define ARRAY_SIZE 10 int Find_max(int * array) { int i; int ret; ret = array[0]; for(i=1; i&lt;ARRAY_SIZE; i++) if(array[i] &gt; ret) ret = array[i]; return ret; } float Calculate_average(int * array) { int i = 0; float average = 0; int sum = ...

内江市15834114691: 求解一道简单的C语言C程序C编程题 -
骑伯尼为: 题目没说清.1.输入仅限于小写字母还是所有字符;2 y,z输出a,b还是也按ASCII码向后推两位.#include <stdio.h>#include <string.h> int main() { char iword; char oword; while(iword = getchar()) { if(iword == '\n') break; oword = (iword - 95) % 26 + 97; printf("%c",oword); } printf("\n"); return 0; } 输入:abcdefxyz 输出:cdefghzab 此程序仅限输入小写字母.

内江市15834114691: 帮忙C语言编程两道很简短的题
骑伯尼为: 1.#include<stdio.h>void main(void) {int *x,*y;*x=3;*y=4;*(y+1)=*x;*x=*y;*y=*(y+1); } 2. #include<stdio.h> void main(void) {int i;for(i=201;i<=300;i++){if(i%3==0){printf("%d\n",i);}} }

内江市15834114691: 求解2道简单的C语言程序
骑伯尼为: 第一道题:输出所有4位数中有2位数字相同的值,并统计出个数.#include<stdio.h>void main(){ int i; int ge; int shi; int bai; int qian; int shen; int count=0; for(i=1000;i<10000;i++) { ge=i%10; shen=i/10; shi=shen%10; shen=shen/10; bai=shen%10; ...

内江市15834114691: 求解下面两道C语言编程题,最好有注释 -
骑伯尼为: #include "stdio.h"void fun(char ch[],char reverse[]){ static int i=0; if(*ch!='\0') { fun(++ch,reverse); reverse[i]=*(ch-1); i...

本站内容来自于网友发表,不代表本站立场,仅表示其个人看法,不对其真实性、正确性、有效性作任何的担保
相关事宜请发邮件给我们
© 星空见康网