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

标签 c

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

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/

相关文章:

c - 在 printf 参数列表中使用 ( )。这个语法是什么意思?

c - 这个 LLVM IR 代码有什么问题

c - 为什么打包不能跨同级 union 或结构工作

c - 指针和结构类型的大小看似不一致的原因是什么?

c++ - pow(a/b,x) 与 pow(b/a,-x) 的数值精度

c - 不使用 sizeof(type),使用 sizeof *p,是否安全正确?

c - 不删除有两个 child 的节点

c++ - calloc 覆盖另一个变量的内存?

任何人都可以使用 opengl 在 c 中给我一个简短的代码示例,其中单击两个不同的方 block 会改变它们的颜色?

c - 从 C 文件中读取整数