Sponsored Links


Results 1 to 3 of 3

Thread: CS201: Introduction to Programming Assignment No. 02 Spring 2010 May 6

  1. #1
    Senior Member viki's Avatar
    Join Date
    May 2010
    Posts
    2,132

    28 CS201: Introduction to Programming Assignment No. 02 Spring 2010 May 6

    Sponsored Links1


    Due Date:07/05/2010

    Problem Statement: Finding the repeated elements in an array
    You are required to write a program that takes 10 integer values in an array as input from user. After getting input, the program should find the elements with repetition and number of times each element is repeated.


    Detailed Description:

    1. Declare an integer type array.
    2. Take input from user in the array i.e. 10 integer values.
    3. Pass this array to a function which will calculate and display the number of times an element is repeated.
    4. If the array contains elements with repetition, the program should only display the repeated elements and their count.
    5. If there is no repetition in the array, the program should simply display the message “There is no repetition in the array”.

    Sample Output 1
    Enter the value of array element 1 : 8
    Enter the value of array element 2 : 6
    Enter the value of array element 3 : 2
    Enter the value of array element 4 : 4
    Enter the value of array element 5 : 2
    Enter the value of array element 6 : 2
    Enter the value of array element 7 : 7
    Enter the value of array element 8 : 8
    Enter the value of array element 9 : 5
    Enter the value of array element 10 : 6

    Sponsored Links


    2 is repeated 3 times
    6 is repeated 2 times
    8 is repeated 2 times


    Sample Output 2
    Enter the value of array element 1 : 1
    Enter the value of array element 2 : 3
    Enter the value of array element 3 : 8
    Enter the value of array element 4 : 7
    Enter the value of array element 5 : 4
    Enter the value of array element 6 : 9
    Enter the value of array element 7 : 6
    Enter the value of array element 8 : 5
    Enter the value of array element 9 : 0
    Enter the value of array element 10 : 2


    There is no repetition in the array

  2. #2
    Quote Originally Posted by viki View Post
    Due Date:07/05/2010

    Problem Statement: Finding the repeated elements in an array
    You are required to write a program that takes 10 integer values in an array as input from user. After getting input, the program should find the elements with repetition and number of times each element is repeated.


    Detailed Description:

    1. Declare an integer type array.
    2. Take input from user in the array i.e. 10 integer values.
    3. Pass this array to a function which will calculate and display the number of times an element is repeated.
    4. If the array contains elements with repetition, the program should only display the repeated elements and their count.
    5. If there is no repetition in the array, the program should simply display the message “There is no repetition in the array”.

    Sample Output 1
    Enter the value of array element 1 : 8
    Enter the value of array element 2 : 6
    Enter the value of array element 3 : 2
    Enter the value of array element 4 : 4
    Enter the value of array element 5 : 2
    Enter the value of array element 6 : 2
    Enter the value of array element 7 : 7
    Enter the value of array element 8 : 8
    Enter the value of array element 9 : 5
    Enter the value of array element 10 : 6


    2 is repeated 3 times
    6 is repeated 2 times
    8 is repeated 2 times


    Sample Output 2
    Enter the value of array element 1 : 1
    Enter the value of array element 2 : 3
    Enter the value of array element 3 : 8
    Enter the value of array element 4 : 7
    Enter the value of array element 5 : 4
    Enter the value of array element 6 : 9
    Enter the value of array element 7 : 6
    Enter the value of array element 8 : 5
    Enter the value of array element 9 : 0
    Enter the value of array element 10 : 2


    There is no repetition in the array
    #include <iostream.h>
    #include <stdlib.h>
    #include <conio.h>
    using namespace std;
    void repeated_values(int[],int);
    int main()
    {
    int a[10],f;
    for(f=0;f<10;f++)
    {
    cout<<"Enter the value of array element "<<f+1<<": ";
    cin>>a[f];
    }
    repeated_values(a,10);
    system("pause");
    return 0;
    }
    void repeated_values(int a[],int n)
    {
    int i,j,k=0,b=0,t,rpt[n];
    bool first,ok;
    for(i=0;i<n;i++)
    rpt[i]=0;
    for(i=0;i<n-1;i++)
    {
    t=1;
    ok=false;
    for(k=0;k<b;k++)
    if(a[i]==rpt[k])
    {
    ok=true;
    }
    if(!ok)
    {
    first=true;
    for(j=i+1;j<n;j++)
    {
    if(a[i]==a[j])
    {
    t++;
    if(first)
    {
    first=false;
    rpt[b]=a[i];
    b++;
    }
    }
    }
    }
    if(t!=1)
    cout<<a[i]<<" is repeated "<<t<<" times\n";

    }
    if(b==0)
    cout<<"There is no repetition in the array\n";
    }

  3. #3
    Senior Member sanam's Avatar
    Join Date
    May 2010
    Location
    sky
    Posts
    217
    good solution but yah tu ab purani ho gai hai.

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Similar Threads

  1. Replies: 2
    Last Post: 11-20-2010, 08:25 PM
  2. FINALTERM EXAMINATION Spring 2010 CS201- Introduction to Programming
    By desireforheaven in forum Current Papers 2010
    Replies: 0
    Last Post: 11-01-2010, 01:07 PM
  3. Replies: 0
    Last Post: 10-29-2010, 12:29 AM
  4. Replies: 0
    Last Post: 05-16-2010, 05:26 AM
  5. CS201 Introduction to Programming Assignment 3 May13,2010
    By viki in forum Assignments & Solutions
    Replies: 0
    Last Post: 05-13-2010, 10:43 PM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
-: Vuhelp Disclaimer :-
None of the files shown here are hosted or transmitted by this server. The links are provided solely by this site's users. The administrator's or staff of Vuhelp.net cannot be held responsible for what its users post, or any other actions of its users. You may not use this site to distribute or download any material when you do not have the legal rights to do so. It is your own responsibility to adhere to these terms. If you have any doubts about legality of content or you have any suspicions, feel free to contact us.
Online Education | JhelumSoft