跪求各位大佬编写一个c语言程序题。

跪求各位大佬编写一个c语言程序题。,第1张

这题主要考查对基础数据类型的了解和变量的输入输出。

测试代码

测试代码:

#include <stdioh>

int main()

{

    int n; // 定义一个整型变量n

    float f; // 定义一个实型变量n

    char c; // 定义一个字符型变量n

    scanf("%d %f %c", &n, &f, &c); // 输入三个变量的值

    printf("%d %f %c", n, f, c); // 输出三个变量的值

    return 0;

}

/

思路: 遍历数组a,然后判断数组a中的每一个元素是否为奇数,如果是奇数,则将该数存放到数组b中。

/

void set(int a[],int length,int b[])

{

int i,j;

for(i=j=0;i<length;i++)

if(a[i]%2 != 0)  //如果a[i]是奇数

b[j++]=a[i]; //将a[i]赋值给数组b,同时j自增1

}

int delete(int data[],int n,int key)

{

int i,j;

for(i=0;i<n;i++)

if(data[i] == key){

//将下标为i之后的所有数组元素左移一位

for(j=i+1;j<n;j++)

a[j-1]=a[j];

n--;  //数组长度减1

break;  //由于已经删除了指定的数组元素,故直接退出for循环

}

return n;  //返回删除后的数组元素个数

}

第一题很简单,没啥好说的,就是输入数字,然后一个简单的 switch case 语句。

#include <stdioh>

int main()

{

int a, b, opr;

printf("输入两个数字,如 3 5 (数字用空格分开)\n");

scanf("%d %d", &a, &b);

printf("选择计算方式:\n");

printf("1 加, 2 减, 3 乘, 4 除\n");

scanf("%d", &opr);

switch (opr)

{

case 1:

printf("%d + %d = %d\n", a, b, a+b);

break;

case 2:

printf("%d - %d = %d\n", a, b, a-b);

break;

case 3:

printf("%d X %d = %d\n", a, b, ab);

break;

case 4:

if (b == 0)

{

printf("除数不能为 0\n");

return 1;

}

printf("%d / %d = %d\n", a, b, a/b);

break;

default:

printf("无效的计算方式\n");

return 1;

}

return 0;

}

第二题,输入购买册数m后,计算出总价 total,然后再根据total的大小,乘以对应的折扣率,即得最终价格。

#include <stdioh>

int main()

{

unsigned int total, m, price;

price = 3; / 3元每册 /

printf("要买多少册?\n");

scanf("%u", &m);

total = mprice; / 总价 /

if (total > 20000)

total = 075;

else if (total > 10000)

total = 08;

else if (total > 2000)

total = 085;

else if (total > 100)

total = 09;

printf("应付 %u 元\n", total);

return 0;

}

第三题,让 x 从1开始循环到 9 ,依次代入 11111 (10x+1) 这个式子中,如果结果等于 111111 ,那么就找到对应的x了,然后打印结果即可。 最终结果 x = 9

#include <stdioh>

int main()

{

int x;

for (x = 1; x <= 9; x++)

{

if (11111(10x + 1) == 111111)

{

printf("x = %d, 111111 = 11111%d1\n", x, x);

break;

}

}

return 0;

}

1

#include "stdioh"

void input(int d[][100],int m)

{

 int r,c;

 for(r=0;r<m;r++)

 {

  printf("输入第%d行%d个数:",r+1,m);

  for(c=0;c<m;c++)

  {

   scanf("%d",&d[r][c]);

  }

 }

}

void fun(int d[][100],int m,int r,int c)

{

 int i,j;

 r=0;c=0;

 for(i=0;i<m;i++)

 {

  for(j=0;j<m;j++)

  {

   if(d[r][c]<d[i][j])

   {

    r=i;c=j;

   }

  }

 }

}

int main()

{

 int d[100][100];

 int m;

 int i,j,r,c;

 printf("输入阶数:");

 scanf("%d",&m);

 input(d,m);

 fun(d,m,&r,&c);

 printf("最大元素位于(%d,%d),值为:%d\n",r+1,c+1,d[r][c]);

}

2

#include "stdioh"

void  fun(char p, char q)

{

 int i,j;

 i=0;j=0;

 while((p+i)!='\0')

 {

  (q+j)=(p+i);

  if((i+1)%3==0)

  {

   j+=1;

   (q+j)=' ';

  }

  i++;

  j++;

 }

 (q+j)='\0';

}

int main()

{

 FILE fp1,fp2;

 char p[100],q[100];

 if((fp1=fopen("formtxt","r"))==NULL)

  printf("formtxt");

 if((fp2=fopen("totxt","w"))==NULL)

  printf("totxt");

 fscanf(fp1,"%s",p);

 fun(p,q);

 fprintf(fp2,"%s",q);

}

首先,定义一个单链表的结构体,用来存储整数值和指向下一个结构体的指针

然后,在main()函数中定义一个头节点指针,并用它来存储整个链表

接下来,实现从键盘输入五个整数并将它们尾插入链表中

最后,实现链表中的插入和删除 *** 作,并输出链表中的所有元素

下面是一个可行的c语言程序,该程序实现了从键盘输入五个整数并存储在链表中,然后插入和删除一个元素,最后输出链表中的元素。

#include <stdioh>#include <stdlibh>#define N 10001void do_symmetry(char s) { int notmatch_left_count = 0; int notmatch_right_count = 0; int i; char p = s; while (p != '\0') { if (p == '(') { notmatch_left_count++; } else if (notmatch_left_count > 0) { notmatch_left_count--; } else { notmatch_right_count++; } p++; } if (notmatch_left_count == 0 && notmatch_right_count == 0) { puts(s); } else { i = notmatch_right_count; while (i --> 0) putchar(')'); i = notmatch_left_count; while (i --> 0) putchar('('); putchar('\n'); i = notmatch_right_count; while (i --> 0) putchar('('); printf("%s", s); i = notmatch_left_count; while (i --> 0) putchar(')'); putchar('\n'); }}int main(int argc, char argv[]){ char s[N]; while (scanf("%s", s) == 1) { do_symmetry(s); } return 0;}

希望能解决您的问题。

您好!很高兴为您解答。

1、852

2、

d1=8

d2=5

3、54321

4、k=3

5、1 0 8

望采纳~

以上就是关于跪求各位大佬编写一个c语言程序题。全部的内容,包括:跪求各位大佬编写一个c语言程序题。、程序编写题、三道c语言的程序题要求要步骤全、最好把思路写上 先上200分在线等等相关内容解答,如果想了解更多相关内容,可以关注我们,你们的支持是我们更新的动力!

欢迎分享,转载请注明来源:内存溢出

原文地址: http://outofmemory.cn/zz/9679282.html

(0)
打赏 微信扫一扫 微信扫一扫 支付宝扫一扫 支付宝扫一扫
上一篇 2023-04-30
下一篇 2023-04-30

发表评论

登录后才能评论

评论列表(0条)

保存