gpt4 book ai didi

c - 如何用 C 语言创建菜单?

转载 作者:行者123 更新时间:2023-11-30 21:03:37 25 4
gpt4 key购买 nike

制作一个包含以下选项的菜单。

A) 生成一个包含 n 个元素的整数数组。

B) 按位置更改元素值

C) 显示元素内重复的值的数量,即如果我们有一个包含以下值的数组2,3,5,2,6,5,7,他们必须证明 2 出现了两次,3 出现过一次,5 出现过两次,6 和 7 出现过一次

D) 退出程序。

我是一名学生,我不知道我的代码会与此相关。

#include <stdio.h>

void ingreso(){
int i=0,tamano,matriz[i],d,a=0;

printf("Escriba el numero de elementos que quieres ingresar ");
scanf("%d", &tamano);
printf("\n");

for(d=1;d <=tamano; d++)
{

printf("Escriba un numero de la matriz ");
scanf("%i", &matriz[i]);

if(i=2){
a=a+1;
printf("\n Se repitio:%d veces \n\n", a);
}


}
printf("%d", matriz[i]);




}



int main (){

printf("Ingresa los valores que tu quieras \n");
printf("Ingresa un numero negativo cuando desies salir \n\n");
ingreso();
return 0;
}

最佳答案

我会给你伪代码:

   1: input n numbers using scanf() 
2:sort the array using any sort algorithm.
3:once it is sorted you can easily count if( a[i]==a[i+1])
4: print count and a[i]

或者

  1:input n numbers using scanf() 
2: for i=0 till n-1{
3: for j=i+1 till n{
4: if a[i] equal to a[j]
if(prev_read[j-1]==i)
ignore and break
prev_read[j-1]==i
5: count++
6: else
prev_read[j-1]=-1
7: count =1
}
8: print a[i] and count
}

我认为这应该可以解决您的问题。我希望您现在没有考虑优化,所以这可能是一个解决方案。您肯定会遇到一些错误。我没有对此进行测试。希望这会有所帮助。

关于c - 如何用 C 语言创建菜单?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/23852737/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com