㈠ 求助各位c语言编程高手~帮我做3道题~
#include<stdio.h>
#include<string.h>
#defineN4
/*-----------------------------------------
第一题
-------------------------------------------*/
voidDiamond(constchar*s,intn,intlen)
{
printf("%*s%-s\n",len,s+n-1,s+n);
if(n>1)
Diamond(s,n-1,len);
printf("%*s%-s\n",len,s+n,n==len?s+n:s+n+1);
}
/*-----------------------------------------
第二题
-------------------------------------------*/
typedefstruct
{
intgcd;
intlcm;
}pair;
voidGCD_LCM(inta,intb,pair*p)
{
inttmp;
intproct=a*b;
while(b%a)
{
tmp=a;
a=b%a;
b=tmp;
}
p->gcd=a;
p->lcm=proct/a;
}
/*-----------------------------------------
第三题
-------------------------------------------*/
voidSwap(int*lhs,int*rhs)
{
inttmp=*lhs;
*lhs=*rhs;
*rhs=tmp;
}
voidBubbleSort(int*beg,int*end)
{
for(;beg!=end;++beg)
for(int*p=end-1;p!=beg;--p)
if(*p<*(p-1))
Swap(p,p-1);
}
voidSelectSort(int*beg,int*end)
{
for(;beg!=end;++beg)
{
int*max=beg;
for(int*p=beg+1;p!=end;++p)
if(*max<*p)
max=p;
Swap(beg,max);
}
}
voidPrint(int*beg,int*end)
{
while(beg!=end)
printf("%d",*beg++);
putchar('\n');
}
intmain()
{
/*一*/
charpt[N+1]={0};
memset(pt,'*',N);
Diamond(pt,N,N);
/*二*/
pairp;
GCD_LCM(3,6,&p);
printf("%d%d\n",p.gcd,p.lcm);
/*三*/
inta[]={32,9,45,22,15,48,47,8,55,1};
Print(a,a+10);
BubbleSort(a,a+10);
Print(a,a+10);
SelectSort(a,a+10);
Print(a,a+10);
}
㈡ 求三道编程题 用初级C语言编写 初级的啊 谢谢0.0
/*3个问题都在下面这个小程序里解决*/
#include <stdio.h>
char cch(char c)
{
if(c>='A'&&c<='Z')
return c+('a'-'A');
if(c>='a'&&c<='z')
return c-('a'-'A');
}
int mstrl(char* str)
{
char *ps=str;
while(*(ps++)){};
return ps-str-1;
}
void sortstr(char* str)
{
char tch;
int i,j;
int len=mstrl(str);
for(i=0;i<len;i++)
{
for(j=i+1;j<len;j++)
{
if(str[i]>str[j])
{
tch=str[i];
str[i]=str[j];
str[j]=tch;
}
}
}
}
int main()
{
char c;
char str[100];
printf("输入一个字符:");
scanf("%c",&c);
printf("转换后:%c\n",cch(c));
printf("输入一个字符串:");
getchar();
scanf("%s",str);
printf("字符串长度为: %d\n",mstrl(str));
sortstr(str);
printf("升序排列:%s\n",str);
return 0;
}
输入一个字符:A
转换后:a
输入一个字符串:bcwPASDkds
字符串长度为: 10
升序排列:ADPSbcdksw
请按任意键继续. . .
㈢ 问3道C语言编程题目
1.#include<stdio.h>
int main(){
int a[3]={1,2,3},b[3]={4,5,6},c[3];
for(int i=0;i<3;i++){
c[i]=a[i]+b[i];
printf("%-2d",c[i]);
}
return 0;
}
2.#include<stdio.h>
int main(){
int a[10],i,j=0,max;
for(i=0;i<10;i++){
scanf("%d",&a[i]);
}
max=a[0];
for(i=1;i<10;i++){
if(a[i]>max){
max=a[i];
j=i;
}
}
printf("%-4d下标:-4d",max,j);
return 0;
}
3.#include<stdio.h>
int main(){
char a[100]={'\0'},b;
gets(a);
int i,j;
for(i=0;a[i]!='\0';i++){;}
for(j=0;j<=(i-1)/2;j++){
b=a[j];
a[j]=a[i-1-j];
a[i-1-j]=b;
}
printf("%s\n",a);
return 0;
}
㈣ 求助!简单C语言编程题3道
1.
#include <stdio.h>
int fn(int a,int n)
{
int count,sum=0,b=0;
for(count=1;count<=n;count++)
{
b+=a;
sum+=b;
a=a*10;
}
return sum;
}
main()
{
int a,n,sum=0;
printf("input a and n:");
scanf("%d%d",&a,&n);
sum=fn(a,n);
printf("a+aa+aaa+...=%d",sum);
}
2.
#include <stdio.h>
#include <math.h>
int dist(int x1,int y1,int x2,int y2)
{
return (int)sqrt(abs(x1-x2)*abs(x1-x2)+abs(y1-y2)*abs(y1-y2));
}
main()
{
int x1,x2,y1,y2,s;
printf("input a and n:");
scanf("%d%d%d%d",&x1,&y1,&x2,&y2);
s=dist(x1,y1,x2,y2);
printf("distance=%d",s);
}
3.
#include <stdio.h>
#include <math.h>
int countdigit(int number,int digit)
{
int count=0;
do
if(number%10==digit)
count++;
while(number/=10);
return count;
}
main()
{
int number,digit,s;
printf("input a and n:");
scanf("%d%d",&number,&digit);
s=countdigit(number,digit);
printf("%d",s);
}
//全部实现 验证成功
㈤ 三道C语言题!编写下列三道程序!
//1个函数对应1道题
//给点财富值就行了。
#include<stdio.h>
#include<stdlib.h>
int main()
{
void f1();
void f2();
void f3();
f1();
f2();
f3();
system("PAUSE");
return EXIT_SUCCESS;
}
void f1()
{
int i,j,t,a[4];
printf("请输入4个整数:");
for(i=0;i<4;i++)
{
scanf("%d",&a[i]);
}
for(i=0;i<3;i++)
{
for(j=3;j>=i+1;j--)
{
if(a[j]<a[j-1])
{
t=a[j-1];
a[j-1]=a[j];
a[j]=t;
}
}
}
for(i=0;i<4;i++)
{
printf("%d ",a[i]);
}
printf("\n");
}
void f2()
{
int i,j,n;
printf("请输入要打印的行数:");
scanf("%d",&n);
for(i=0;i<n;i++)
{
for(j=0;j<2*i+1;j++)
{
printf("*");
}
printf("\n");
}
}
void f3()
{
int i,j,minr=0,minc=0,maxr=0,maxc=0,a[5][5];
printf("请输入5x5矩阵的各元素的值:\n");
for(i=0;i<5;i++)
{
for(j=0;j<5;j++)
{
scanf("%d",&a[i][j]);
if(a[i][j]>a[maxr][maxc])
{
maxr=i;
maxc=j;
}
else if(a[i][j]<a[minr][minc])
{
minr=i;
minc=j;
}
}
}
printf("max=%d,row=%d,col=%d\n",a[maxr][maxc],maxr,maxc);
printf("min=%d,row=%d,col=%d\n",a[minr][minc],minr,minc);
}
㈥ 请大家帮做3道C语言题目,一定是要用C语言啊!
/*
* 第一个,100~300之间不能被3整除的数输出
*/
#include<stdio.h>
int main ( viud )
{
int i;
for ( i=100; i<=300; i++ ) {
if ( i%3 !=0 ) {
printf( "\n%d", i );
}
}
return 0;
}
/*
* 第二个 你那图形估计不对,不过方法差不多,简单处理就好了
*/
#include<stdio.h>
int main ( viud ) {
puts("&&&&&");
puts("&&&&&");
puts("&&&&&");
puts("&&&&&");
return 0;
}
/*
* 第三题 string.h 里的 strcpy 就是了
* 下边是代码,将src所指向的字符串复制到dest里
*/
char *strcpy(char *dest, const char *src)
{
const char *p;
char *q;
for(p = src, q = dest; *p != '\0'; p++, q++)
*q = *p;
*q = '\0';
return dest;
}
㈦ C语言编程题~3道,高分求解~~先到先得
#include "iostream.h"
struct student
{
private:
int num;
char *name;
int math,english,Cworlds,all;
public:
void set_info(int Num,char *Name);
void set_chengji(int Math,int English,int C);
int allscore();
void display();
};
void student::set_info(int Num,char *Name)
{
num=Num;
name=Name;
}
void student::set_chengji(int Math,int English,int C)
{
this->math=Math;
this->english=English;
this->Cworlds=C;
}
void student::display()
{
cout<<"学号:"<<num<<'\t';
cout<<"姓名:"<<name<<'\t';
cout<<"总成绩:"<<all;
cout<<endl;
}
int student::allscore()
{
all=english+math+Cworlds;
return all;
}
void main()
{
student stu[4];
int NUM=10000;
for(int i=0;i<4;i++)
{
stu[i].set_info(NUM++,"张三");
stu[i].set_chengji(80,90,100);
stu[i].allscore();
stu[i].display();
}
}
-----------------------------------------
#include "iostream.h"
#include "math.h"
struct zuobiao
{
int x,y;
void set_x_y();
zuobiao & set_mid(zuobiao &a);
double set_long();
friend ostream & operator <<(ostream &out,zuobiao &a);
};
void zuobiao::set_x_y()
{
cout<<"请输入横坐标x的值:";
cin>>x;
cout<<"请输入纵坐标y的值:";
cin>>y;
}
zuobiao & zuobiao::set_mid(zuobiao &a)
{
x=(x+a.x)/2;
y=(y+a.y)/2;
return *this;
}
double zuobiao::set_long()
{
double how_long=sqrt(x*x+y*y);
return how_long;
}
ostream & operator <<(ostream &out,zuobiao &a)
{
out<<a.x<<','<<a.y<<endl;
return out;
}
void main()
{
zuobiao zb1,zb2;
zb1.set_x_y();
zb2.set_x_y();
cout<<zb1.set_mid(zb2);
cout<<zb1.set_long();
}
-----------------------------
#include "iostream.h"
struct node
{
int work_num;
int gongz;
node *next;
};
void list(node *l)
{
while(l->next!=NULL)
{
cout<<"工号:";
cout<<l->next->work_num<<endl;
cout<<"工资:";
cout<<l->next->gongz;
cout<<endl;
l=l->next;
}
}
void creat(int n)
{
node *L;
L=new node;
L->next=NULL;
for(int i=0;i<n;i++)
{
node *s;
s=new node;
cout<<"工号:";
cin>>s->work_num;
cout<<"工资:";
cin>>s->gongz;
cout<<endl;
s->next=L->next;
L->next=s;
}
list(L);
}
void main()
{
int n;
cout<<"输入您要创建的职工个数:";
cin>>n;
creat(n);
}
㈧ 急求 3道c语言编程题
第一道:(太晚了,困了,没时间写注释,不好意思)
#include<stdio.h>
#include<string.h>
#include<math.h>
int compare(int *a,int n)
{
int temp;
if(a[0]>a[1])
temp=a[0];
else
temp=a[1];
if(temp<a[2])
temp=a[2];
return temp;
}//compare
void main()
{
int a[3];
char str[3][10];
char *p;
int i,j,count;
printf("Please input the data.\n");
for( i=0;i<3;i++)
{
gets(str[i]);
p=str[i];
while(*p!='\0')
{
if(*p>='0'&&*p<='9')
p++;
else
{
printf("Data error!Please try again!\n");
i--;
break;
}//else
}//while
}//for
for( i=0;i<3;i++)
{
puts(str[i]);
count=0;
for(j=0;j<strlen(str[i]);j++)
{
count*=10;
count=count+(int)str[i][j]-48; //减去48是把字符型的ASCII码转换成本身代表的整数
}//for
a[i]=count;
}//for
printf("The max number is:%d.\n",compare(a,3));
}//main
第二道条件太少,不知道楼主到底想怎样的分寝室。
第三道:
#include<stdio.h>
void main()
{
int i,j,count,m=0;
for(i=2;i<=1000;i++)//1不是素数
{
count=0;
for(j=2;j<=i/2;j++)
{
if(i%j==0)
{ count++;
break;
}
}//for
if(count==0)
{ printf("%d\t",i);
m++;
}//if
if(m==5)
{
printf("\n");
m=0;
}//if
}//for
}//main
补充:(时间匆忙,没时间编译。)
#include<stdio.h>
void main()
{
int person;
printf("Please input the number of person!");
scanf("%d",&person);
if(person%6==0)
printf("The number of dormitory is %d",person/6);
else
printf("The number of dormitory is %d",person/6+1);
}//main