Navigation Bar

Prime or Not prime with while loop

#include<iostream.h>
#include<conio.h>
void main()
{
  char c = ‘y’;
  int n;
  while( c == ‘y’ || c ==’Y’ )
    {
clrscr();
cout<<” Enter a Number”<<endl;
cin>>n;
             int s = 0;

for(int i=1; i<=n; i++)
  {
            if(n%i==0)
                 s = s+1;
  }

if(s == 2)
cout<<” Prime Number”<<endl;
else
cout<<” Not Prime Number”<<endl;

cout<<” Do you want to check another number? Press ‘y’ for yes and ‘n’ for No ”<<endl;
cin>>c;
    }
getch();
}

Prime or Not prime with while loop

#include<iostream.h>
#include<conio.h>
void main()
{
  char = ‘y’;
  int n;
  while( c == ‘y’ || c ==’Y’ )
    {
clrscr();
cout<<” Enter a Number”<<endl;
cin>>n;
             int s = 0;
for(int i=0; i<=n; i++)
  {
            if(n%i==0)
                 s = s+1;
  }
if(s == 2)
cout<<” Prime Number”<<endl;
else
cout<<” Not Prime Number”<<endl;
cout<<” Do you want to check another number? Press ‘y’ for yes and ‘n’ for No ”<<endl;
cin>>c;
    }
getch();
}

Program to Convert Military Time to Standard time (12 OR 24 Hours)

  1. #include<iostream>
  2. #include<conio.h>
  3. using namespace std;
  4. int main()
  5. {
  6. int hours,mins,seconds;
  7. bool status = true;
  8. cout << "Enter Hours (00-23): "; cin >> hours;
  9. cout << "Enter Minutes (00-59): "; cin >> mins;
  10. cout << "Enter Seconds (00-59): "; cin >> seconds;
  11. if((hours >= 24 || hours < 0))
  12. {
  13. cout<<"\nInvalid Hours.."; status=false;
  14. }
  15. if((seconds >= 60 || seconds < 0))
  16. {
  17. cout<<"\nInvalid Seconds.."; status=false;
  18. }
  19. if((mins >= 60 || mins < 0))
  20. {
  21. cout<<"\nInvalid Minutes.."; status=false;
  22. }
  23. if(status)
  24. {
  25. cout<<"\n24 Hours Format\n";
  26. cout << "Hours: " << hours << endl;
  27. cout << "Minutes: " << mins << endl;
  28. cout << "Seconds: " << seconds << endl;
  29. if(hours > 12)
  30. {
  31. hours-=12;
  32. }
  33. cout<<"\n\n12 Hours Format\n";
  34. cout << "Hours: " << hours << endl;
  35. cout << "Minutes: " << mins << endl;
  36. cout << "Seconds: " << seconds << endl;
  37. }
  38. return 0;
  39. }

Output: