Menu

c programming question,

sirios
2017-11-23
2017-11-23
  • sirios

    sirios - 2017-11-23

    hello,i am working on a university project and i want some help with my last topic,my whole code is down below,any help would be appreciated
    • Asks the user to enter an integer between 1 and 20 (validation must be checked), which he stores in the count variable. Then prints all integers from 1 to 10 for which the number of their impressions is equal to the count value.

    include <stdio.h>

    include <stdlib.h>

    int main() {
    int numbers[20], counters[20];
    int elementCount, i, j, count,cnt;

    printf("Enter Number of Elements in Array\n"); // entering the numbers of the array
    scanf("%d", &elementCount);  //array numbers
    printf("Enter %d numbers\n", elementCount); 
    /* Read array elements */
    for(i = 0; i <elementCount; i++){ //loop
        scanf("%d", &numbers[i]);  //read 
        counters[i] = -1; 
        while (numbers[i]<1 || numbers[i]>10){ //check if value of element is correct
    
     printf("The number you entered is false,please enter a number again\n"); //re-enter number
     scanf("%d",&numbers[i]); //read again
    

    }
    }

    //  for any element inputArray[i], If countArray[i] = -1, 
    //  that means frequency is not counted for this number yet 
    //  and countArray[i] = 0 means frequency is already 
    //  counted for this number.
    
    for(i = 0; i < elementCount; i++) {  //loop
        count = 1;   
        for(j = i+1; j < elementCount; j++) {  
            if(numbers[i]==numbers[j]) {
                counters[j] = 0;    
                count++;
            }  
        }  
        if(counters[i]!=0) {  
            counters[i] = count;  
        }  
    }
    
    // Print count of each element   
    for(i = 0; i < elementCount; i++) {  
        if(counters[i] != 0) {  
            printf("Element %d : Count %d\n", numbers[i], counters[i]);  
        }  
    }
    

    //enter a random element bewteen 1..20 then print the elements that are equal to the count value
    for(i = 0; i < elementCount; i++);
    printf("Enter a number bewteen 1...20\n");
    scanf("%d",&cnt);
    while (cnt<1 || cnt>20){ //check if value of element is correct

     printf("The number you entered is false,please enter a number again\n"); //re-enter
     scanf("%d",&cnt); //read
     for(i = 0; i < elementCount; i++);
     printf("\n",&count);
    

    }

    return 0;
    

    }

     
  • Deep Vyas

    Deep Vyas - 2017-11-23

    Hello,
    I checked your post for detail and can help you with current expectation.
    We can discuss further on email deepvyas71@gmail.com
    Please let me know your interest

    Best regards,
    Deep

     

Log in to post a comment.

Want the latest updates on software, tech news, and AI?
Get latest updates about software, tech news, and AI from SourceForge directly in your inbox once a month.