2014-05-25 2 views
-3

다음 옵션이있는 메뉴를 만드십시오.C로 메뉴를 만들려면 어떻게해야합니까?

가) 정수 n 개의 요소 배열을 생성합니다. 위치 별

B) 변화 소자 값

C) 우리는 다음 값 2,3,5- 배열을 가질 경우, 즉 소자 내에서 반복되는 값들의 수를 표시 , 2,6,5,7, 2 명이 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;  
} 
+0

http://stackoverflow.com/questions/11945486/how-to-create-an-interactive-menu-in-c-that-move-from-one-function-into-another의 가능한 속담 – CandiedOrange

+0

http를 참조하십시오. : //www.tenouk.com/cpluscodesnippet/dowhilemenu.html – CandiedOrange

답변

1

내가 당신에게 의사 코드를 줄 것이다는 :

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 
     } 

나는이 문제를 해결한다고 생각합니다. 최적화에 관심이 없기를 바랍니다. 솔루션이 될 수 있습니다. 확실한 오류가 발생할 것입니다. 나는 이것을 시험하지 않았습니다. 희망이 도움이됩니다.

+0

감사합니다 :) 그것을 사용할 것입니다. –

관련 문제