|
Please is there any one out there that can help me I am having a very tough time trying to figure this crap out. I know I have to create a loop to find the prime numbers, but i can't figure it out. I have never done any programming before. This is my 4th week in my C# programming class and its going to fast for me.
This website is supposed to have free code and tutorials. does anyone know the code for this? Please help I am lost!
Ryan
|
|
|
|
|
okay I found a code that displays the prime numbers, but i need to find the average of the dispalyed prime numbers. Here is the code does anyone what to let me know how to find the average please.
using System;
namespace PrimeNumbers
{
///
/// Summary description for Class1.
///
class PrimeNumbers
{
///
/// The main entry point for the application.
///
[STAThread]
static void Main(string[] args)
{
// Ask the user for the quantity to check for Prime Numbers.
Console.Write("Please enter the quantity to test for Prime Number: ");
// Assign topNumber with User's Input.
ulong topNumber = ulong.Parse(Console.ReadLine());
// Create an boolean array, numbers
bool[] numbers = new bool[topNumber];
// Assign all the values in numbers with 'true'.
for (ulong i = 0; i < topNumber; i++)
{
numbers[i] = true;
}
// Assign all those mutiples of 2 and 3 to be 'false'.
// So that it facilitate you in finding the Prime Numbers.
for (ulong i = 2; i < topNumber; i++)
{
if(numbers[i])
{
for(ulong j = i * 2; j < topNumber; j += i)
numbers[j] = false;
}
}
// The counter to count how many Prime Numbers.
ulong primes = 0;
// For the remaining numbers which are still 'true' are Prime Numbers.
for (ulong i = 1; i < topNumber; i++)
{
if(numbers[i])
{
primes++;
Console.Out.WriteLine(i);
}
}
Console.Out.WriteLine();
Console.Out.WriteLine(primes + " out of " + topNumber + " prime numbers found.");
Console.In.ReadLine();
}
}
}
Ryan
|
|
|
|
|
Well, an average is the sum of the numbers divided by how many numbers there are. You already know how many primes there are (ulong primes), you just need another variable to total them inside the same loop (the last loop). Then, after the loop exists, compute the average.
I'd rather not show you the exact code, because you're supposed to learn something.
BTW, the comment "Assign all those mutiples of 2 and 3 to be 'false'" should either read "Assign multiples of 2 to be false for all numbers", or "assign multiples of 2, 3, ... up to topNumber to be false".
And also, it's sort of pointless to assign multiples of i where i > topNumber / 2, since any multiples are outside of the range of the array.
Most of programming is NOT coding, it's figuring out the algorithm. Good luck!
Marc
My website
|
|
|
|
|
Pffff well done.
I make myself some work in the other thread to post you some code just to realize now that you already found most of what you were searching for.
Please stick to ONE thread and dont hop around.
|
|
|
|
|
hii all;
i want ask some questions about network.
1-if am in lan and we connect to internet through proxy server. of course the proxy replace each request ip address of any machine on lan by his ip. the destination host will replay on proxy ip. how can the proxy determine the staion on lan who made original request to take response? also same question if i access internet in lan through (ics) for ex pc has modem
2- if i bind a sockt on lan its address and port will be on lan only. if this machine can access internet through lan is there away to bind it on lan router which access internet or i mean the interface which has direct access to internet so i can communicate with it from outside like imesh wich can work even if am in lan?
marcoryos
|
|
|
|
|
With an admission that i am quite novice to C#, (i am only 30 days old) i have few doubts if C# is suited for engineers? Say, if I want to develop a numerical tool to do some matrix calculation or Computational Fluid Dyanmics Analysis, should i prefer C or C++ or C#....I know MATLAB is written in C and so do some other engineering software.
Regards,
Amit
|
|
|
|
|
amitmohanty wrote:
i am only 30 days old
Your parents must be congratulated as your linguistic skills for such a young person are way above what I could have ever expected.
amitmohanty wrote:
i have few doubts if C# is suited for engineers? Say, if I want to develop a numerical tool
Does this answer your question? Harness the Features of C# to Power Your Scientific Computing Projects[^]
- SUMMARY: The C# language has been used quite successfully in many kinds of projects, including Web, database, GUI, and more. One of the last frontiers for the application of C# code may well be scientific computing. But can C# measure up to the likes of FORTRAN and C++ for scientific and mathematical projects?
In this article, the author answers that question by looking at the .NET common language runtime to determine how the JIT compiler, Microsoft intermediate language, and the garbage collector affect performance. He also considers C# data types, including arrays and matrices, along with other language features that play an important role in scientific computing applications.
My: Blog | Photos
WDevs.com - Open Source Code Hosting, Blogs, FTP, Mail and More
|
|
|
|
|
Well I am 30 days old means I have started coding C# since last 30 days. I usually code in MATLAB and C.
Thanks, reading your link. Let me see what it has to offer.
Regards and Thanks,
Amit
|
|
|
|
|
|
Thats okay. Its fun By the way, the article is exactly what I was looking for. Thanks a lot.
Amit
|
|
|
|
|
Are you going to stick with C#?
/\ |_ E X E GG
|
|
|
|
|
Well thats a good question. I think nothign is all good and perfection is a myth. So I am still trying to find out what are the drawbacks of doing coding with C# if i am trying to develop a scitific tool. I will wait and see. But anyway, if nothign else I would still learn it. I like it. Reasons may be unknown. Now can anone tell me what is not so good about C# if i am considering scientific computing?
Regards,
Amit
|
|
|
|
|
amit
If you read the article posted by Colin, it is pretty interesting. The article was very interesting if you are a hardcore matlab user and seeing how one can exploit c#.
In the mean time you can take a look at this
http://www.codeproject.com/csharp/dynmatrixmath.asp
In my opinion having come from an embedded systems background and moving into windows application development, I have to say that matlab is simply the best for prototyping algorithms quickly and efficiently. The answer is partly baised because i have used matlab for 8 years and c# for 3 months. If you are going to do simulations using the model developed in matlab you can always run it on a unix box as well.
I have to say c# is fantastic for doing all the pretty window gui things
You can also do matrix calculations in c++ because i recall seeing someone develop c++ matrix libraries to give c++ matlab like matrix functionalities.
cheers
|
|
|
|
|
When I reopen an old C# console application, say Class1.cs, and modify it; I found no build option for that. Damn, how do i complie it and build the solution.
Amit
|
|
|
|
|
Could you explain much more your problem ?
|
|
|
|
|
Thank you for your response LongHC. It is like that
1> I opened a new console application in microsoft studio.net for C#.
2> Say , I modified it to write "HelloWorld" program.
3> I build it and run it. everything is fine till now.
4> I close it.
5> I come back tomorrow ro sometime after and feel like i want to make some changes in the code of HelloWorld.cs
6> so I open the file HelloWorld.cs, but i can't see the build option on the toolbar at all. I can't build it if i want to and hence i can't do any modification to it. So, now i have to open a new console apllication. Defnitely that will have the Build option on the toolbar but thing is that I have to do everythign once more or i have copy my previous program to the new file.
I know I am doing somethign really silly, but can't really figure out. Do i need to make somechanges in the option setting?
Regards,
Amit
|
|
|
|
|
Any file that is openj in the vs cann't be build ,cuz it's not in solution file or project file,if you want to be able to compile it ,don't open just the file,but open the .csproj file or the .sln file and you will be able to do any thing.
|
|
|
|
|
Thanks very much from a novice..
Take Care
|
|
|
|
|
amitmohanty wrote:
Thanks very much from a novice..
You ?
amitmohanty wrote:
Take Care
?
|
|
|
|
|
I am novice
|
|
|
|
|
i want to create a Crystal report, all the records are stored in DATASET how can create a report from dataset
i tried this code but it's not working
Report1 is blank
***************************************
Report1 rpt = new Report1();
rpt.SetDataSource(dsrefresh);
crystalReportViewer1.ReportSource = rpt;
***************************************
this code will UNION all DBF files from temporary folder, to dataset.
this part is ok
while (i < countdays)
{
DirectoryInfo Folders = new DirectoryInfo(@ALOHA_PATH+"\\"+datefolders+"");
if (Folders.Exists)
{
string ITMConnString = "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=" + Application.StartupPath + ";Extended Properties=dBase IV";
OleDbConnection ITMConnection = new OleDbConnection(ITMConnString);
string ITMSelectQuery = "Select * from "+ALOHA_PATH+"\\GNDITEM.DBF UNION ALL Select * from "+ALOHA_PATH+"\\"+datefolders.ToString()+"\\GNDITEM.DBF" ;
//MessageBox.Show(ITMSelectQuery);
OleDbDataAdapter da= new OleDbDataAdapter(ITMSelectQuery ,ITMConnection);
da.Fill (dsrefresh,"GNDITEM");
dv = new DataView(dsrefresh.Tables["GNDITEM"]);
dataGrid1.DataSource = dv;
ITMConnection.Close();
}
i +=1;
// frmwait.Close();
// this.Show();
}
dv = new DataView(dsrefresh.Tables["GNDITEM"]);
dataGrid1.DataSource = dv;
|
|
|
|
|
I am trying to make a webservice that return a image to ppc. I have tried to return it as a bitmap but it give this following error "System.Drawing.Bitmap cannot be serialized because it does not have a default public constructor" so I changed from bitmap to base64 string, this works, however when I tried to convert base64 string back to bitmap(on ppc) I got the same error again.. Do anyone know exactly what I should do?
|
|
|
|
|
Make sure to extract the bytes of the image to transfer. (And base64 that array)
public Image GetImageFromBytes( byte[] bytes )
{
MemoryStream stream = new MemoryStream(bytes);
Image image = Image.FromStream( stream );
return image;
}
public byte[] GetImageBytes(Bitmap bitmap)
{
MemoryStream stream = new System.IO.MemoryStream();
bitmap.Save( stream, System.Drawing.Imaging.ImageFormat.Jpeg );
stream.Position = 0L;
System.IO.BinaryReader reader = new System.IO.BinaryReader(stream);
byte[] bytes = reader.ReadBytes( (int)stream.Length );
stream.Close();
return bytes;
}
|
|
|
|
|
public Image getObjectPicture(string objectID)
{
OdbcConnection connection= new OdbcConnection(@"Driver={MySQL ODBC 3.51 Driver};SERVER=localhost;DATABASE=ic;UID=;PASSWORD=;");
OdbcCommand cmm = new OdbcCommand("SELECT Picture FROM Object WHERE ObjectID='"+objectID+"'", connection);
connection.Open();
OdbcDataReader reader = cmm.ExecuteReader();
string filename= @"c:\default.bmp"; //default pic
while(reader.Read())
{
filename = reader[0].ToString();
}
Bitmap bitmap = new Bitmap(filename);
MemoryStream stream1 = new System.IO.MemoryStream();
bitmap.Save( stream1, System.Drawing.Imaging.ImageFormat.Bmp );
stream1.Position = 0L;
BinaryReader br = new BinaryReader(stream1);
byte[] bytes = br.ReadBytes( (int)stream1.Length );
stream1.Close();
MemoryStream stream2 = new MemoryStream(bytes);
Image image = Image.FromStream( stream2 );
return image;
}
I combined the given code and did this, and I got this error message "System.Drawing.Imaging.ImageFormat cannot be serialized because it does not have a default public constructor.", I put this coding on the webservice though.. that exactly should I do, I am rather confuse now
|
|
|
|
|
Hi,
I have many questions about checkbox :
1/I would like to create dynamicaly 8 checkbox into a form.
The name of each checkbox begin with "CHECKBOX_CAM_".
So :
CHECKBOX_CAM_1
CHECKBOX_CAM_2
CHECKBOX_CAM_3
...
CHECKBOX_CAM_8
2/ I would like to set/get some properties like text,position, tag,... with a SQL Database.
3/ I would like to retrieve the state of the group to a byte at any moment. when the user un/select one or more checkbox.
Best Regards
youssef
|
|
|
|