shalini_goel14
shalini_goel14
Branch Unspecified
15 Feb 2009

Enhance your programming skills from Scratch

Hi All CEans ,

So you guys don't get enough time to try your hands on programming? No tensions anymore, you will be given a chance here to do simple programming and in return get a surprise every month if your code will be liked.

Rules:
1. No sms language will be allowed
2. You can write your program in any language but expect answers of questions asked here in Java only.
3. Your program should be well compiled and executed.
4. Your program should be well-documented.
5. Your program should be enclosed within CODE tags.
6. Output should also be shown along with your program.
7. Don't make the thread dead.

You will get a surprise after every month.

In the starting programs will given here will be of Level1. Gradually its Level will be increased depending on the response of all CEans here.

Example
Sample Program: Write a Program that prints "Hello World" in console.

/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

package myjava;

/**
 *
 * @author shalinig
 */
public class HelloWorldProgram {

    /**
     * @param args the command line arguments
     */
    public static void main(String[] args) {
        System.out.println("Hello World ");
    }

}
Ouput:
Hello World
Hope you all will enjoy here. 😀
shalini_goel14

shalini_goel14

Branch Unspecified
15 Feb 2009
So strating this thread from a very simple program.😀

Program # 1 : Write a simple program that accepts two numbers from user and print them on console.

All the best to all.
15 Feb 2009
Sorry to interrupt: Is C/C++/PERL/PYTHON allowed? I can do the Program #1 😉
shalini_goel14

shalini_goel14

Branch Unspecified
15 Feb 2009
The_Big_K
Sorry to interrupt: Is C/C++/PERL/PYTHON allowed? I can do the Program #1 😉
@Big_K According to rule no 2, yes allowed. It will be really appreciating if you can write Program # 1 in all 4 languages mentioned by you but yes in 4 different posts.
PS: You need to go for Java class. These languages are too outdated.😉


All CEans,
If you know more than 1 language Please do write the same program in all of those languages. It will be really very helpful to other languages programmers here and will be appreciated lot. Just remember the rules mentioned in my first post. 😀
raj87verma88

raj87verma88

Branch Unspecified
15 Feb 2009
I am not a master of computer languages but I know C and assembly. That is, if Shalini counts them in the category of languages 😛
shalini_goel14

shalini_goel14

Branch Unspecified
15 Feb 2009
raj87verma88
I am not a master of computer languages but I know C and assembly. That is, if Shalini counts them in the category of languages 😛
Yes raj, every language is allowed here if it is possible for you to make that program in your known language.
silverscorpion

silverscorpion

Branch Unspecified
15 Feb 2009
shalini_goel14
PS: You need to go for Java class. These languages are too outdated.😉
Outdated? no way., every language has it's own pros and cons.
I cant accept C as outdated compared to java, because, I don't know Java yet, but I know C quite well..😁😁
shalini_goel14

shalini_goel14

Branch Unspecified
15 Feb 2009
silverscorpion
Outdated? no way., every language has it's own pros and cons.
I cant accept C as outdated compared to java, because, I don't know Java yet, but I know C quite well..😁😁
Don't mind Scorpion if you know C well then why are you taking so much time to write a simple program?Tell?

PS: Don't mind CEans who all know C. I have a question for you. Where were you all when I started following thread? Tell all C users (Big_K, raj, Scorpion and many such...) here hmm?

https://www.crazyengineers.com/forum...ng/13742-do-you-know-how-code-black-jack.html
silverscorpion

silverscorpion

Branch Unspecified
15 Feb 2009
shalini_goel14
Program # 1 : Write a simple program that accepts two numbers from user and print them on console.
Well, here goes my answer in C.

#include<stdio.h>
main()
{
int a,b;                                                         /*Declare variables*/
char c;                
printf("Enter the first number\n");        
scanf("%d",&a);                                             /*input the first number*/
printf("Enter the second number\n");
scanf("%d",&b);                                             /*input second number*/
printf("Do you want to print the numbers?(y/n)");/*asks whether to print or not*/
scanf("%c",&c);
if(c=='y' || c=='Y')
printf("%d\n%d", a,b);                                    /*prints the numbers*/
}

And the ouptut is:

Enter the first number
5
Enter the second number
3
Do you want to print the numbers?(y/n)
y

5
3
raj87verma88

raj87verma88

Branch Unspecified
15 Feb 2009
Because I have already mentioned that I am not a master of computer languages. Just crammed enough C to clear the exams. After the 3rd semester, we have no application of C in the mechanical course.
rohit330

rohit330

Branch Unspecified
17 Feb 2009
//Program to accept two numbers and print the same 

#include<iostream.h>
#include<conio.h>
void main()
{
clrscr(); // clear screen
int a,b;  // declaration
cout<<"ENTER TWO NUMBERS: "; 
cin>>a>>b;
cout<<"\n"; // new line
cout<<a<<b;
getch();
}
[U]output[/U]

ENTER TWO NUMBERS: 3 2

3 2
rohit330

rohit330

Branch Unspecified
17 Feb 2009
//Program to accept two numbers and print the same

#include<stdio.h>
#include<cono.h>
void main()
{
int a,b;  // declaration
clrscr(); //clear screen
printf("ENTER TWO NUMBERS: ");
scanf("%d%d",&a,&b);
printf("\n%d %d",a,b);
getch();
}

[U]output[/U]

ENTER TWO NUMBERS: 3 2

3 2
Raviteja.g

Raviteja.g

Branch Unspecified
17 Feb 2009
import java.io.*;
class first
{
public static void main(String args[ ])
{
InputStreamReader isr=new Inputstreamreader(System.in);
BufferedReader br=new BufferedReader(isr);
System.out.println("enter two numbers");
int a=Integer.parseint(br.readLine( ));
int b=Integer.parseint(br.readLine( ));
System.out.println("if u want to print the numbers? (y/n)");
String option=br.readLine( );
if(option==y)
System.out.println("the numbers are     "+a+"   "+b); 
}
}


/*output is
enter two numbers
2
3
if u want to print the numbers? (y/n)
y
the numbers are     2   3
*/

komputergeek

komputergeek

Branch Unspecified
18 Feb 2009
code in python :
print "Enter two numbers :"
a=input()
b=input()
print "You entered '" , a , "' and '" , b ,"'"
output :
Enter two numbers :
1
2
You entered ' 1 ' and ' 2 '
Ashraf HZ

Ashraf HZ

Communications
18 Feb 2009
Marvel the beauty of Python.
safwan

safwan

Branch Unspecified
18 Feb 2009
shalini_goel14
Hi All CEans ,

So you guys don't get enough time to try your hands on programming? No tensions anymore, you will be given a chance here to do simple programming and in return get a surprise every month if your code will be liked.

Rules:
1. No sms language will be allowed
2. You can write your program in any language but expect answers of questions asked here in Java only.
3. Your program should be well compiled and executed.
4. Your program should be well-documented.
5. Your program should be enclosed within CODE tags.
6. Output should also be shown along with your program.
7. Don't make the thread dead.

You will get a surprise after every month.

In the starting programs will given here will be of Level1. Gradually its Level will be increased depending on the response of all CEans here.

Example
Program #1: Write a Program that prints "Hello World" in console.

/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
 
package myjava;
 
/**
 *
 * @author shalinig
 */
public class HelloWorldProgram {
 
    /**
     * @param args the command line arguments
     */
    public static void main(String[] args) {
        System.out.println("Hello World ");
    }
 
}
Ouput:
Hope you all will enjoy here. 😀
your first program to print message "Hello World"
its here in Visual Basic6.0

Private Sub Form_Load()
MsgBox ("hello World")
End Sub

and out put will be :

in a form
"hello World"
Joe1717

Joe1717

Branch Unspecified
18 Feb 2009
great idea!!
shalini_goel14

shalini_goel14

Branch Unspecified
18 Feb 2009
Well done Scorpion, Rohit,Raviteja,Komputegeek, safwan. I am proud of you guys. 😁. Keep it up. Please if you know any other languages do write your program in that also.


Joe1717
great idea!!
Thanks for good words Joe but where are your programs? 😉
shalini_goel14

shalini_goel14

Branch Unspecified
19 Feb 2009
@safwan : Write the code for following also 😀
Program # 1 : Write a simple program that accepts two numbers from user and print them on console.

Here goes the second program:

Program # 2 Write a simple program(in any computer language) that accepts a number from the user and prints "This is an even number" if the number is even and "This is not an even number" if the number is not even.

All the best to all. Please do mention your name closed in comments at the top of your program.See example shown in first post of this thread. 😀
komputergeek

komputergeek

Branch Unspecified
19 Feb 2009
"""
Program : Write a simple program(in any computer language) that accepts a 
number from the user and prints "This is an even number" if the number is even 
and "This is not an even number" if the number is not even.
Language : Python
Author : komputergeek
"""
print "Enter number :"
num=input()
if num % 2 == 0 :
    print "Number is even"
else:
    print "Number is odd"

"""
Output 1:
Enter number :
43
Number is odd


Output 2:
Enter number :
46
Number is even

"""
shalini_goel14

shalini_goel14

Branch Unspecified
19 Feb 2009
Hi All CEans,

Imp Notice: Please don't forget to mention the language you are using for writing your program along with it.Thanks

@Komputergeek You are doing good job here man. I liked your regularity here. 😀
komputergeek

komputergeek

Branch Unspecified
19 Feb 2009
Thanx shalini :smile:
/*
Program : Write a simple program(in any computer language) that accepts a 
number from the user and prints "This is an even number" if the number is even 
and "This is not an even number" if the number is not even.
Language : Java
Author : komputergeek
*/

import java.util.Scanner;

public class EvenNumber
{    
    public static void main(String args[])
    {
        int num;               //declaration
        Scanner sc=new Scanner(System.in); //create object of scanner class to read input from user
        System.out.print("Enter number : ");
        num=sc.nextInt();               //read int
        if((num % 2)==0)
            System.out.println("Number is even");
        else
            System.out.println("Number is odd");
    }
}

/*
Output 1 :

Enter number : 54
Number is even


Output 2 :

Enter number : 67
Number is odd
*/

safwan

safwan

Branch Unspecified
19 Feb 2009
hi all
@ shallini your given second program is here

To check wherther given no. is even or not

Private Sub cmdcheck_Click()
Dim intnum1 As Integer
'declaration of variable
If intnum1 Mod 2 = 0 Then
Print "Given Number is even"
Else
Print "given number is Odd"
End If
'checking the variables

End Sub

out put is :

2

when user will press check button it will print "Given Number is even"
if user enters 3 then it will print on form "given number is Odd"


i have used visual basic 6.0
and i know only two language
SQL and Basic
rohit330

rohit330

Branch Unspecified
19 Feb 2009
/*Program to check whether the given number is even or not (C++)*/

#include<iostream.h>
#include<conio.h>
void main()
{
clrscr();
int n;
cout<<"Enter the number:";
cin>>n;
if(n%2==0)
cout<<"This is an even number";
else
cout<<"This is not an even number";
getch();
}
[U]OUTPUT[/U]

Enter the number:2
This is an even number

Enter the number:3
This is not an even number

rohit330

rohit330

Branch Unspecified
19 Feb 2009
/*Program to check whether the given number is even or not (C)*/

#include<stdio.h>
#include<conio.h>
void main()
{
int n;
clrscr();
printf("Enter the number: ");
scanf("%d",&n);
if(n%2==0)
printf("This is an even number");
else
printf("This is not an even number");
getch();
}

[U]OUTPUT[/U]

Enter the number:2
This is an even number

Enter the number:3
This is not an even number
shalini_goel14

shalini_goel14

Branch Unspecified
22 Feb 2009
Program # 3 Write a program that check whether the given number is prime number or not. If the number is not a number, it should print desired output. Like if I input a charcater, it should print appropriate message at Console.Overall Your program should work for each and every kind of input appropriately.

Note: Please keep on writing here codes for other Program # 1 and Program # 2 if you know more languages. 😀

PS: At the end of month all the programs by an individual will be considered, not any single one.OK
komputergeek

komputergeek

Branch Unspecified
22 Feb 2009
"""
Program : Write a program that check whether the given number is prime number or not. If the number is
 not a number, it should print desired output. Like if I input a charcater, it should print appropriate message 
at Console.Overall Your program should work for each and every kind of input appropriately.
Language : Python
Author : komputergeek
"""
print "Enter number :"
num=input()    #Take input from user 
flag=True
if num < 0 :
    num = num * -1 ;    # If number is negative,make it possitive so that 
                #program will produce correct output for -ve numbers
for i in range(2,num):
    if (num % i == 0):        #Check whether number is divisible by any other number
        flag=False        #if yes make flag false
        break
if num < 2 :
    flag=False
if flag == True :
    print "Number is prime"
else :
    print "Number is not prime"
"""
Output 1:
Enter number :
68
Number is not prime


Output 2:
Enter number :
67
Number is prime

"""
komputergeek

komputergeek

Branch Unspecified
22 Feb 2009
/*
Program : Write a program that check whether the given number is prime number or
not. If the number is not a number, it should print desired output. Like if I input a
charcater, it should print appropriate message at Console.Overall Your program should
work for each and every kind of input appropriately.
Language : Java
Author : komputergeek
*/

import java.util.Scanner;

public class PrimeNumber
{    
    public static void main(String args[])
    {
        int num;               //declaration
        boolean flag=true;
        Scanner sc=new Scanner(System.in); //create object of scanner class to read
                                               //input from user
        System.out.print("Enter number : ");
        num=sc.nextInt();               //read int
        if (num<0)
            num = num * -1;        //If number is negative,make it possitive so that 
                    //program will produce correct output for -ve numbers
        for(int i=2;i<num;i++)
        {    
                if((num % i) == 0)    //Check whether number is divisible by any other number
                {    
                   flag = false;        //if yes make flag false
                   break;    
                }
        }
        if (num < 2)
            flag=false;
        if (flag == true)
            System.out.println("Number is prime");
        else    
            System.out.println("Number is not prime");
    }
}

/*
Output 1 :

Enter number : 39
Number is not prime


Output 2 :

Enter number : 37
Number is prime

*/
silverscorpion

silverscorpion

Branch Unspecified
22 Feb 2009
This is not the full program right? What if the input is an alphabet?
And what if negative numbers are given? Negative prime numbers are still prime, isn't it?
I'll give my program soon..
komputergeek

komputergeek

Branch Unspecified
22 Feb 2009
What should be the output for alphabets?
komputergeek

komputergeek

Branch Unspecified
22 Feb 2009
I have modified both the programs.Now both are working for negative numbers.
vaibhav agrawal

vaibhav agrawal

Branch Unspecified
23 Feb 2009
shalini_goel14
So strating this thread from a very simple program.😀

Program # 1 : Write a simple program that accepts two numbers from user and print them on console.

All the best to all.
i am not very good in language but i am trying to give your question's answer.
wiil it be ok? if i write in c language............

#include<stdio.h>
#include<conio.h>
void main()
{
int a,b;
printf("enter any two no.\n");
scanf("%d%d",&a,&b);
printf("your entered no are\na=%d and b=%d",a,b);
getch();
}

output:
enter any two no.
5 6
your entered no. are a=5 and b=6
shalini_goel14

shalini_goel14

Branch Unspecified
23 Feb 2009
Well done vaibhav 😀
1. Please use CODE tags symbol(#) given above to enclose your program in CODE block.
2. Don't forget to mention the author's name in your program.
3. Other programs (I mean Program # 2 and Program # 3 ) are also waiting for your code.
4. If you know any other language. Please find out some time to write your program using them also.

😁

Thanks
shalini_goel14

shalini_goel14

Branch Unspecified
26 Feb 2009
[Reminder]
Guys, you all have 2 more days to submit your code here for Program #1, Program # 2 and Program #3 and then finally a surprise for someone(one who has written best code here till 28th Feb) 😁.

So then what are you all waiting for? Go ahead and get a surprise. 😁
CEMember

CEMember

Branch Unspecified
27 Feb 2009
Hi Shalini,

Following is my program in Java 😀

Program # 1 : Write a simple program that accepts two numbers from user and print them on console.

/*
 * Program1Class.java
 *
 * Created on February 27, 2009, 11:01 AM
 */
package myjava;

import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;

/**
 *
 * @author cemember
 */
public class Program1Class {
    
   public static void main(String[] args){
       
      Integer num1, num2=null;
      BufferedReader br=new BufferedReader(new InputStreamReader(System.in));
       try {
            System.out.println("Enter number 1:");
            num1=Integer.parseInt(br.readLine());
            System.out.println("Enter number 2:");
            num2=Integer.parseInt(br.readLine());
            
            System.out.println("Number1= "+num1+" and Number2= "+num2);
        } catch (IOException ex) {
            System.out.println("An IO Exception has occured");  
        }
   }
    
}

Output is:
Enter number 1:
32
Enter number 2:
51
Number1= 32 and Number2= 51
Please check if any corrections is required 😀
CEMember

CEMember

Branch Unspecified
27 Feb 2009
Shalini, here is my Program # 2 in Java only

Program # 2 Write a simple program(in any computer language) that accepts a number from the user and prints "This is an even number" if the number is even and "This is not an even number" if the number is not even.

/*
 * Program2Class.java
 *
 * Created on February 27, 2009, 11:20 AM
 */

package myjava;

import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;

/**
 *
 * @author cemember
 */
public class Program2Class {
    
    public static void main(String arg[]){
        
        String enteredNum=null;
        BufferedReader br=new BufferedReader(new InputStreamReader(System.in));
        System.out.println("Enter any value ");
        try {
            enteredNum= br.readLine();
            Integer enteredNumInInt=Integer.parseInt(enteredNum);
            if(Math.abs(enteredNumInInt)%2==0){
                System.out.println("This is an even number");
            }
            else{
                  System.out.println("This is not an even number");
            }
        } catch (IOException ex) {
            System.out.println("An IO Exception has occured");          
        }catch (NumberFormatException ex) {
            System.out.println("This is an invalid value");
           
        }
        
    }
    
}
Ouput:
Case 1: When entered number is an even number
Enter any value
0
This is an even number
Case 2: When entered number is not an even number
Enter any value
73
This is not an even number
Case 3: When entered value is not a number
Enter any value
a
This is an invalid value
Please check if any corrections are required. 😀
CEMember

CEMember

Branch Unspecified
27 Feb 2009
Shalini, here is my Program # 3 in Java only.

Program # 3 Write a program that check whether the given number is prime number or not. If the number is not a number, it should print desired output. Like if I input a charcater, it should print appropriate message at Console.Overall Your program should work for each and every kind of input appropriately.

/*
 * Program3Class.java
 *
 * Created on February 27, 2009, 11:33 AM
 *
 */
package myjava;
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
/**
 *
 * @author cemember
 */
public class Program3Class {
    
    public static void main(String arg[]){
        
        String enteredNum=null;
        BufferedReader br=new BufferedReader(new InputStreamReader(System.in));
        System.out.println("Enter any value ");
        try {
            enteredNum= br.readLine();
            Integer enteredNumInInt=Integer.parseInt(enteredNum);
            Integer numberToCheck =Math.abs(enteredNumInInt);
            
            /* static boolean expression evaluated outside 'for' loop */
            boolean staticexpr=false;
            /* dynamic boolean expression evaluated inside of 'for' loop */
            boolean dynamicexpr=true;
            
            /* Checks if the number is 1 */
            if(numberToCheck==1){
                System.out.println("1 is neither a composite number nor a prime number");
            } else if(numberToCheck > 1){
                
                
                /* checks if number is divisble by itself and 1 */
                staticexpr=(numberToCheck%numberToCheck==0)&&(numberToCheck%1==0);
                
               /* loop that checks whether the number is
                * divisible by all the numbers less than it
                * excluding itself and 1
                */                
                for(int i=(numberToCheck-1);(i!=0 && i!=1 && i<numberToCheck); i--){
                    
                    if(numberToCheck%i==0){
                        dynamicexpr=false;
                  //if numberToCheck is divisible by any number less than numberToCheck
                        break;
                    }
                    
                }
                if(staticexpr&&dynamicexpr){
                    System.out.println("This is a prime number");
                } else{
                    System.out.println("This is not a prime number");
                }
            } else{
                System.out.println("0 is not a prime number");
            }
        } catch (IOException ex) {
            System.out.println("An IO Exception has occured");
        }catch (NumberFormatException ex) {
            System.out.println("This is an invalid value");
        }
        
    }
    
}
Output:

Case 1: When entered value is not a number
Enter any value
a
This is an invalid value
Case 2: When the number is 0
Enter any value
0
0 is not a prime number
Case 3: When the number is 1
Enter any value
1
1 is neither a composite number nor a prime number
Case 4: When the number is a prime number
Enter any value
17
This is a prime number
Case 5: When the number is not a prime number
Enter any value
57
This is not a prime number
Please check if it fails for any type of input or need any corrections.😀
shalini_goel14

shalini_goel14

Branch Unspecified
27 Feb 2009
Hey Good job CEMember ! 😁 Keep it up

CEMember if you know any other languages, do write your programs in them also.

All CEans, Where are you? Write only 3 simple programs. 2 days left. Come on get a surprise. 😁

[ PS: All the programs will be checked whether they are running or not.]
mayurpathak

mayurpathak

Branch Unspecified
27 Feb 2009
This is a good initiative, although may be I'm commenting too late.
shalini_goel14

shalini_goel14

Branch Unspecified
27 Feb 2009
mayurpathak
This is a good initiative, although may be I'm commenting too late.
Thank you very much Sir 😁
shalini_goel14

shalini_goel14

Branch Unspecified
28 Feb 2009
Notice for all CEans,

Guys few more hours left for you and someone tomorrow will get a surprise for the programs written. This surprise is for month of Feb only. Coming months will have more new programs and more surprises. 😁

So what are you all waiting here, Please write program # 1, Program #2, Program #3 and get a surprise. 😁 So easy to get right? 😉
silverscorpion

silverscorpion

Branch Unspecified
28 Feb 2009
All rightie.. Here are my programs for all the three questions, all three in C++.

Program # 1 : Write a simple program that accepts two numbers from user and print them on console.


#include<iostream.h>
void main()
{
int a,b;                            [COLOR=Red]// Declare two integers[/COLOR]
cin >> a >> b;                     [COLOR=Red]// Get input from user[/COLOR]
cout << a << endl << b;            [COLOR=Red]// print them[/COLOR]
}
[B]OUTPUT:[/B] 
5 3
5
3


Program # 2 Write a simple program(in any computer language) that accepts a number from the user and prints "This is an even number" if the number is even and "This is not an even number" if the number is not even.

#include<iostream.h>
void main()
{
int a;
cin >> a;                                           [COLOR=Red]//Get two integers from user[/COLOR]
if(a%2==0)                                         [COLOR=Red]//Check if it's divisible by two[/COLOR]
cout << "This is an even number";                 [COLOR=Red]// Print if it's even or odd number[/COLOR]
else
cout << "This is not an even number;
}
OUTPUT:
5
This is an not an even number
10
This is an even number
Program # 3 Write a program that check whether the given number is prime number or not. If the number is not a number, it should print desired output. Like if I input a charcater, it should print appropriate message at Console.Overall Your program should work for each and every kind of input appropriately.

#include<iostream.h>
void main()
{
int a,flag=0;
cin >> a;                                              [COLOR=Red]//get the number[/COLOR]
if(cin.fail())                                         [COLOR=Red]//check if the input is a number[/COLOR]
{
cout << "The input is not a number";                  [COLOR=Red]// print an appropriate message[/COLOR]
exit(0);                                                   [COLOR=Red]//exit!![/COLOR]
}
if(a<0) a= -1*a;
if(a==0)
{
cout << "The number is not a prime number";       [COLOR=Red]//if the number is 0 or 1, print corresponding msg[/COLOR]
exit(0);
}
if(a==1)
cout << "The number is neither prime, nor composite";
else
{
for (i=2; i<=a/2; i++)
{
if(a%i==0)
{                                                [COLOR=Red]//Checking if the number is prime(in the for loop)[/COLOR]
flag=1;
cout << "The number is not a prime number";
exit(0)
}
}
}
if(flag==0)
cout << "The number is a prime number";               [COLOR=Red]//and the job is done!! Voila![/COLOR]
}
OUTPUT
a
The input is not a number
23
The number is a prime number
25
The number is not a prime number
Are these correct?? 😁😁
shalini_goel14

shalini_goel14

Branch Unspecified
28 Feb 2009
Good job Scorpion. Keep it up .😁

I am totally confused to select one person over here for giving the surprise 😔.

I am impressed with you all 😁. I wish I can give the surprise to all. 😉
Yamini L

Yamini L

Branch Unspecified
28 Feb 2009
Now i will right all these 3 programs in C....

Program # 1 : Write a simple program that accepts two numbers from user and print them on console.



#include<stdio.h>
void main()
{
int a;
printf("Enter two numbers\n ");//get the number from user
scanf("%d%d\n",&a,&b);
printf("The numbers are %d %d",a,b);//display it 
}

Output
Enter two numbers
5 6
The numbers are 5 6
Program # 2 Write a simple program(in any computer language) that accepts a number from the user and prints "This is an even number" if the number is even and "This is not an even number" if the number is not even.
#include<stdio.h>
void main()
{
int num;
printf("Enter the number\n");//get the number
scanf("%d\n",&num);
if(num%2==0) //check whether its even or odd
{
printf("This is an even number ");
}
else
{
printf("This is not an even number");
}
}
 
output
Enter the number
10
This is an even number

Enter the number
5
This is not an even number

Program # 3 Write a program that check whether the given number is prime number or not. If the number is not a number, it should print desired output. Like if I input a charcater, it should print appropriate message at Console.Overall Your program should work for each and every kind of input appropriately.

#include<stdio.h>
    #include<math.h>
  void  main()
    {
      int i,n,rem,sq;
        printf("enter the number ");
          scanf("%d",&n);
            sq=sqrt(n);
              for(i=2;i<=sq;i++)
                {
                     rem=n%i;
                          if(rem==0)
                      {
       printf("given number is not prime");
              exit(0);
                   }
                     }
                       printf("given number is prime");
                       }
 
output


enter the number 5
given number is prime

enter the number 8
given number is not prime
safwan

safwan

Branch Unspecified
28 Feb 2009
hay wait you are getting so fast i am posting my last programm within an hour .
zia.sepsis

zia.sepsis

Branch Unspecified
28 Feb 2009
Am too late to enter into this competition 😔
safwan

safwan

Branch Unspecified
28 Feb 2009
sorry unable to find how to check wheather user has enterd number or charecter .
programe no. #3 so if any one knows in vb than share it.
shalini_goel14

shalini_goel14

Branch Unspecified
28 Feb 2009
Firstly I am really impressed with you all devoting your efforts and time for this thread. 😁 Thanks to everyone from my side.😁

It was really very difficult for me to decide a single person for the "surprise" but no tensions, those who could not get there is a reason behind it. If you want to know the problem in your program , Feel free to ask here or by PM ok.

Well here goes the summary of who did what in this thread:

Program # 1
Scorpion -C,C++
Rohit- C++
Raviteja- Java
komputergeek -Pyhon
safwan -vb(but not Program #1 rather example program)
vaibhav agarwal -C
CEMember -Java
miniy -C

Program # 2

komputergeek -python, java
safwan -vb,
Rohit - C++, C
CEMember -Java
Scorpion -C++
miniy -C

Program # 3
komputergeek -python
CEMember -Java
SCcrpion -C++
miniy -C

I appreciated programs of everyone here. Being of not CS branch or being only a 12th standard student or being not so much regular member here, you all showed very good efforts. Hats off to you all but still I could not resist my self to give the surprise to "CEMember" who showed great neatness in his programs and showed outputs for wide no of cases.


@CEMember Check your Inbox for the surprise 😁

@Scorpion I liked your Program # 3. A "Dairy Milk" from my side for you. You can send me the bill. 😉

@komputergeek I liked your diversity shown towards programs writing in Java as well as Python. A "Dairy Milk" from my side for you also. You can also send me the bill. 😉

PS: Competition is not yet over. Every month I will give you chance and more the complication involved in the program, more better will be the surprise.

Guys Look at him CEMember, he took the surprise. Common beat him next time in writing programs. Write much better than him and get the surprise next time. 😛

PS I: Do let me know if anyone has any issues with my decision. 😀
PS II: No Congratulations or Thanks or other similar posts in this thread. Use either visitor's message or PM facility to do so 😀
shalini_goel14

shalini_goel14

Branch Unspecified
01 Mar 2009
ok Guys, here goew next program starting the month of march.

Program # 4 Write a program that prints the reverse of the entered string or number in console. If entered value consists of single character, it shoudl display same value in output.

e.g If I enter "Shalini" it prints "inilahS" and if I enter "123" it prints "321" and if I enter "a" or "1" int prints same "a" or "1" in output.

All the best for writing best program. 😀
silverscorpion

silverscorpion

Branch Unspecified
01 Mar 2009
Does the case matter? ie, if you give "Shalini" as inout, should it print "inilahS" or is "inilahs" fine?
And is spaces included in the input??
shalini_goel14

shalini_goel14

Branch Unspecified
01 Mar 2009
silverscorpion
Does the case matter? ie, if you give "Shalini" as inout, should it print "inilahS" or is "inilahs" fine?
And is spaces included in the input??
Very good question-case matters and space is also allowed. 😀
Yamini L

Yamini L

Branch Unspecified
02 Mar 2009
Program # 4 Write a program that prints the reverse of the entered string or number in console. If entered value consists of single character, it shoudl display same value in output.

Here is my code for the fourth program..
PROGRAMMING LANGUAGE USED:C++

Here,i have displayed a menu..User can either select string or number from the options displayed and can get its reverse printed on the screen....

#include<iostream.h>
#include<string.h>
#include<conio.h>
void reverse();//function declaration for finding reverse of a number 
void revstring();//function declaration for finding reverse of string
void main()
{
int n;
char ch;
clrscr();
label:cout<<"\n\n\a\a********************MENU********************\a\a\n\n";        //display menu for the user to select one
cout<<"1.String\n";
cout<<"2.Number\n";
cout<<"\nSelect any one option to print the reverse\n";
cin>>n;
switch(n)
{
case 1:
revstring();          //String Reverse
goto label;
 
case 2:
reverse();        //Number Reverese
goto label;
 
default:
cout<<"\nEnter a valid option\n";                                  //default case if invalid option is selected
cout<<"\nProgram Terminated\n";
getch();
}
}
 
void reverse()
{
long num,s=0,r;
cout<<"\nEnter the number\n";                                    //get the number from user
cin>>num;
while(num>0)
{
r=num%10;
s=(s*10)+ r;                                                               //find the reverse of number
num=num/10;
}
cout<<"The reverse of the number is"<<" "<<s<<endl;     //print the reverse
}
 
void revstring()
{
int l=0,i,j;
char c,str[120],temp[120];
cout<<"enter the string to reverse:";                   //get the string from user
cin.clear();                                                       //clear the error bits for the cin input stream
cin.sync();                                                       //synchronize the input buffer, discarding any leftover characters in the buffer 
cin.getline(str,120);
while(str[l])                                                   //find length of string
{l++;
}
cout<<"\nlength of the string is"<<l<<endl;        //Display string length
j=l;
for (i=0;j>=0;i++,j--)
{
temp[i]=str[j];                                            //reverse string(using another variable)
}
cout<<"Reversed string is"<<" ";                  //display reversed string
for (i=0;i<=l;i++)
{
cout<<temp[i];
}
cout<<endl<<endl;
}
OUTPUT

********************MENU********************
1.String
2.Number
Select any one option to print the reverse //select string
1
enter the string to reverse:a // character input
length of the string is1
Reversed string is a

********************MENU********************
1.String
2.Number
Select any one option to print the reverse //select string
1
enter the string to reverse:YamIni //input with upper and lower cases
length of the string is6
Reversed string is inImaY

********************MENU********************
1.String
2.Number
Select any one option to print the reverse //select string
1
enter the string to reverse:YamInI LakshmIPATHy //input with space
length of the string is19
Reversed string is yHTAPImhskaL InImaY

********************MENU********************
1.String
2.Number
Select any one option to print the reverse //select string
1
enter the string to reverse:miniy is a CRAZY Computer Science ENGINEER
length of the string is42
Reversed string is REENIGNE ecneicS retupmoC YZARC a si yinim

********************MENU********************
1.String
2.Number
Select any one option to print the reverse //select string
1
enter the string to reverse:Crazyengineers provide a common platform for enginee
rs all around the world..Its not about Social Networking..
length of the string is110
Reversed string is ..gnikrowteN laicoS tuoba ton stI..dlrow eht dnuora lla sree
nigne rof mroftalp nommoc a edivorp sreenigneyzarC

********************MENU********************
1.String
2.Number
Select any one option to print the reverse //select number
2

Enter the number //zero as input
0
The reverse of the number is 0

********************MENU********************
1.String
2.Number
Select any one option to print the reverse //single digit number input
2
Enter the number
7
The reverse of the number is 7

********************MENU********************
1.String
2.Number
Select any one option to print the reverse //select number
2
Enter the number
23
The reverse of the number is 32

********************MENU********************
1.String
2.Number
Select any one option to print the reverse //select number
2
Enter the number
345
The reverse of the number is 543

********************MENU********************
1.String
2.Number
Select any one option to print the reverse //select number
2
Enter the number
5698
The reverse of the number is 8965

********************MENU********************
1.String
2.Number
Select any one option to print the reverse //select number
2
Enter the number
45097865 //multidigit number
The reverse of the number is 56879054

********************MENU********************
1.String
2.Number
Select any one option to print the reverse //select number
2
Enter the number
45690
The reverse of the number is 9654

********************MENU********************
1.String
2.Number
Select any one option to print the reverse //invaild option
3

Enter a valid option //alert user
Program Terminated

********************MENU********************
1.String
2.Number
Select any one option to print the reverse //invalid option
An
Enter a valid option //alert user
Program Terminated
shalini_goel14

shalini_goel14

Branch Unspecified
02 Mar 2009
Good job miniy, keep it up.
Raviteja.g

Raviteja.g

Branch Unspecified
03 Mar 2009
i tried to solve in java using reverse( ) method in string handling functions
but last solved in another way
can any one solve this using reverse( ) method
import java.io.*;
import java.util.*;
class rev
{
public static void main(String args[])throws IOException
{
InputStreamReader isr=new InputStreamReader(System.in);
BufferedReader br=new BufferedReader(isr);
System.out.println("enter a string");
String s=br.readLine();
int i=s.length();
System.out.print("OUTPUT :");
for(i--;i>=0;i--)
System.out.print(s.charAt(i));
}
}
and the output is
enter a string
ravi teja
OUTPUT :ajet ivar
Yamini L

Yamini L

Branch Unspecified
04 Mar 2009
Program # 4 Write a program that prints the reverse of the entered string or number in console. If entered value consists of single character, it shoudl display same value in output.

Programming Language Used:JAVA
In this program , i have used StringBuffer class and its inbuilt function reverse() to make the code look simple and short😎..Here is the code..

public class Strev
{
    public static void main(String[] args)
    { 
   String str=args[0];
    String rev= new StringBuffer(str).reverse().toString();
    System.out.println("\nString before reverse: "+str);
    System.out.println("String after reverse: "+rev);
  }     
}  

Output

C:\Documents and Settings\USER1\Desktop>javac Strev.java

C:\Documents and Settings\USER1\Desktop>java Strev "YamiNI" //input with mixed cases

String before reverse: YamiNI
String after reverse: INimaY

C:\Documents and Settings\USER1\Desktop>java Strev "Yamini LaksHMIPATHy" //input with space

String before reverse: Yamini LaksHMIPATHy
String after reverse: yHTAPIMHskaL inimaY

C:\Documents and Settings\USER1\Desktop>java Strev "1234" //number input

String before reverse: 1234
String after reverse: 4321

C:\Documents and Settings\USER1\Desktop>java Strev "10203330"

String before reverse: 10203330
String after reverse: 03330201

C:\Documents and Settings\USER1\Desktop>java Strev "9"

String before reverse: 9
String after reverse: 9

C:\Documents and Settings\USER1\Desktop>java Strev "a" //character input

String before reverse: a
String after reverse: a
shalini_goel14

shalini_goel14

Branch Unspecified
04 Mar 2009
Superb yamini 😁 !!!

I don't have words in your praise.😁
safwan

safwan

Branch Unspecified
05 Mar 2009
programm no.#4

in visual basics 6.0

 Private Sub Command1_Click()
Dim num As Integer, rnum As Integer, d As Integer
 'declaring the variables
 
num = Val(txtnum.Text)
 'converting the text into number
 
rnum = 0 ' initialising the reverse number with zero
Do While num > 0  'initialising the loop checking the condition.
 d = num Mod 10
 rnum = rnum * 10 + d
 num = num / 10
Loop
 txtrnum.Text = rnum ' displaying the result in concerned text
 
 
End Sub

and the output will be
  when we will enter 1234 
it will show  4321 
shalini_goel14

shalini_goel14

Branch Unspecified
07 Mar 2009
OK Guys, Here I am adding one more simple program to March's list .😀

Program # 5 Write a program that will calculate both the square and cube of any input number and print it on console. Again check for non numeric numbers also.
Yamini L

Yamini L

Branch Unspecified
07 Mar 2009
Program # 5 Write a program that will calculate both the square and cube of any input number and print it on console. Again check for non numeric numbers also..


PROGRAMMING LANGUAGE:JAVA

Here is a simple code to print the square and cube of a number..
It also checks for non numeric characters..

import java.io.*;
class Sqcu
{
public static void main(String args[]) throws IOException
{
try
{
System.out.println("*************MENU******************");
System.out.println("!.Square");                [COLOR=red]//display menu[/COLOR]
System.out.println("2.Cube");
System.out.println("Enter your choice");   [COLOR=red]//get the choice[/COLOR]
DataInputStream di=new DataInputStream(System.in);
int choice=Integer.parseInt(di.readLine());
switch(choice)
{
 
case 1:
System.out.println("Enter the number");  [COLOR=red]//get the number from user[/COLOR]
DataInputStream dis=new DataInputStream(System.in);
double x= Float.parseFloat(dis.readLine());
System.out.println("Square of number is " +(x*x)); [COLOR=red]//print the square[/COLOR]
break;
 
case 2:
System.out.println("Enter the number"); [COLOR=red]//get the number from user[/COLOR]
DataInputStream d=new DataInputStream(System.in);
double y= Float.parseFloat(d.readLine());
System.out.println("Cube of number is " +(y*y*y)); [COLOR=red]//print cube[/COLOR]
break;
 
default:
System.out.println("Enter a valid choice");  [COLOR=red]//default case[/COLOR]
System.out.println("Program terminated");
}
}
catch(Exception e){
System.out.print(e.getMessage());
System.out.println("is not a numberic value");[COLOR=red] //print message[/COLOR]
System.out.println("Enter a valid number");
}
}
}

OUTPUT

C:\Documents and Settings\USER1\Desktop>java Sqcu
*************MENU******************
!.Square
2.Cube
Enter your choice //select square
1
Enter the number
10
Square of number is 100.0

C:\Documents and Settings\USER1\Desktop>java Sqcu
*************MENU******************
!.Square
2.Cube
Enter your choice //select square
1
Enter the number
5.77
Square of number is 33.29289977989197


C:\Documents and Settings\USER1\Desktop>java Sqcu
*************MENU******************
!.Square
2.Cube
Enter your choice //select cube
2
Enter the number
7
Cube of number is 343.0

C:\Documents and Settings\USER1\Desktop>java Sqcu
*************MENU******************
!.Square
2.Cube
Enter your choice //select cube
2
Enter the number
9.99
Cube of number is 997.0029304727112

C:\Documents and Settings\USER1\Desktop>java Sqcu
*************MENU******************
!.Square
2.Cube
Enter your choice
1
Enter the number //non numeric input
e
For input string: "e"is not a numberic value
Enter a valid number

C:\Documents and Settings\USER1\Desktop>java Sqcu
*************MENU******************
!.Square
2.Cube
Enter your choice
2
Enter the number //non numeric input
rt
For input string: "rt"is not a numberic value
Enter a valid number

C:\Documents and Settings\USER1\Desktop>java Sqcu
*************MENU******************
!.Square
2.Cube
Enter your choice //invalid choice
4
Enter a valid choice
Program terminated
shalini_goel14

shalini_goel14

Branch Unspecified
08 Mar 2009
Hey Scorpion, komputergeek, CeMember , safwan- Where are your programs? I am waiting for your programs .Don't want any surprises? 😔

Please post your programs here guys. 😀
safwan

safwan

Branch Unspecified
09 Mar 2009
Program # 5 Write a program that will calculate both the square and cube of any input number and print it on console. Again check for non numeric numbers also.

For this programe i took
two option butoons
two command buttons
two textboxes

the code for this programe is
 Sub find()
 'programmed by safwan
 ' program to find square and cube of given number
 ' this is subroutin and which will find out wheathre
 'programm has to find out cube or sqaure
 ' you can freely distribute this programm no copyright.
 ' sifus.
 Dim intnum As Integer, intcube As Integer, intsqr As Integer
 intnum = Val(txtnum.Text)
 
 
 If optsq.Value = True Then
    intsqr = intnum * intnum
    txtop.Text = intsqr
 ElseIf optcub.Value = True Then
   intcube = intnum * intnum * intnum
   txtop.Text = intcube
 End If
 
 
 
 
End Sub
Private Sub cmdclear_Click()
'this will clear all text boxes and option buttons
txtop.Text = " "
txtnum.Text = " "
optcub.Value = False
optsq.Value = False
End Sub
Private Sub cmdfind_Click()
' we are calling the subroutine
Call find
End Sub
and the out put is
 when i input 5 into first textbox
and if we chose square optionbutton then 
output will be 25
when i chose cube optionbutton then 
other textbox will show me 125.
Note: this programme is written in visual basic 6.0
Note : sorry unable to chechk wheather given charecter is numeric or alphabatic.
silverscorpion

silverscorpion

Branch Unspecified
09 Mar 2009
Program # 5 Write a program that will calculate both the square and cube of any input number and print it on console. Again check for non numeric numbers also.

Language: C

#include<stdio.h>
main()
{
float a;
int x;
printf("Enter a number");
x=scanf("%f", &a);
if(x==1)
{
printf("The square of the number is %f\n", a*a);
printf("The cube of the number is %f\n", a*a*a);
}
else if(x==0)
{
printf("The input is non-numeric");
}

OUTPUT:
Case 1
Enter a number: 5.5
The square of the number is 30.250000
The cube of the number is 166.375000

Case 2
Enter a number: 8
The square of the number is 64.000000
The cube of the number is 512.000000

Case 3
Enter a number: a
The input is non-numeric

Case 4
Enter a number: 5.5r
The input is non-numeric
silverscorpion

silverscorpion

Branch Unspecified
09 Mar 2009
Program # 5 Write a program that will calculate both the square and cube of any input number and print it on console. Again check for non numeric numbers also.

Language: C++

#include<iostream.h>
void main()
{
float a;
int x;
cout<<"Enter a number";
cin>>a;
if(cin.fail())
{
cout<<"Invalid input";
exit(0);
}
else
{
cout<<"The square of the number is "<< a*a << endl;
cout<<"The cube of the number is "<< a*a*a << endl;
}
OUTPUT:

Case 1
Enter a number: 6.3
The square of the number is 39.690000
The cube of the number is 250.047000

Case 2
Enter a number: 7
The square of the number is 49.000000
The cube of the number is 343.000000

Case 3
Enter a number: abcde
Invalid input

Case 4
Enter a number: 523.5r3fer
Invalid input
silverscorpion

silverscorpion

Branch Unspecified
09 Mar 2009
Program # 4 Write a program that prints the reverse of the entered string or number in console. If entered value consists of single character, it shoudl display same value in output.

LANGUAGE : C

#include<stdio.h>
main()
{
char a[50];
int i,l
printf("Enter a string");
gets(a);
for(i=1; a[i]!='\0'; i++);
l=i;
printf("The length of the string is %d\n", l;
printf("The reversed string is\n");
for(i=l-1; i>=0)
printf("%c",a[i]);
}

OUTPUT

Case 1: Only lower case alphabets and special characters
Enter a string: ce rocks!!

The length of the string is 10
The reversed string is
!!skcor ec

Case 2: Upper and lower case letters
Enter a string: CE RoCkS!!

The length of the string is 10
The reversed string is
!!SkCoR EC

Case 3: Alphabets and numbers
Enter a string: 123 RAM 456 !!!

The length of the string is 15
The reversed string is
!!! 654 MAR 321

Case 4: only numbers
Enter a string: 1234567890

The length of the string is 10
The reversed string is
0987654321
silverscorpion

silverscorpion

Branch Unspecified
09 Mar 2009
I'm thinking of writing these programs in MATLAB. Is it allowed? MATLAB is strictly not considered a programming language. It's a computational tool. So..??!!
shalini_goel14

shalini_goel14

Branch Unspecified
09 Mar 2009
@Scorpion

If you don't have any issues and it is possible to do in it -share it in MATLAB also. Those who don't know that , may get benefits 😀
Yamini L

Yamini L

Branch Unspecified
09 Mar 2009
Program # 5 Write a program that will calculate both the square and cube of any input number and print it on console. Again check for non numeric numbers also.


Programming Language:C
Here user needs to specify upto what number he wants square and cube to be displayed..It also checks for non numeic characters..

#include<stdio.h>
#include<ctype.h>
#include<math.h>
#include<conio.h>
void main()
{
int n,i,s,c;
clrscr();
printf("Enter the number upto which you want to display square and cube\n");              [COLOR=red]//get the number[/COLOR]
scanf("%d",&n);
if(isalpha(n))        [COLOR=red]//check whether it is an alphabet[/COLOR]
{
printf("enter a numeric character\n"); 
}
else
{
printf("\tNUMBER\tSQUARE\tCUBE\t\n"); 
for(i=0;i<=n;i++)
{
s=pow(i,2);
c=pow(i,3);
printf("\t%d\t%d\t%d\t\n",i,s,c );  [COLOR=red]  //print square and cube[/COLOR]
}}
getch();
}
Output
Enter the number upto which you want to display square and cube
9 //numeric input
NUMBER SQUARE CUBE
0 0 0
1 1 1
2 4 8
3 9 27
4 16 64
5 25 125
6 36 216
7 49 343
8 64 512
9 81 729



Enter the number upto which you want to display square and cube
ere //non numeric input
enter a numeric character

PS:As per the progam,we will get a formatted output..But here numbers are not displayed in order..While posting,format is changing.i dont know why..😕
silverscorpion

silverscorpion

Branch Unspecified
09 Mar 2009
That's because, when responding to a post, CE will ignore white spaces. That's why!! But it's ok, dont worry.
Yamini L

Yamini L

Branch Unspecified
09 Mar 2009
I was not aware of that fact..anyways,thanks for the info scorpion😀
shalini_goel14

shalini_goel14

Branch Unspecified
17 Mar 2009
Here goes the another program for the followers of this thread-

Program # 6 Write a program that accepts a number from user and then find out all the prime numbers between 1 and the input no. Ex user enters 100 as a number , then program should calculate all the prime numbers between 1 and 100.
Ashutosh_shukla

Ashutosh_shukla

Branch Unspecified
21 Mar 2009
Solution for Problem#6 in Java
/*
File Name: Main.java
@Author: Ashutosh Shukla
*/
import java.io.*;
class Main
{
	public static void main(String args[])
	{
		int number=0,i,j;

		//Loop to read from user till number is greater than or equal to 2
		do
		{
			try
			{
				System.out.print("Enter the number : ");
				BufferedReader br=new BufferedReader(new InputStreamReader(System.in));
				number=Integer.parseInt(br.readLine());
			}
			catch(Exception e)
			{
				e.printStackTrace();
			}
		}
		while(number<=1);
		System.out.println("The various prime nos between 1 and "+number+" are : ");

		//Loop to check for each and every number
		for(i=2;i<number;i++)
		{
			//Loop to check whethar the number is prime or not
			for(j=2;j<i;j++)
			{
				if(i%j==0)
					break;
			}
			if(j==i)
				System.out.print(i+" ");
		}
		System.out.println();
	}
}
Sample Output:
Enter the number : 45
The various prime nos between 1 and 45 are :
2 3 5 7 11 13 17 19 23 29 31 37 41 43
Press any key to continue . . .
Ashutosh_shukla

Ashutosh_shukla

Branch Unspecified
21 Mar 2009
Solution of Problem#1 in C++
/*@Author: Ashutosh*/
#include<iostream.h>
#include<conio.h>
void main()
{
	int n1,n2;
	clrscr();
	cout<<"Enter N1 : ";
	cin>>n1;
	cout<<"Enter N2: ";
	cin>>n2;
	cout<<"The entered numbers are : "<<n1<<" and "<<n2;
	getch();
}
Sample Output:
Enter N1 : 3
Enter N2 : 4
The entered numbers are 3 and 4
shalini_goel14

shalini_goel14

Branch Unspecified
21 Mar 2009
Welcome back to CE Ashutosh 😁

If you want to get the surprise for the month of April in this thread. Please do share the code for Program # 4 and Program # 5 also.

Thanks
Ashutosh_shukla

Ashutosh_shukla

Branch Unspecified
21 Mar 2009
Solution of Program#2 in C++
/*@Author: Ashutosh*/
#include<iostream.h>
#include<conio.h>
void main()
{
	int n;
	clrscr();
	cout<<"Enter any number : ";
	cin>>n;
	if(n%2==0)
		cout<<"The number is even number.";
	else
		cout<<"The number is not even an number.";
	getch();
}
Sample Output:
Enter any number : 2
The number is even number.
Ashutosh_shukla

Ashutosh_shukla

Branch Unspecified
21 Mar 2009
Well the Problem#4 is quite simple if you want as follows in C++ using <string.h>:
#include<iostream.h>
#include<conio.h>
#include<string.h>
void main()
{
	char str[80];
	cout<<"Enter any string : ";
	cin>>str;
	cout<<"The reverse is : "<<strrev(str);
	getch();
}
Sample Output:
Enter any string : Shalini
The reverse is : inilahS

Well if you want to do reverse yourself then go long way by reading it and print it in reverse order or simply swap first half with latter half
Ashutosh_shukla

Ashutosh_shukla

Branch Unspecified
21 Mar 2009
Problem#5 in C++
#include<iostream.h>
#include<conio.h>
#include<ctype.h>
void main()
{
	int n;
	clrscr();
	cout<<"Enter any number : ";
	cin>>n;
	if(!isalnum(n))
	{
		cout<<"The sqaure of number is : "<<n*n;
		cout<<"\nThe cube of number is : "<<n*n*n;
	}
	else
		cout<<"Invalid number.";
	getch();
}
Sample Output:
Enter any number : 5
The square of number is : 25
The cube of number is : 125
shalini_goel14

shalini_goel14

Branch Unspecified
21 Mar 2009
Wow, very good Ashutosh 😁 but I could not see your Program # 3 code.
Yamini L

Yamini L

Branch Unspecified
22 Mar 2009
Program # 6 Write a program that accepts a number from user and then find out all the prime numbers between 1 and the input no. Ex user enters 100 as a number , then program should calculate all the prime numbers between 1 and 100.



Programming Language:JAVA

import java.io.*;
class prime
{
public static void main(String args[])
{
try
{
System.out.println("Enter the last number");                               [COLOR=red]//get input from user[/COLOR]
DataInputStream dis=new DataInputStream(System.in);
int n=Integer.parseInt(dis.readLine());
int i,num=1;
while(num<=n)               
{
i=2;
while(i<=num)
{
if(num%i==0)                                                                          [COLOR=red]//check whether is number is prime or not[/COLOR]
break;
i++;
}
if(i==num)
System.out.println( "  " +num+ "is a Prime Number");            [COLOR=red]//display if number is prime[/COLOR]
num++;                                                   
}
}
catch (Exception e){}
}
}

Output
C:\Documents and Settings\USER1\Desktop>java prime
Enter the last number
25
2is a Prime Number
3is a Prime Number
5is a Prime Number
7is a Prime Number
11is a Prime Number
13is a Prime Number
17is a Prime Number
19is a Prime Number
23is a Prime Number
safwan

safwan

Branch Unspecified
26 Mar 2009
programe #6 in visual basic 6.0


Private Sub Form_Load()
 'this programm is program to find prime noumbers till
 '100
 'This programe is programmed and coded by
 'Safwan patel
 'you can share this programm no copyrights
 
MsgBox ("PLease enter any noumber under 100 for finding prime no.")
MsgBox ("this programm will find prime noumbers under 100")
End Sub
Private Sub cmdFind_Click()
 ' this code is 4 event when user will click this button
 Dim inti As Integer, intnum As Integer
  ' data verification related to use
  intnum = Val(txtnum.Text)
   ' converts text into number and take it in use
  List1.AddItem 1
  List1.AddItem 2
  List1.AddItem 3
  List1.AddItem 5
  List1.AddItem 7
   ' we are adding this abouve itemes in list1 as
   'we know already this noumbers are prime
   'and also we dont want to waset pc time
 For inti = 4 To intnum Step 1
 
 
 
    If inti Mod 2 = 0 Then  'we are moving all no. which are divisible by 2
      List2.AddItem inti
    Else
         If inti Mod 3 = 0 Then 'after taking all odd no.
                                'we are moving all no. which are divisible by 3
            List2.AddItem inti
         Else
              If inti Mod 5 = 0 Then
                 'agin we are moving all no. which are divisible by 5
                List2.AddItem inti
              Else
                   If inti Mod 7 = 0 Then
                     ' we are moving all no. which are divisible by 7
 
                      List2.AddItem inti
                   Else
                       If inti Mod 9 Then
                        'agin we are moving all no. which are divisible by 9
                          List2.AddItem inti
                       Else
                            List1.AddItem inti
                       End If
                  End If
              End If
         End If
    End If
Next inti
 
 
 
End Sub
 
 
when i insert 30 in text bos the result will be :
1
1
2
3
5
7
11
13
17
19
23
29
 
komputergeek

komputergeek

Branch Unspecified
29 Mar 2009
Program # 6 Write a program that accepts a number from user and then find out all the prime numbers between 1 and the input no. Ex user enters 100 as a number , then program should calculate all the prime numbers between 1 and 100.

"""
Program : Write a program that accepts a number from user and then find out all the 
prime numbers between 1 and the input no. Ex user enters 100 as a number , then 
program should calculate all the prime numbers between 1 and 100.
Language : Python
Author : komputergeek
"""
print "Enter number 1 :"
num1=input()    #Take input from user 
if type(num1).__name__ != 'int' :     #Check whether the number is integer
    print "Not a number"
    quit()
print "Enter number 2 :"

num2=input()    #Take input from user
if type(num2).__name__ != 'int' :    #Check whether the number is integer
    print "Not a number"
    quit()

print "Prime numbers in range : "

for j in range(num1,num2):    #Run loop for all numbers in accepted range
    flag=True
    for i in range(2,j):
        if (j % i == 0):        #Check whether number is divisible by any other number
            flag=False        #if yes make flag false
            break
    if j < 2 :
        flag=False
    if flag == True :
        print j
"""
Output :


Enter number 1 :
2
Enter number 2 :
30
Prime numbers in range : 
2
3
5
7
11
13
17
19
23
29

"""
shalini_goel14

shalini_goel14

Branch Unspecified
29 Mar 2009
Common guys , you have 3 more days left to write 3 programs and getting the surprise. 😀

@CEMember- What happened to you man? Where are you? Not happy with the surprise 😔. No programs this time?

@Komputergeek - Man! Well done,Can you start a class or a thread on Python? I want to learn it? 😀 By the way, I could not see your Program # 4 and Program # 5(March's surprise list programs) 😉

@safwan Good work going but you need to learn either of C, C++ and Java. This VB is not going to take you anywhere. Post your problem in program#6 in separate thread. VB users will correct it there. 😀
komputergeek

komputergeek

Branch Unspecified
29 Mar 2009
shalini_goel14
@Komputergeek - Man! Well done,Can you start a class or a thread on Python?
Nice suggestion.I will think of it but after some days...
komputergeek

komputergeek

Branch Unspecified
29 Mar 2009
Program # 5 Write a program that will calculate both the square and cube of any input number and print it on console. Again check for non numeric numbers also.

"""
Program : Write a program that will calculate both the square and cube of any input 
number and print it on console. Again check for non numeric numbers also.
Language : Python
Author : komputergeek
"""
print "Enter number :"
num=input()    #Take input from user 
if type(num).__name__ != 'int' :     #Check whether the number is integer
    print "Not a number"
    quit()
print num, "^2 = " , num*num
print num, "^3 = " , num*num*num
"""
Output 1 :

Enter number :
3
3 ^2 =  9
3 ^3 =  27

Output 2 :

Enter number :
1
1 ^2 =  1
1 ^3 =  1

Output 3 :

Enter number :
101
101 ^2 =  10201
101 ^3 =  1030301

"""
komputergeek

komputergeek

Branch Unspecified
29 Mar 2009
Program # 4 Write a program that prints the reverse of the entered string or number in console. If entered value consists of single character, it shoudl display same value in output.

"""
Program : Write a program that prints the reverse of the entered string or number in 
console. If entered value consists of single character, it should display same value in 
output.
Language : Python
Author : komputergeek
"""
str=raw_input("Enter string :")    #Take input from user 
str2=""
for i in range(len(str)-1,-1,-1):
    str2 = str2 + str[i]
print "Reverse is : ", str2
"""
Output 1 :

Enter string :python
Reverse is :  nohtyp

Output 2 :

Enter string :1
Reverse is :  1

"""
shalini_goel14

shalini_goel14

Branch Unspecified
30 Mar 2009
@MODS/CE TEAM(having enough powers) A request(though reported through spam option also but no action taken yet 😡) - Please move the last post made by Mr "yamrajbhalla" in a separate thread. It is irrelevant in this thread.He/she has posted a program for Complex umbers which no one asked him to do here.

@yamrajbhalla Kindly see the thread purpose and your post purpose. If both matches then only make posts in the thread else start a new thread. OK

Thanks a ton 😐
shalini_goel14

shalini_goel14

Branch Unspecified
31 Mar 2009
Well done Guys !

So here goes the quick summary of who did what in March here:

Program # 1
Ashutosh -C++ (late reply)

Program # 2
Ashutosh - C++(late reply)

Program # 4
Miniy- C, Java
Raviteja -Java
safwan - VB
Scorpion - C
Ashutosh - C++
komputergeek -Python

Program # 5
Miniy- C, Java
safwan - VB
Scorpion - C, C++
Ashutosh- C++
komputergeek -Python

Program # 6
Ashutosh - Java
Miniy- Java
safwan - VB(not working)
komputergeek -Python

So after looking at the consistency of using same language for all 3 programs despite of its advantages and disadvantages unlike Ashutosh(who didn't maintain consistent use of C++ in all 3 programs) and keeping in mind about neatness of your code, I would like to give surprise to 2 people this time as for April there will be no programs due to some unavoidable circumstances , so surprise goes to

@komputergeek - Congrats !you get surprise + your last time due Dairy Milk
@Miniy -Congrats ! You also get the surprise.

Both of you , Please check your PM and reply me soon. 😀

Note: Guys ! These surprises are not as big as CEoM get, so Please don't leave your programming part even after not liking surprises unlike CEMember OK. I don't know why this time he didn't post his programs. 😔

@Others - This programming part is not yet over, you will again get the chance in May. 😀

Thanks
safwan

safwan

Branch Unspecified
01 Apr 2009
now MY programe #6 is working i got the result. thanks to MAro. (no problem i got it late i am not sad i am happy becous i got some thing to learn.
shalini_goel14

shalini_goel14

Branch Unspecified
02 Apr 2009
livewire09
Yes for programming the basics play a lot of importance.So it is right to understand the roots of the language and then get on with the rest....
Hey livewire ! Thanks a lot for the tip.
safwan

safwan

Branch Unspecified
06 Apr 2009
hay shalini , when new programe you are going to post i am waiting for it?
shalini_goel14

shalini_goel14

Branch Unspecified
07 Apr 2009
safwan
hay shalini , when new programe you are going to post i am waiting for it?
Hey safwan, no programs this month because I will not be able to check them. 😔
slashfear

slashfear

Branch Unspecified
14 Apr 2009
Hey Shalini!!!

Sorry I dropped in late i belive any way here is my versions of Solutions in C++! 😔
slashfear

slashfear

Branch Unspecified
14 Apr 2009
Program # 1 : Write a simple program that accepts two numbers from user and print them on console.

/* Program is written by: Arvind Kumar
Language used: C++
*/

#include<iostream>

using namespace std;

bool Yes() ;

int main()
{
int a,b;
cout << "Enter First numbers: ";
cin>>a;
cout<<"Enter Second numbers: ";
cin>>b;

if(Yes())
{
cout << "\nThe First number you entered is:" <<a<<endl;
cout << "The Second number you entered is:" <<b<<endl;
}
else
{
cout << "Thank you for using our program : )" << endl ;
}
return 0 ;
}

bool Yes()
{
char x[2] ;

while(true)
{
cout << "\nPlease enter (y) for yes or (n) for no:" << endl ;

cin >> x ;

if(x[1] == '\0')
if(x[0] == 'y' || x[0] == 'Y' || x[0] == 'n' || x[0] == 'N')
if(x[0] == 'y' || x[0] == 'Y')
return true ;
else return false ;
cout << "Error!\n " ;
}
}
slashfear

slashfear

Branch Unspecified
14 Apr 2009
Program # 2 Write a simple program(in any computer language) that accepts a number from the user and prints "This is an even number" if the number is even and "This is not an even number" if the number is not even.


/* Program is written by: Arvind Kumar
   Language used: C++
*/


#include <iostream>
using namespace std;

int main ()
{
    int a;
  cout << "Please enter an integer to check if it's EVEN or ODD: ";     
  cin >> a;                     

  if ( a % 2== 0 )   

       cout << "\nThe number you entered is '"<< a << "' and it is a EVEN number" <<endl;
  else               

       cout << "\nThe number you entered is '"<< a << "' and it is a ODD number  "<<endl;

  return 0;
}
slashfear

slashfear

Branch Unspecified
14 Apr 2009
Program # 3 Write a program that check whether the given number is prime number or not. If the number is not a number, it should print desired output. Like if I input a charcater, it should print appropriate message at Console.Overall Your program should work for each and every kind of input appropriately.

/* Program is written by: Arvind Kumar
   Language used: C++
*/

#include <iostream>
#include <limits>

using namespace std;
int main()
{
int no,i;

cout<<" Enter a Number to check if it's prime number or not: ";
cin>>no;

  cin.ignore(numeric_limits<int>::max(), '\n');

  if (!cin || cin.gcount() != 1)
  {
    cout << "\n Error: Your input is not a numeric value!!!! ";
    cout<<"\n\n The Possible cause of this ERROR could be one of the following:";
    cout<<"\n\t -You could have Entered a Charatcter";
    cout<<"\n\t -You could have Entered a symbol like @,#,$";
    cout<<"\n\t -If you have Entered a decimal value then it would be rounded off and will get the output";
  }
  else
    cout << "\nYour entered number: " << no;

if(no==1)
{
    cout<<"\nThe number '"<<no<<"' is neither prime nor composite";
}

i=2;
while(i<=no-1)
{
if(no%i==0)
  {
    cout<<"\nThe number '"<<no<<"' is not a PRIME number";
    break;
  }
i=i+1;
}
if(no==i)
{
  cout<<"\nThe number '"<<no<<"' is a PRIME number";
}

return 0;
}
slashfear

slashfear

Branch Unspecified
14 Apr 2009
Program # 4 Write a program that prints the reverse of the entered string or number in console. If entered value consists of single character, it shoudl display same value in output.

/* Program is written by: Arvind Kumar
   Language used: C++
*/
#include <string>
#include <iostream>
#include <algorithm>
using namespace std;

int main()
{
    string rev;
    cout<<"Enter any data you want to print in reverse order: ";
    cin>> rev;
    cout<<"Here is the data you have entered: ";

    string s(rev.begin(),rev.end());
    // iterate through all of the characters
    string::iterator pos;
    for (pos = s.begin(); pos != s.end(); ++pos)
    {
        cout << *pos;
    }
    cout << endl;
    reverse (s.begin(), s.end());
    cout << "Here is the reverse of the data you entered: " << s << endl;

}
slashfear

slashfear

Branch Unspecified
14 Apr 2009
Program # 5 Write a program that will calculate both the square and cube of any input number and print it on console. Again check for non numeric numbers also.

/* Program is written by: Arvind Kumar
   Language used: C++
*/
#include<iostream>
#include <limits>

using namespace std;

int main()
{
    int a;
    cout<<"Enter the number to find the square and cube of the number: ";
    cin>>a;

  cin.ignore(numeric_limits<int>::max(), '\n');

  if (!cin || cin.gcount() != 1)
  {
    cout << "\n Error: Your input is not a numeric value!!!! ";
    cout<<"\n\n The Possible cause of this ERROR could be one of the following:";
    cout<<"\n\t -You could have Entered a Charatcter";
    cout<<"\n\t -You could have Entered a symbol like @,#,$";
    cout<<"\n\t -You could have Entered a decimal value";
  }

else
{
    cout<<"\nThe square of the number is: "<<a*a<<endl;
    cout<<"\nThe cube of the number is: "<<a*a*a<<endl;
}
    return 0;
}
slashfear

slashfear

Branch Unspecified
14 Apr 2009
Program # 6 Write a program that accepts a number from user and then find out all the prime numbers between 1 and the input no. Ex user enters 100 as a number , then program should calculate all the prime numbers between 1 and 100.

/* 
   Program is written by: Arvind Kumar
   Language used: C++
*/
#include <iostream>
#include <limits>

using namespace std;
int main()
{
int no,i;
int ch;

cout<<" Enter the range of MAX Number of Prime numbers you want to generate : ";

    cin>>no;
    cout <<"\n You want Prime numbers between the range of '1 - " << no<<"'"<<endl;
    cout<<"\n Here is the list of PRIME numbers you wanted:"<<endl<<endl;

for(ch=1;ch<=no;ch++)
{


if(ch==1)
{
    cout<<"\t"<< ch<<" is neither prime nor composite"<<endl;
}

i=2;
while(i<=ch-1)
{
if(ch%i==0)
  {
    break;
  }
i=i+1;
}
if(ch==i)
{
  cout<<"\t"<< ch<<" is a PRIME number"<<endl;
}
}
return 0;
}
slashfear

slashfear

Branch Unspecified
14 Apr 2009
Alright so its done so whens the next programs going to be posted buddy!! I am waiting...........................
safwan

safwan

Branch Unspecified
16 Apr 2009
goyal786
here is a program by me
#include<iostream.h>
#include<conio.h>
int main()
{
clrscr();
int a,b;
char c;
cout<<"Enter two no's which you like to print"<<endl;
cin>>a;
cin>>b;
cout<<"Two no's are"<<endl;
cout<<a<<" "<<b;
getch();
}
output
Enter two no's which you like to print
2
3
Two no's are
2 3
brother Please keep your code and out put in quet tag. 😉
Please read first post of this thread there are some instructions are given for posting in this thread.
madhumurundi

madhumurundi

Branch Unspecified
26 Apr 2009
hi, shalini can i have your email id plz..i need guidence from you about some courses..plz..you can send me a test mail to this id--> <removed>
shalini_goel14

shalini_goel14

Branch Unspecified
04 May 2009
Here goes the next two simple programs for month of "May"

Program # 7 Write a program to find out the factorial of any input number without recursion.

Program # 8 Write a program to find out the factorial of any input number using recursion.
slashfear

slashfear

Branch Unspecified
04 May 2009
shalini_goel14
Here goes the next two simple programs for month of "May"

Program # 7 Write a program to find out the factorial of any input number without recursion.

Program # 8 Write a program to find out the factorial of any input number using recursion.

Hey Shalini,

Here is my version of solution's in C++

Program # 7 : Write a program to find out the factorial of any input number without recursion.

 
/* Written by : Arvind (slashfear)
   Language: C++  */

#include <iostream>
using namespace std;

int factorial(int n)
{
   int result = 1;
   for (int i = n; i > 0; i--)
   result = result * i;
   return result;
}

main()
{
    int n;
    cout << "Enter a non-negative integer: ";
    cin >> n;
    cout << "Factorial of " << n << " is " << factorial(n) << endl;
    return 0;
  }
Output:

Enter a non- negative integer: 2
Factorial of 2 is 2

Enter a non- negative integer: 0
Factorial of 0 is 1
Program # 8 Write a program to find out the factorial of any input number using recursion

[B]/* Written by : Arvind (slashfear)
   Language: C++  */

[/B][B]#include <iostream>
  using namespace std;

  int factorial(int n)    
  {
    if (n == 0) return 1;
    return n * factorial(n-1);
  }

  main()
  {
    int n;
    cout << "Enter a non-negative integer: ";
    cin >> n;
    cout << "Factorial of " << n << " is " << factorial(n) << endl;
    return 0;
  }
[/B]

Output:

Enter a non- negative integer: 1
Factorial of 1 is 1

Enter a non- negative integer: 3
Factorial of 3 is 6
 
And as a additional program i would like to add this below program which explains how recursion works(That's how each and every recursive call is made 😉) :

[B]/* Written by : Arvind (slashfear)
   Language: C++  */

[/B][B]#include <iostream>
  using namespace std;

  int factorial(int n)
  {
    int return_value;
    cout << "Called factorial(" << n << ")\n"; 
    if (n == 0) 
     {
      return_value = 1;
     } 
    else 
       {
      return_value = n * factorial(n-1);
       }
    cout << "Factorial(" << n << ") is returning " << return_value << endl;  
    return return_value;
  }

  main()
  {
    int n;
 
    cout << "Enter a non-negative integer: ";
    cin >> n;
    cout << "Factorial of " << n << " is " << factorial(n) << endl;  
    return 0;
  }
[/B]

Output:

Called factorial(2)
Called factorial(1)
Called factorial(0)
Factorial(0) is returning 1
Factorial(1) is returning 1
Factorial(2) is returning 2
Factorial of 2 is 2
 



-Arvind (Slashfear)
shalini_goel14

shalini_goel14

Branch Unspecified
05 May 2009
Yo ! Quite impressive work Slashfear 😁. Keep it up.

Where are our rest of CE programmers ? 😉 I am waiting for your programs also
slashfear

slashfear

Branch Unspecified
05 May 2009
shalini_goel14
Yo ! Quite impressive work Slashfear 😁. Keep it up.

Where are our rest of CE programmers ? 😉 I am waiting for your programs also
Hey shalini,

Thanks!!!

And dude I have already posted them!!!! (your asking about the 6 programs right)
Please check and let me know (I posted on 14th April could you please toggle back some post you can find my programs😲)


-Arvind (slashfear)
savior

savior

Branch Unspecified
07 May 2009
here's my code in java
/* Code
import java.io.*;
class Print
{
   public static void main(String args[])throws IOException // input/output Exception handling
   {
      DataInputStream d= new DataInputStream(System.in);
      System.out.println("Enter 1st no.");
      int a=Integer.parseInt(d.readLine()); // conversion from string to integer
      System.out.println("Enter 2nd no.");
      int b=Integer.parseInt(d.readLine());
      System.out.println("Do You want to print the nos?");
      String s=d.readLine();
      if(s.equals("y") || s.equals("Y"))
      {
        System.out.println("Numbers are "+a+" & "+b);  //printing of numbers to the console
      }
   }
}
*/

Output:
Enter 1st no.
3
Enter 2nd no.
5
Do You want to print the nos?
y
Numbers are 3 & 5
😔
savior

savior

Branch Unspecified
07 May 2009
Here's my solutions to problems #7, #8 in java...

Program #7
/*program #7 to calculate the factorial of any number n by the user without  recursion */
import java.io.*;
class Factnor
{
   public static void main(String args[])throws IOException      //exception handling
   {
      double fact=1;
      DataInputStream d= new DataInputStream(System.in);
      System.out.println("enter no. whose factorial is to be found");
      int n=Integer.parseInt(d.readLine());
      if(n==0) fact=1;
      else
      {
       for(int i=n;i>=1;i--)                                                             //calculation of factorial
       {
          fact=fact*i;
       }
      }
      System.out.println("factorial of "+n+" is "+fact);             //prints the result
   }
}

Output Program # 7
enter no. whose factorial is to be found
32
factorial of 32 is 2.6313083693369355E35

Program #8

 /* program #8 to calculate the factorial of any number n by the user using recursion */
import java.io.*;
class Factr
{
  public static double f(int a)   // method definition
  {
    if(a==0)
    return 1;
    else
    return (a*f(a-1));
  }
  public static void main(String args[])throws IOException  //exception handling
  {
    DataInputStream d = new DataInputStream(System.in);
    System.out.println("enter no. whose factorial is to be found"); //number as input
    int n= Integer.parseInt(d.readLine());
    System.out.println("factorial of "+n+" is "+f(n));    //prints the result
  }
}
Output Program # 8
enter no. whose factorial is to be found
32
factorial of 32 is 2.6313083693369355E35

shalini_goel14

shalini_goel14

Branch Unspecified
08 May 2009
slashfear
Please check and let me know (I posted on 14th April could you please toggle back some post you can find my programs😲)
Slashfear , Don't worry I have already seen your all programs a time. I was just asking our regular users of this thread. 😀

@savior Good trial man, keep it up. 😁
slashfear

slashfear

Branch Unspecified
08 May 2009
Oh..... ok 😲
safwan

safwan

Branch Unspecified
09 May 2009
Programe To find Factorial
Programming Language : visual Basic 6.0


  Private Sub Print_Click()
Dim dblnum As Double, dbli As Double
 Dim dblf As Double
 
   dblnum = Val(Text1.Text)
    
    f = 1
    
     For i = 1 To dblnum
     
       dblf = dblf * i
       
       List1.AddItem dblf
       
    Next i
    
    
    
    
    
End Sub
when we input 3 we get
1,2,6
sreelu_a

sreelu_a

Branch Unspecified
14 May 2009
class test
{
public static void main(String args[[])
{
int a,b;
a=Integer.parseInt(args[0]);
b=Integer.parseInt(args[1]);
System.out.println("two values entered are "+a+" " +b);
}
}
// this program needs the nubers to be given at command prompt

--- to compile
javac test.java
--to execute
java test 10 20
--output
two values entered are 10 20
sreelu_a

sreelu_a

Branch Unspecified
14 May 2009
Program # 2 Write a simple program(in any computer language) that accepts a number from the user and prints "This is an even number" if the number is even and "This is not an even number" if the number is not even.

// sree lakshmi

import java.io.*;
class test
public static void main(String args[])
{
int a;
InputStreamReader isr=new InputStreamReader(System.in);
BufferedReader br=new BufferedReader(isr);
System.out.println("enter a number");
a=Integer.parseInt(br.readline());
if(a%2==0)
System.out.printl(a+" is even number");
else
System.out.println(a+" is not an even number");
}
}


-----to compile
javac test.java

---- to run
java test

--output
enter a number
4
4 is even number
shalini_goel14

shalini_goel14

Branch Unspecified
14 May 2009
Program # 9 Write a program that finds out the factors of any input number.

Program # 10 Write a program that prints the multiplication table of 2 to 20. Entries for each table should be 10. Proper formatting matters for this program.
safwan

safwan

Branch Unspecified
14 May 2009
hay Shalini can you explain Programm #10 by giving example sorry i am not able to understand 😕
😒
😀
slashfear

slashfear

Branch Unspecified
14 May 2009
Hi safwan,

The program #10 : Requires you to print the multiplication table values from 2 to 20 and for Eg: 2 x1..............2x10 similarly till 20 number that is like,

2x1.........2x10 then 3x1.........3x10...................... till ....20x1...........20x10

If its not clear still look at my program output( you get a clear picture)😉


-Arvind(slashfear)
slashfear

slashfear

Branch Unspecified
14 May 2009
Hi Shalini,

Here is my solution for the problems in C++.....😁

Program # 9 Write a program that finds out the factors of any input number.
[B]
/* Written by: Arvind(slashfear)
   Language: C++      */

#include <iostream>
using namespace std;

void factors(long n,long f=1)
{
     if(n%f==0)
          cout<<f<<"  ";

     if(f==n)
          return;

     factors(n,f+1);
}

int main()
{
    int n;
    cout<<"Enter the Number to find its factors: ";
    cin>>n;
    factors(n);
    return 0;
}
[/B]
Output:
[B]
Enter the Number to find its factors:10
1 2 5 10[/B]
Program # 10 Write a program that prints the multiplication table of 2 to 20. Entries for each table should be 10. Proper formatting matters for this program.

This program displays the multiplication tables from 2 to 20:
[B]/* Written by: Arvind(slashfear)
   Language: C++      */

#include <iostream>
#include <iomanip>
using namespace std;

int main()
{
   cout << setw ( 4 ) << right << "|";
   for ( int i = 2; i <= 20 ; ++i ) cout << left << setw ( 5 ) << i ;       
   cout << "\n------------------------------------------------------\n" ;

   for ( int i = 1; i <= 10; ++i )
   {
      cout << setw ( 3 ) << left << i << '|' ;
      for ( int j = 1; j <= 10 ; ++j )
         cout << setw ( 5 ) << left << i*j ;
      cout << "\n   |\n" ;
   }
}[/B]
Output:
So the sample output for this program is cut down to 10 because it will be long, but the output for the above code yields multiplication of 20 numbers;-) (I don't know how to format in this......😒 but you will get a formated output when you execute 😲)

 [B]     2      3      4      5      6      7      8      9      10
-----------------------------------------------------------------------------
1|   2      3      4      5      6      7      8      9      10

2|   4      6      8    10    12    14    16     18    20

3|   6      9      12    15    18    21    24    27    30    

4|   8      12     16    20    24    28    32    36    40

5|   10    15     20    25    30    35    40    45    50

6|   12    18     24    30    36    42    48    54    60

7|   14    21     28    35    42    49    56    63     70

8|   16    24     32    40    48    56    64    72    80

9|   18    27     36    45    54    63    72    81     90

10| 20    30    40    50    60    70    80    90    100[/B]
As an additional program i like to add this code ;-),
This program will provide you the Multiplication tables of specific number (works for all integer number) what the user inputs or wants:
This program will help Kids......😁
[B]/* Written by: Arvind(slashfear)
   Language: C++      */
#include <iostream>

using namespace std;


int main()
{
    int i;
    int j;
    cout<<"Enter the Multiplication table you want to see: ";
    cin>>i;
    cout<<endl;
    cout<<"The Multiplication Tables of "<<i<<" is as follows:";

    for(j=1;j<=10;j++)
    {
        cout<<endl;
        cout<<i<<" x "<<j<<" = "<<i*j;
        cout<<endl;
    }
    return 0;
}[/B]

Output:
[B]
Enter the Multiplication table you want to see: 100

The Multiplication Tables of 100 is as follows:

100 x 1 = 100

100 x 2 = 200

100 x 3 = 300

100 x 4 = 400

100 x 5 = 500

100 x 6 = 600

100 x 7 = 700

100 x 8 = 800

100 x 9 = 900

100 x 10 = 1000[/B]


-Arvind(slashfear);-)
shalini_goel14

shalini_goel14

Branch Unspecified
14 May 2009
Superb Slashfear 😁

Guys(rest of CEans) post your programs also and beat this guy slashfear in programming. 😀
savior

savior

Branch Unspecified
15 May 2009
Solutions to programs 9 and 10 in java.
Program #9

//program to find factors of any input number
import java.io.*;
class Factor
{
   public static void main(String[] args)throws IOException
   {
       int n;
       InputStreamReader isr = new InputStreamReader(System.in);
       BufferedReader br = new BufferedReader(isr);
       System.out.print(" Enter a number ");
       n=Integer.parseInt(br.readLine());
       System.out.println(" ");
       System.out.print("Factors are ");
       for(int i=1; i<=n;i++)
       if(n%i==0) System.out.print(i+" ");
   }
}
Output
Enter a number 30
Factors are 1 2 3 5 6 10 15 30

Program #10
//program to print multiplication tables of 2 to 20.
import java.io.*;
class Multtable
{
   public static void main(String[] args)
   {
     int n=2;
     System.out.print("      ");
     for(int i=1; i<=10;i++)
     System.out.print(i+" ");
     System.out.println(" ");
     while(n<21)
     {
       System.out.print(n+"    ");
       for(int j=1; j<=10;j++)
       {
         System.out.print(n*j+" ");
       }
       System.out.println(" ");
       n++;
     }
   }
}
Output:
1 2 3 4 5 6 7 8 9 10

2 2 4 6 8 10 12 14 16 18 20
3 3 6 9 12 15 18 21 24 27 30
4 4 8 12 16 20 24 28 32 36 40
5 5 10 15 20 25 30 35 40 45 50
. . . . . . . . . . .
20 20 40 60 80 100 120 140 160 180 200


Shalini, is there any specified format for program 10 or can we use any?😕
The output format got distorted here in the post. I don't know why....it works when you execute the code though.
shalini_goel14

shalini_goel14

Branch Unspecified
15 May 2009
Hi savior,

Good going man. There is not specific format. I just mentioned this thing so that multiplication table atleast look like a multiplication table. Your format is also ok but think a little more, in java you can make it much better just think some thing crazy. 😉
slashfear

slashfear

Branch Unspecified
15 May 2009
shalini_goel14
Guys(rest of CEans) post your programs also and beat this guy slashfear in programming. 😀

So kind of you buddy...........😁
CEMember

CEMember

Branch Unspecified
15 May 2009
shalini_goel14
Guys(rest of CEans) post your programs also and beat this guy slashfear in programming. 😀
Hey Shalini, Please wait for my programs also. I will post them soon. Actually I was going very busy so could not log into this site .😔
shalini_goel14

shalini_goel14

Branch Unspecified
15 May 2009
CEMember
Hey Shalini, Please wait for my programs also. I will post them soon. Actually I was going very busy so could not log into this site .😔
Its ok CEMember , Welcome back in this thread. I will wait . 😁
komputergeek

komputergeek

Branch Unspecified
16 May 2009
I will post my programs in 2-3 days.
safwan

safwan

Branch Unspecified
16 May 2009
my Program is ready but going to post it tomorrow now no time .
shalini_goel14

shalini_goel14

Branch Unspecified
16 May 2009
@komputergeek & @safwan Its ok guys. I am waiting. 😀
enthudrives

enthudrives

Branch Unspecified
17 May 2009
//To print the factors of a number using C++
#include<iostream.h>
#include<conio.h>
main()
{
int n,i;
cout<<"enter a number";
cin>>n;
cout<<"\nThe factors are  ";
for(i=1;i<=n;i++)
{
                 if(n%i==0)
                 cout<<i<<"\t";
}
getch();
}
Output:
enter a number14
The factors are  1         2         7         14
enthudrives

enthudrives

Branch Unspecified
17 May 2009
//Printing tables using C++
#include<iostream.h>
#include<conio.h>
main()
{
int j,i;
for(i=2;i<=20;i++)
{
                 cout<<"\n\nTable "<<i<<"\n";
                 for(j=1;j<=10;j++)
                 cout<<j<<"*"<<i<<"="<<i*j<<"\n";
}
getch();
}
safwan

safwan

Branch Unspecified
18 May 2009
Programe # 10

Code for this Programe is
Language : BASIC 6.0 (VB6.0
Private Sub cmdPrint_Click()
 ' programed by Safwan Patel
 ' no Copyright
 'this software is FLOSS
 'Programe to print multiplication in List Box
 'Writeen on 16/05/09
 
  Dim intn As Integer, intcount As Integer, intr As Integer
      'Declaration of variable
      
    For intn = 1 To 20
       intcount = 1
       r = 0
       Do While intcount <= 10
                intr = intcount * intn
               
                lst1.AddItem intn & "x" & intcount & "=" & intr
            
                intcount = intcount + 1
      Loop
  Next intn
  
      
End Sub
when we Press button Print we get out put
like
1 X 1= 1
1x2=2
......
like this till 20x10=200
there is another programe which i wrot befor was
Private Sub Command1_Click()
 
  
 Dim num As Integer, i As Integer
    num = Val(Text1.Text)
       For i = 1 To 10
            List1.AddItem num & "x" & i & "=" & num * i
       Next i
       
End Sub
so when we enter 5 we get out put like
5X1=5
.....etc
😁 :smile:
CEMember

CEMember

Branch Unspecified
19 May 2009
Hi Shalini,

Here goes my program in Java

Program # 7 Write a program to find out the factorial of any input number without recursion.

package myjava;
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
/**
 *
 * @author CEMember
 */
public class FactorialWithoutRecursion {
 
    public static void main(String arag[]){
 
        int number;
        double factorial=1D;
        BufferedReader br=new BufferedReader(new InputStreamReader(System.in));
        try {
 
            number=Integer.parseInt(br.readLine());
            System.out.println("Entered number is::"+number);
 
            /* Checks if the number is a negative number */
            if(number < 0){
            System.out.println("Negative number is entered."); 
            System.exit(0);
            }
 
            /* Checks if the number is 0 or 1 */
            if(number==0 || number==1){
 
                System.out.println("Factorial of "+number+" is 1");
            }else{
                for(int i=1;i<=number;i++){
                    factorial*=i;
                }
                System.out.println("Factorial of "+number+" is "+factorial);
            }
 
 
        } catch (NumberFormatException ex) {
            System.out.println("Invalid number is entered.");
        }
        catch (IOException ex) {
            System.out.println("IOException occured");
        }
    }
}
Output:
abc
Invalid number is entered.

-59
Entered number is::-59
Negative number is entered.

170
Entered number is::170
Factorial of 170 is 7.257415615307994E306

171
Entered number is::171
Factorial of 171 is Infinity

0
Entered number is::0
Factorial of 0 is 1

1
Entered number is::1
Factorial of 1 is 1
Program # 8 Write a program to find out the factorial of any input number using recursion.

package myjava;
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
/**
 *
 * @author CEMember
 */
public class FactorialWithRecursion {
 
    public static void main(String arag[]){
 
        int number;
 
        BufferedReader br=new BufferedReader(new InputStreamReader(System.in));
        try {
 
            number=Integer.parseInt(br.readLine());
            System.out.println("Entered number is::"+number);
 
            /* Checks if the number entered is 0 or more than that */
            if(number >=0){
                System.out.println("Factorial of "+number+" is "+recursiveFact(number));
            } else{
                System.out.println("Negative number is entered.");
            }
        } catch (NumberFormatException ex) {
            System.out.println("Invalid number is entered.");
        } catch (IOException ex) {
            System.out.println("IOException occured");
        }
    }
 
    /* Recursive method called to find out the factorial of a number */
    public static double recursiveFact(int number){
 
        if(number==0 || number==1){
            return 1;
        } else{
            return  number * recursiveFact(number-1);
        }
 
 
    }
}
Output:
abc
Invalid number is entered.

-59
Entered number is::-59
Negative number is entered.

170
Entered number is::170
Factorial of 170 is 7.257415615307994E306

171
Entered number is::171
Factorial of 171 is Infinity

0
Entered number is::0
Factorial of 0 is 1.0

1
Entered number is::1
Factorial of 1 is 1.0
CEMember

CEMember

Branch Unspecified
19 May 2009
Hi Shalini,

Here goes my program in Java for Program # 9 and 10

Program # 9 Write a program that finds out the factors of any input number.
package myjava;
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
/**
 *
 * @author CEMember
 */
public class FindFactorsProgram {
 
    public static void main(String arag[]){
 
        int number;
 
        BufferedReader br=new BufferedReader(new InputStreamReader(System.in));
        try {
 
            number=Integer.parseInt(br.readLine());
            System.out.println("Entered number is::"+number);
 
 
            /* Checks if the number entered is 0 or more than that */
            if(number >=0){
                System.out.print("Factors of "+number+" are [ ");
                for(int i=1;i<=number;i++){
                    if(number % i==0){
                        System.out.print(i+" ")  ;
                    }
                }
                System.out.print("] ")  ;
            }
            else{
                System.out.println("Negative number is entered.");
            }
 
 
 
        } catch (NumberFormatException ex) {
            System.out.println("Invalid number is entered.");
        } catch (IOException ex) {
            System.out.println("IOException occured");
        }
    }
 
}
Output:
abc
Invalid number is entered.

-59
Entered number is::-59
Negative number is entered.

100000000
Entered number is::100000000
Factors of 100000000 are [ 1 2 4 5 8 10 16 20 25 32 40 50 64 80 100 125 128 160 200 250 256 320 400 500 625 640 800 1000 1250 1280 1600 2000 2500 3125 3200 4000 5000 6250 6400 8000 10000 12500 15625 16000 20000 25000 31250 32000 40000 50000 62500 78125 80000 100000 125000 156250 160000 200000 250000 312500 390625 400000 500000 625000 781250 800000 1000000 1250000 1562500 2000000 2500000 3125000 4000000 5000000 6250000 10000000 12500000 20000000 25000000 50000000 100000000 ]
Program # 10 Write a program that prints the multiplication table of 2 to 20. Entries for each table should be 10. Proper formatting matters for this program.

package myjava;
/**
 *
 * @author CEMember
 */
public class MultiplicationTable {
 
    public static void main(String[] args){
 
        System.out.println("Multiplication table for numbers from 2 to 20");
          System.out.println("-------------------------------------------");
       for(int i=2;i<=20;i++){
 
       System.out.print(i+" = [ ");
       for(int j=1;j<=10;j++){
           System.out.print(j*i+" ");
       }
       System.out.println("]");
 
    }
     }
}
 
Output:
Output:
Multiplication table for numbers from 2 to 20
-------------------------------------------
2 = [ 2 4 6 8 10 12 14 16 18 20 ]
3 = [ 3 6 9 12 15 18 21 24 27 30 ]
4 = [ 4 8 12 16 20 24 28 32 36 40 ]
5 = [ 5 10 15 20 25 30 35 40 45 50 ]
6 = [ 6 12 18 24 30 36 42 48 54 60 ]
7 = [ 7 14 21 28 35 42 49 56 63 70 ]
8 = [ 8 16 24 32 40 48 56 64 72 80 ]
9 = [ 9 18 27 36 45 54 63 72 81 90 ]
10 = [ 10 20 30 40 50 60 70 80 90 100 ]
11 = [ 11 22 33 44 55 66 77 88 99 110 ]
12 = [ 12 24 36 48 60 72 84 96 108 120 ]
13 = [ 13 26 39 52 65 78 91 104 117 130 ]
14 = [ 14 28 42 56 70 84 98 112 126 140 ]
15 = [ 15 30 45 60 75 90 105 120 135 150 ]
16 = [ 16 32 48 64 80 96 112 128 144 160 ]
17 = [ 17 34 51 68 85 102 119 136 153 170 ]
18 = [ 18 36 54 72 90 108 126 144 162 180 ]
19 = [ 19 38 57 76 95 114 133 152 171 190 ]
20 = [ 20 40 60 80 100 120 140 160 180 200 ]
PS: Shalini, 1 request Please increase some level of programs man. 😀
shalini_goel14

shalini_goel14

Branch Unspecified
24 May 2009
@CEMember Ya sure man, for increasing the level of programs, level of surprises also need to increase. 😛 Anyways good to see your programs here.

@safwan I liked your spirit of trying to beat everyone with VB. Keep it up man. 😀

@enthudrives Good going. I am waiting for your rest of programs.

@komputergeek, @Scropion & @ Miniy : I am still waiting for your programs.

PS: 7 more days to announce the winner for surprise. 😁
safwan

safwan

Branch Unspecified
24 May 2009
Thnks you shalini and my Fellow CEans
sheeko

sheeko

Branch Unspecified
28 May 2009
i don't have a new idea for number 9

here is number 10
#include<iostream>

using namespace std;

int main()
{
    int a[21][11];

    for(int i=2;i<=20;i++)
    {
        for(int j=1;j<=10;j++)
        {
            a[i][j]=i*j;
        }
    }

    for(int i=2;i<=20;i++)
    {
        cout<<"---------------------------------------------------------------------------\n";
        for(int j=1;j<=10;j++)
        {
            if(j!=1)
                cout<<"\t|";
            cout<<a[i][j];
        }

        cout<<endl;
    }

    return 0;
}
the output
---------------------------------------------------------------------------
2     |4     |6     |8     |10    |12    |14    |16    |18    |20
---------------------------------------------------------------------------
3     |6     |9     |12    |15    |18    |21    |24    |27    |30
---------------------------------------------------------------------------
4     |8     |12    |16    |20    |24    |28    |32    |36    |40
---------------------------------------------------------------------------
5     |10    |15    |20    |25    |30    |35    |40    |45    |50
---------------------------------------------------------------------------
6     |12    |18    |24    |30    |36    |42    |48    |54    |60
---------------------------------------------------------------------------
7     |14    |21    |28    |35    |42    |49    |56    |63    |70
---------------------------------------------------------------------------
8     |16    |24    |32    |40    |48    |56    |64    |72    |80
---------------------------------------------------------------------------
9     |18    |27    |36    |45    |54    |63    |72    |81    |90
---------------------------------------------------------------------------
10    |20    |30    |40    |50    |60    |70    |80    |90    |100
---------------------------------------------------------------------------
11    |22    |33    |44    |55    |66    |77    |88    |99    |110
---------------------------------------------------------------------------
12    |24    |36    |48    |60    |72    |84    |96    |108   |120
---------------------------------------------------------------------------
13    |26    |39    |52    |65    |78    |91    |104   |117   |130
---------------------------------------------------------------------------
14    |28    |42    |56    |70    |84    |98    |112   |126   |140
---------------------------------------------------------------------------
15    |30    |45    |60    |75    |90    |105   |120   |135   |150
---------------------------------------------------------------------------
16    |32    |48    |64    |80    |96    |112   |128   |144   |160
---------------------------------------------------------------------------
17    |34    |51    |68    |85    |102   |119   |136   |153   |170
---------------------------------------------------------------------------
18    |36    |54    |72    |90    |108   |126   |144   |162   |180
---------------------------------------------------------------------------
19    |38    |57    |76    |95    |114   |133   |152   |171   |190
---------------------------------------------------------------------------
20    |40    |60    |80    |100   |120   |140   |160   |180   |200
shalini_goel14

shalini_goel14

Branch Unspecified
28 May 2009
Good work sheeko, keep it up. 😀

Others where are you 3 more days left. Come on.
shalini_goel14

shalini_goel14

Branch Unspecified
31 May 2009
Well done Guys !

Below is the sort summary of who did what in this thread in the month of May
Program # 1
slashfear - C++ (without output)
goyal786 -C++
savior -Java
sreelu-a -Java
Program # 2
slashfear - C++ (without output)
sreelu-a -Java
Program # 3
slashfear - C++ (without output)
Program # 4
slashfear - C++ (without output)
Program # 5
slashfear - C++ (without output)
Program # 6
slashfear - C++ (without output)
safwan - made working
Program # 7
slashfear - C++
savior -Java
safwan -VB
CEMember - Java
Program # 8
slashfear - C++
CEMember - Java
Program # 9
slashfear - C++
savior - Java
enthudrives -C++
CEMember - Java
Program # 10
slashfear - C++
savior -Java
enthudrives - C++ (without output)
safwan -VB
CEMember - Java
sheeko -C++

So after looking at programs, I found slashfear to be declared as winner for the surprise but I am not sure whether all his programs are his own made , so
CEMember is made as the winner for the surprise. Congrats again man. 😁

Special surprise
@safwan - I really appreciated your work in this thread. Your tendencey to learn and correcting your program even if it didn't work last time. Keep it up this spirit of "Keep on trying" - A Dairy Milk for you
@savior - A Dairy Milk for you also. Keep it up man. 😁
@Scorpion : Your pending Dairy Milk also I am giving this month.
Check PM in your mailbox.

PS: Because of increased no of posts in this thread than our CE system can accomodate and some other unavoidable reasons. Here I close another chapter of my intiative.
Special Thanks to everyone who posted their programs here.😀

Thanks !
silverscorpion

silverscorpion

Branch Unspecified
01 Jun 2009
Well if only the number of posts is the reason, you may start another thread as in "programming challenge - II" or something.

So, please continue giving such programs. I thought you were gonna increase the difficulty level of future programs, and you are saying you're gonna close this thread..😔😔
safwan

safwan

Branch Unspecified
01 Jun 2009
Thank you shallini and english scared yes exactly English _scared is correct i am ready to beat and compite with other CE ans Fellow in next challange II if itsd going to start
.
savior

savior

Branch Unspecified
04 Jun 2009
THANK YOU Shalini.... hope you come programming contest-II
savior

savior

Branch Unspecified
04 Jun 2009
Shalilni, you asked for my name and address through a private message, but I am unable to reply because of the following error:
[Qoute] shalini_goel14 has chosen not to receive private messages or may not be allowed to receive private messages. Therefore you may not send your message to him/her.[/Quote].
how do I reply?
shalini_goel14

shalini_goel14

Branch Unspecified
04 Jun 2009
savior
Shalilni, you asked for my name and address through a private message, but I am unable to reply because of the following error:
[Qoute] shalini_goel14 has chosen not to receive private messages or may not be allowed to receive private messages. Therefore you may not send your message to him/her.
how do I reply?
.

Oops ! I am so sorry dear. Wait I am sending a friend request to you. Accept it and then send the details soon. 😀
Sanjeev Jaiswal

Sanjeev Jaiswal

Branch Unspecified
08 May 2015
Here comes Perl one liner for question#3
Beat it!
perl -E 'say "Prime" if (1 x shift) !~ /^1?$|^(11+?)\1+$/' 123

Share this content on your social channels -

Only logged in users can reply.