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();
}

please help me with problems 1 and 2 :))

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

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++.

@ 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;
}
commented: That too. And also... it's Lucaci?!?!... :) +6
Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.