Jump to content
منتدى البحرين اليوم

ساعدوني بلييز


Recommended Posts

لو سمحتوا ابي حل اسايمنت 5 حق السي اس 101

السؤال هو

4.15

use asingle array to solve the following problem

read in 10 numbers each of wich is between 10 and 100, inclusive. as each number is read , print it only if it is not a duplicate of the a number already read . provide for the"worst case" in which all 10 numbers are different . at tha end you shouid print all the elements of the array

 

مشكورين وما تقصرون thumbup.gif

Link to comment
Share on other sites

 

#include <iostream>

 

using std::cout;

using std::endl;

using std::cin;

 

#include <iomanip>

 

using std::setw;

 

int main()

{

const int SIZE = 20;

int a[ SIZE ] = { 0 };

int subscript = 0;

int duplicate;

int value;

 

cout << "Enter 20 integers between 10 and 100:\n";

 

for ( int i = 0; i < SIZE; ++i ) {

duplicate = 0;

cin >> value;

 

for ( int j = 0; j < subscript; ++j )

if ( value == a[ j ] ) {

duplicate = 1;

break;

 

} // end if

 

if ( !duplicate )

a[ subscript++ ] = value;

 

} // end for

 

cout << "\nThe nonduplicate values are:\n";

 

for ( i = 0; a[ i ] != 0; ++i )

cout << setw( 4 ) << a[ i ];

 

cout << endl;

 

return 0;

 

} // end main

Link to comment
Share on other sites

 

#include<stdio.h>

int main()

{

 

int i,j,a[20],x=1;

 

for (i=0;i<20;i++)

{

printf("Enter a number between 10 & 100:");

scanf("%d",& a);

 

while (a<10 || a>100)

{

printf("\nEnter a number again (10-100):");

scanf("%d",& a);

}

 

for (j=0;j<i;j++)

{

if (a[j]!=a)

x=1;

 

else

{

x=2;

break;

}

}

 

if(x==1)

printf("%d\n",a);

}

return 0;

}

 

 

Link to comment
Share on other sites

اختي مسامحة بس ليش ما يرضه يطلع عندي الاوت بوت نفسه الي عندي في الورقة

لو سمحتوا محد عنده حل ثاني

ساااعدوني الله يخليكم يوم الاحد آخر يوم تسليمه sad.gif

الي عنده حل ثاني يحطه لي

ما تقصرون

Link to comment
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
الرد على هذا الموضوع...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

Loading...
×
×
  • Create New...