Start New Discussion within our Software Development Community

Write a program that displays all the prime numbers between 50 and 100.

Below is my code:

Write a program that displays all the prime numbers between 50 and 100.
please correct my mistake, thank you.

#include <stdafx.h>
#include "genlib.h"
#include "simpio.h"
#include "math.h"


int _tmain(int argc, _TCHAR* argv[])
{
	int i,nam,lim;
	for (i=50;1<=100;i++)
	    nam=i;
	    lim=sqrt((double)i)+1;
		for (i=50;i<=lim;i+=2)
			   printf("%d",i);
}

--------------------------------------------------------------------------------
The output should appear as follows:

The prime numbers between 50 and 100 are:
53
59
61
71
73
79
83
89
97
Press any key to continue_

-------------------------------------------------------------------
But the output of my code appear as follows:

_

--------------------------------------------------------------------

When I run the program nothing appears.
please correct my mistake, thank you.

#include <stdafx.h>
#include "genlib.h"
#include "simpio.h"
#include "math.h"


int _tmain(int argc, _TCHAR* argv[])
{
	int i,nam,lim;
	for (i=50;1<=100;i++)
	    nam=i;
	    lim=sqrt((double)i)+1;
		for (i=50;i<=lim;i+=2)
			   printf("%d",i);
}

Here is your code, with brackets and consistent indentation.

#include <stdafx.h>
#include "genlib.h"
#include "simpio.h"
#include "math.h"


int _tmain(int argc, _TCHAR* argv[])
{
    int i,nam,lim;
    for (i=50;1<=100;i++)
    {
        nam=i;
    }
    lim=sqrt((double)i)+1;
    for (i=50;i<=lim;i+=2)
    {
        printf("%d",i);
    }
}

Is this what you intended?

This article has been dead for over six months. Start a new discussion instead.