1.Make and run a program that will output all the prime numbers from 1-100. (FN do prime)
2.make and run a program that will allow the user to input 10 numbers and display the total number of positive and negative numbers entered.
3. write a program that reads numbers until number is less than or equal to 100.

can you make that program using do while functions ?? i've already did the third problem though.

#include<stdio.h>
#include<conio.h>
main()
{
int a=0;

do
{
printf("%d ",a);
a=a+1;
}
while(a<101);
getch();
}

guidelines to write a program for your 2 question:

  1. take an interger array with size 10 or number whatever you want
  2. i think you know how to read input values so then store those values into that array
  3. iterate through the array elements one by one by checking whether it is positive or negative ( elemnt > 0 then print positive otherwise negative )

first you try it your own

we will help you furtherly in case if you have any doubts

happy coding

Edited 3 Years Ago by radhakrishna.p: giving information about the solution

For your 1st part. This will tell you if a number is prime or not:

bool isPrime(int nr){
    if (nr == 0 || nr == 1) return false;
    for (int i=2;i<nr/2+1;i++) if (nr%i==0) return false;
    return true;
}

Now insert this validation into your loop, and see what you get.
As for your 3rd, you an use

do{ cout << i++ << " "; } while(i<=100);

since you're working in C++.

Edited 3 Years Ago by Lucaci Andrew

@ luicaci Andrew to make your isPrime function a little faster you can do this

bool isPrime(int nr)
{    
    if (nr == 0 || nr == 1) 
        return false;
    if (nr % 2 == 0 && nr != 2) // check to see if its even
        return false
    for (int i=3; i * i <= nr; i += 2) // no need to check even numbers here
        if (nr % i == 0 ) return false;    
    return true;
}
Comments
That too. And also... it's Lucaci?!?!... :)
This article has been dead for over six months. Start a new discussion instead.