Friday, September 5, 2014
COMPRO1 Hands-on Exam (Set A) - Answer Key
Problem:
Write a program to require an integer input between 1 to 10. Vary and display the control variable of a for-loop statement from 1 to 10 and put a dollar sign ($) in place of that number.
Sample Output #1:
Enter a number between 1 and 10: 6
$$$$$6$$$$
Sample Output #2:
Enter a number between 1 and 10: 2
$2$$$$$$$$
Sample Output #3:
Enter a number between 1 and 10: 9
$$$$$$$$9$
Solution:
#include <iostream>
using namespace std;
int main(){
int n;
cout << "Enter a number between 1 and 10: "
cin >> n;
for (int i=1; i<=10; i++)
{
if (n==i)
cout << "$";
else
cout << i;
}
return 0;
}
Viral Stuff and Trending News
Monday, September 1, 2014
Prime Numbers with for Loop
public class GeneratePrimeNo {
public static void main(String[] args) {
int max = 100;
System.out.println("Generate Prime numbers between 1 and " + max);
// loop through the numbers one by one
for (int i = 1; i<max; i++) {
boolean isPrimeNumber = true;
// check to see if the number is prime
for (int j = 2; j < i; j++) {
if (i % j == 0) {
isPrimeNumber = false;
break; // exit the inner for loop
}
}
// print the number if prime
if (isPrimeNumber) {
System.out.print(i + " ");
}
}
}
}
public static void main(String[] args) {
int max = 100;
System.out.println("Generate Prime numbers between 1 and " + max);
// loop through the numbers one by one
for (int i = 1; i<max; i++) {
boolean isPrimeNumber = true;
// check to see if the number is prime
for (int j = 2; j < i; j++) {
if (i % j == 0) {
isPrimeNumber = false;
break; // exit the inner for loop
}
}
// print the number if prime
if (isPrimeNumber) {
System.out.print(i + " ");
}
}
}
}
Sunday, August 31, 2014
Random Password Generator
This is a simple javascript that will generate n number of password with length l. If you think this is useful, please feel free to like my Facebook page or click this link. See the source code below:
<script>
var
keylist="abcdefghijklmnopqrstuvwxyz123456789"
var temp=''
function generatepass(plength,n){
temp='';
for
(j=0;j<n;j++){
for
(i=0;i<plength;i++);
temp+=keylist.charAt(Math.floor(Math.random()*keylist.length));
temp+="<br
/>";
}
return
temp ;
}
function populateform(vlength, n){
document.getElementById("result").innerHTML=generatepass(vlength,n);
}
</script>
<form name="formgen">
<b>Password Length:</b> <input
type="text" name="thelength" size="3"
value="5"><br />
<b>How many Passwords would you like to
generate?:</b> <input type="text" name="num"
size="3" value="1"><br />
<input type="button"
value="Generate Password"
onClick="populateform(this.form.thelength.value,this.form.num.value)"><br
/>
</form>
<div id="result"></div>
<br />
<p >Free Javascript Random Password
Generator<br />Provided by:
<a
href="http://adichosa.blogspot.com">adichosa.blogspot.com</a></p>
For Viral Stuff and Trending News please visit Fooviral.
For Viral Stuff and Trending News please visit Fooviral.
Subscribe to:
Posts (Atom)