Symbianize Forum

Most of our features and services are available only to members, so we encourage you to login or register a new account. Registration is free, fast and simple. You only need to provide a valid email. Being a member you'll gain access to all member forums and features, post a message to ask question or provide answer, and share or find resources related to mobile phones, tablets, computers, game consoles, and multimedia.

All that and more, so what are you waiting for, click the register button and join us now! Ito ang website na ginawa ng pinoy para sa pinoy!

-= Having Difficulties in C++ and Java? Be a Part of This Thread =-

PROJECT SA C
AICS GRADING SYSTEM
Attendance 1:
attendance 2:
attendance 3:
attendance 4:
attendance 5:

attendance=10%
recitation=30%
quiz=40%
project=20%
cls 100%

Recitatiton:
Quiz 1:
Quiz 2:
Project:

CLS:
Exam:
Pro Grade:
Ratings:
Remarks:

do you wanna use again the grading system ? [YES] or [NO]

attendance (all ave) x.10
recitation x.30
quiz (all ave) x.40
project x.20
cls= attendance recitation quiz proejct
Prd Grade = (cls x2 ) exam / 3 (divide )

things to used sabi ni sir
-
variables for input and output
if condition
switch case
looping
array ( kung gusto mo makatipid sa variables )
arithmetic and logical operators.

hmm dito nako pumunta sa symbianize alam ko maramimg matalino dito at matulungin. maraming salamat sa sasagot po mga master.


nasaan ang sariling mong code na gawa para diyan? :slap:
 
Pwede po magpatulong sa C++ project po namin ayoko na pong umulit ng Advance Programming

eto po yung codes, ang idadagdag daw po structure at file manipulation



Thank you po sa tutulong!

hehe, haba ng code ah, sipag

Code:
#include <iostream>
#include <sstream>
using namespace std;

int convert(char a){
	if(isdigit(a)){
		int b = a - '0';
		return b;
	}
	else if(isalpha(a)){
		a = toupper(a);
		char c = 'A';
		for(int i=10; i<16; i++){
			if(c == a)
				return i;
			c++;
		}
	}
}

int main(){

	char x, y;
	int a, b, c, d;
	stringstream s1, s2;
	
	cout 	<< "***************************************\n"
			<< "    Welcome to Hexadecimal Division    \n"
			<< "***************************************" << endl;
	
	cout << "\nEnter first hexadecimal value (0-9/A-F): ";
	cin >> x;
	
	a = convert(x);
	s1 << a;
	s1 >> hex >> c;
	double first = (double) c;
	
	cout << "\nEnter first hexadecimal value (0-9/A-F): ";
	cin >> y;
	b = convert(y);
	s2 << b;
	s2 >> hex >> d;
	double second = (double) d;

	cout << "\n***************************************\n\nRESULTS:" << endl;

	cout << "\nDecimal value of the first hexadecimal input: " << first << endl;
	cout << "Decimal value of the second hexadecimal input: " << second << endl;
	cout << "Quotient: " << first / second << endl;
	cout << "Calculated Hexadecimal Division: " << a/b << endl;


	return 0;
}
 
eto na po yung program ang problema hanggang 99 lang po ang na coconvert.. pano po ba pag convert ng 100 to 999,999 in words...

package com.Converter;

import javax.swing.*;

import java.util.*;
import java.awt.*;
import java.awt.event.*;
import javax.swing.JComponent;
import java.awt.Component;
import java.awt.event.ActionListener;

public class Convert extends JFrame implements ActionListener{

String string;
String st1[] = { "", "One", "Two", "Three", "Four", "Five", "Six", "Seven",
"Eight", "Nine", };
String st2[] = { "Hundred", "Thousand", "Hundred", "" };
String st3[] = { "Ten", "Eleven", "Twelve", "Thirteen", "Fourteen",
"Fifteen", "Sixteen", "Seventeen", "Eighteen", "Ninteen", };
String st4[] = { "Twenty", "Thirty", "Fourty", "Fifty", "Sixty", "Seventy",
"Eighty", "Ninety" };


protected JPanel panel;
protected JLabel label1;
protected JLabel label2;
protected JTextField textField;
protected JTextArea textArea;
protected JButton button;
protected JButton button1;
protected int num;
protected String words;
public Convert() {
super(" Converter");
setTitle("Number To Words");
setSize(380,300);
setLocationRelativeTo(null);
setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
panel = new JPanel();
panel.setLayout(null);
add(panel);

label1 = new JLabel("Number To Convert:");
label1.setBounds(20, 50, 150, 20);
panel.add(label1);

textField = new JTextField(20);
textField.setBounds(180, 50, 150, 25);
panel.add(textField);
textField.addActionListener(this);

label2 = new JLabel("Number In Words:");
label2.setBounds(20, 100, 150, 20);
panel.add(label2);

textArea = new JTextArea("3, 20");
textArea.setBounds(60, 150, 250, 50);
panel.add(textArea);

button = new JButton("Convert");
button.setBounds(30, 220, 100, 30);
panel.add(button);
button.addActionListener(this);

button1 = new JButton("Clear");
button1.setBounds(230, 220, 100, 30);
panel.add(button1);
button1.addActionListener(this);



}

public void actionPerformed(ActionEvent e) {

if (e.getSource() == button1) {
textField.setText("");
textArea.setText("");
}
if (Integer.parseInt(textField.getText())>=999999){
JOptionPane.showMessageDialog(null,
"Error: Please enter the number between 0-999,999", "Error Massage",
JOptionPane.ERROR_MESSAGE);
}
if (e.getSource() == button) {
num = Integer.parseInt(textField.getText());
textArea.setText(String.valueOf(num ));

}

int n = 1;
int word;
string = "";
while (num != 0) {
switch (n) {
case 1:
word = num % 100;
pass(word);
if (num > 100 && num % 100 != 0) {
textArea.setText(" and ");
}
num /= 100;
break;
case 2:
word = num % 10;
if (word != 0) {
textArea.setText(" ");
textArea.setText(st2[0]);
textArea.setText(" ");
pass(word);
}
num/= 10;
break;
case 3:
word = num % 100;
if (word != 0) {
textArea.setText(st2[1]);
pass(word);
}
num /= 100;
break;
case 4:
word = num % 1000;
if (word != 0) {
textArea.setText(" ");
textArea.setText(st2[2]);
textArea.setText(" ");
pass(word);
}
num /= 1000;
break;
case 5:
word = num % 10000;
if (word != 0) {
textArea.setText(" ");
textArea.setText(st2[3]);
textArea.setText(" ");
pass(word);
}
num /= 10000;
break;
}
n++;
}
return;
}

private void pass(int num) {
int word, q;

if (num < 10) {
textArea.setText(st1[num]);
}

if (num > 19) {
word = num % 10;

if(num >99){
word = num %100;
}

else {
q = num / 10;
textArea.setText((st4[q - 2])+ st1[word]);

}
}
}



public static void main(String[] args){

SwingUtilities.invokeLater(new Runnable(){
public void run(){
Convert x = new Convert();
x.setVisible(true);
}
});
}
}
 
pwede po ba patulong sa C dto ? :D eto ksi pnpagawa samen..

The program would ask you to enter a number. Then the program will output all the addends of that number but will only show the prime addends

Example :
Enter number: 10
The addends are:
1+9
5+5
6+4
7+3
2+8.
 
pwede po ba patulong sa C dto ? :D eto ksi pnpagawa samen..

The program would ask you to enter a number. Then the program will output all the addends of that number but will only show the prime addends

Example :
Enter number: 10
The addends are:
1+9
5+5
6+4
7+3
2+8.

meron na akong nagawang solution para dito pero gusto kong makita yung ginawa mo ring code..
 
PROJECT SA C
AICS GRADING SYSTEM
Attendance 1:
attendance 2:
attendance 3:
attendance 4:
attendance 5:

attendance=10%
recitation=30%
quiz=40%
project=20%
cls 100%

Recitatiton:
Quiz 1:
Quiz 2:
Project:

CLS:
Exam:
Pro Grade:
Ratings:
Remarks:

do you wanna use again the grading system ? [YES] or [NO]

attendance (all ave) x.10
recitation x.30
quiz (all ave) x.40
project x.20
cls= attendance recitation quiz proejct
Prd Grade = (cls x2 ) exam / 3 (divide )

things to used sabi ni sir
-
variables for input and output
if condition
switch case
looping
array ( kung gusto mo makatipid sa variables )
arithmetic and logical operators.

hmm dito nako pumunta sa symbianize alam ko maramimg matalino dito at matulungin. maraming salamat sa sasagot po mga master.

gamit ka do while loop jan sir para mag repeat sya
 
mukhang ang tahimik po ng thread :D
 
Pa help nman po sa string conversion a=1 b=2 c=3 d=4 e=5 .... z=26

Ang output nya po dapat ay:

Enter character: A B C D E

Tapos ang ikakalabasan ay: 01 02 03 04 05
 
:praise::praise:
pa convert namn po ung code na ito sa java. c++po ung code.



Code:
#include <iostream>
#include <windows.h>
#include <time.h>
using namespace std;

struct phonebook {
    int id;
    char name[20];
    char surname[20];
    char phone[20];
} phonelist[20];

int cnt=0; // record counter
int cnt_del=0; // deleted record counter

int generate_my_id() {

    //srand((unsigned)time(0));
    return rand() % 20000 + 1500; // random user id
}

void func_add() {
    char yes_no;
    system("CLS");
    SetConsoleTextAttribute(GetStdHandle(STD_OUTPUT_HANDLE), 12);
cout<<"******************************************************************"<<endl;
    cout<<"\t\t\t ADD A PERSON"<<endl;
cout<<"******************************************************************"<<endl;
    SetConsoleTextAttribute(GetStdHandle(STD_OUTPUT_HANDLE), 15);
    if(cnt!=20) { // if struct is full give error
        cout<<"Index...........................: "<<cnt<<endl; // pk
        cout<<"Id..............................: ";
        phonelist[cnt].id=generate_my_id(); // random id
        cout<<phonelist[cnt].id<<endl;
        cout<<"Name............................: ";
        cin>>phonelist[cnt].name;
        cout<<"Surname.........................: ";
        cin>>phonelist[cnt].surname;
        cout<<"Phone...........................: ";
        cin>>phonelist[cnt].phone;
        SetConsoleTextAttribute(GetStdHandle(STD_OUTPUT_HANDLE), 9);
        cout<<"Do you want to save this person ? (Y)es-(N)o : ";
        cin>>yes_no;
            if(yes_no=='Y' || yes_no=='y') {
                SetConsoleTextAttribute(GetStdHandle(STD_OUTPUT_HANDLE), 12);
                cout<<"Person is saved !!!"<<endl;
                cnt++; // increase record counter
            }
            else {
                SetConsoleTextAttribute(GetStdHandle(STD_OUTPUT_HANDLE), 12);
                cout<<"Person is not saved !!!"<<endl; // delete the record
                    for(int j=cnt; j<10; j++) { // scroll the array
                                phonelist[j].id=phonelist[j+1].id;
                                strcpy(phonelist[j].name,phonelist[j+1].name);
                                strcpy(phonelist[j].surname,phonelist[j+1].surname);
                                strcpy(phonelist[j].phone,phonelist[j+1].phone);
                    }
            }
    }
    else {
        SetConsoleTextAttribute(GetStdHandle(STD_OUTPUT_HANDLE), 12);
        cout<<"Phonebook is full you can't add any person anymore !!! "<<endl;
    }
} // add person

void func_del() {
    char sch_name[20];
    char yes_no=' ';
    system("CLS");
    SetConsoleTextAttribute(GetStdHandle(STD_OUTPUT_HANDLE), 12);
cout<<"******************************************************************"<<endl;
    cout<<"\t\t\t DELETE A PERSON"<<endl;
cout<<"******************************************************************"<<endl;
    SetConsoleTextAttribute(GetStdHandle(STD_OUTPUT_HANDLE), 9);
    cout<<"Please enter a name : ";
    cin>>sch_name;
        for(int i=0; i<20; i++) {
                if(strcmp(phonelist[i].name,sch_name)==0) { // compare two char array
                    SetConsoleTextAttribute(GetStdHandle(STD_OUTPUT_HANDLE), 12);
                    cout<<"Person is found !!!"<<endl;
                    SetConsoleTextAttribute(GetStdHandle(STD_OUTPUT_HANDLE), 15);
                    cout<<"Index...........................: "<<i<<endl;
                    cout<<"Id..............................: "<<phonelist[i].id<<endl;
                    cout<<"Name............................: "<<phonelist[i].name<<endl;
                    cout<<"Surname.........................: "<<phonelist[i].surname<<endl;
                    cout<<"Phone...........................: "<<phonelist[i].phone<<endl;
                    int dlt_index=i;
                    SetConsoleTextAttribute(GetStdHandle(STD_OUTPUT_HANDLE), 9);
                    cout<<"Do you want to delete this person (Y)es-(N)o : ";
                    cin>>yes_no;
                        if(yes_no=='Y' || yes_no=='y') {
                            for(int j=dlt_index; j<10; j++) { // scroll the array
                                i=dlt_index-1;
                                phonelist[j].id=phonelist[j+1].id;
                                strcpy(phonelist[j].name,phonelist[j+1].name);
                                strcpy(phonelist[j].surname,phonelist[j+1].surname);
                                strcpy(phonelist[j].phone,phonelist[j+1].phone);
                            }
                            cnt--; // decrease the counter
                            SetConsoleTextAttribute(GetStdHandle(STD_OUTPUT_HANDLE), 12);
                            cout<<"Person is deleted !!!"<<endl;
                            break;
                        }
                }
                else if(i==19 && yes_no==' ') {
                    SetConsoleTextAttribute(GetStdHandle(STD_OUTPUT_HANDLE), 12);
                    cout<<"Person is not found !!!"<<endl;
                }
        }
} // delete person

void func_lst() {
    system("CLS");
    SetConsoleTextAttribute(GetStdHandle(STD_OUTPUT_HANDLE), 12);
cout<<"******************************************************************"<<endl;
    cout<<"\t\t\t LIST ALL PERSON"<<endl;
cout<<"******************************************************************"<<endl;
    SetConsoleTextAttribute(GetStdHandle(STD_OUTPUT_HANDLE), 15);
        for(int i=0; i<cnt; i++) {
     cout<<"Index..: "<<i<<" Id..: "<<phonelist[i].id<<"\t"<<phonelist[i].name<<"\t\t"<<phonelist[i].surname<<"\t\t"<<phonelist[i].phone<<endl;
            }
        if(cnt==0) {
                SetConsoleTextAttribute(GetStdHandle(STD_OUTPUT_HANDLE), 12);
                cout<<"There is no any record !!!"<<endl;
            }
} // list person

void func_sch() {
    char sch_name[20];
    system("CLS");
    SetConsoleTextAttribute(GetStdHandle(STD_OUTPUT_HANDLE), 12);
cout<<"******************************************************************"<<endl;
    cout<<"\t\t\t SEARCH A PERSON"<<endl;
cout<<"******************************************************************"<<endl;
    SetConsoleTextAttribute(GetStdHandle(STD_OUTPUT_HANDLE), 9);
    cout<<"Please enter a name : ";
    cin>>sch_name;
        for(int i=0; i<20; i++) {
                if(strcmp(phonelist[i].name,sch_name)==0) { // compare two char array
                    SetConsoleTextAttribute(GetStdHandle(STD_OUTPUT_HANDLE), 12);
                    cout<<"Person is found !!!"<<endl;
                    SetConsoleTextAttribute(GetStdHandle(STD_OUTPUT_HANDLE), 15);
                    cout<<"Index...........................: "<<i<<endl;;
                    cout<<"Id..............................: "<<phonelist[i].id<<endl;;
                    cout<<"Name............................: "<<phonelist[i].name<<endl;
                    cout<<"Surname.........................: "<<phonelist[i].surname<<endl;
                    cout<<"Phone...........................: "<<phonelist[i].phone<<endl;
                    break;
                }
                else if(i==19) {
                    SetConsoleTextAttribute(GetStdHandle(STD_OUTPUT_HANDLE), 12);
                    cout<<"Person is not found !!!"<<endl;
                }
        }
} // search person

void func_upd() {
    char sch_name[20];
    char upd_line;
    system("CLS");
    SetConsoleTextAttribute(GetStdHandle(STD_OUTPUT_HANDLE), 12);
cout<<"******************************************************************"<<endl;
    cout<<"\t\t\t UPDATE A PERSON"<<endl;
cout<<"******************************************************************"<<endl;
    SetConsoleTextAttribute(GetStdHandle(STD_OUTPUT_HANDLE), 9);
    cout<<"Please enter a name : ";
    cin>>sch_name;
        for(int i=0; i<20; i++) {
                if(strcmp(phonelist[i].name,sch_name)==0) { // compare two char array
                    SetConsoleTextAttribute(GetStdHandle(STD_OUTPUT_HANDLE), 12);
                    cout<<"Person is found !!!"<<endl;
                    SetConsoleTextAttribute(GetStdHandle(STD_OUTPUT_HANDLE), 15);
                    cout<<"    Index...........................: "<<i<<endl; // pk
                    cout<<"    Id..............................: "<<phonelist[i].id<<endl;; // id
                    cout<<"1-) Name............................: "<<phonelist[i].name<<endl;
                    cout<<"2-) Surname.........................: "<<phonelist[i].surname<<endl;
                    cout<<"3-) Phone...........................: "<<phonelist[i].phone<<endl;
                    tryagain:
                    SetConsoleTextAttribute(GetStdHandle(STD_OUTPUT_HANDLE), 9);
                    cout<<"Which line you want to change 1-3 : ";
                    cin>>upd_line;
                    SetConsoleTextAttribute(GetStdHandle(STD_OUTPUT_HANDLE), 15);
                        switch(upd_line) {
                            case '1' : {
                                    cout<<"Please enter new name : ";
                                    cin>>phonelist[i].name;
                                    break;
                                     }
                            case '2' : {
                                    cout<<"Please enter new surname : ";
                                    cin>>phonelist[i].surname;
                                    break;
                                     }
                            case '3' : {
                                    cout<<"Please enter new phone number : ";
                                    cin>>phonelist[i].phone;
                                    break;
                                     }
                            default : {
                                goto tryagain; // out of range
                                      }
                        }
                        SetConsoleTextAttribute(GetStdHandle(STD_OUTPUT_HANDLE), 12);
                        cout<<"Person is updated !!!"<<endl;
                        break;
                }
                else if(i==19) {
                    SetConsoleTextAttribute(GetStdHandle(STD_OUTPUT_HANDLE), 12);
                    cout<<"Person is not found !!!"<<endl;
                }
        }
} // update person

void func_srt() {
    int temp_id;
    char temp_name[20];
    char temp_surname[20];
    char temp_phone[20];
             for (int i = (cnt-cnt_del - 1); i > 0; i--) {
                for (int j = 1; j <= i; j++) {
                     if (phonelist[j-1].id > phonelist[j].id) { // ascending...
                          temp_id = phonelist[j-1].id;
                          strcpy(temp_name,phonelist[j-1].name);
                          strcpy(temp_surname,phonelist[j-1].surname);
                          strcpy(temp_phone,phonelist[j-1].phone);
                          phonelist[j-1].id = phonelist[j].id;
                          strcpy(phonelist[j-1].name,phonelist[j].name);
                          strcpy(phonelist[j-1].surname,phonelist[j].surname);
                          strcpy(phonelist[j-1].phone,phonelist[j].phone);
                          phonelist[j].id = temp_id;
                          strcpy(phonelist[j].name,temp_name);
                          strcpy(phonelist[j].surname,temp_surname);
                          strcpy(phonelist[j].phone,temp_phone);
                    }
                 }
             }
    system("CLS");
    SetConsoleTextAttribute(GetStdHandle(STD_OUTPUT_HANDLE), 12);
cout<<"******************************************************************"<<endl;
    cout<<"\t\t\t SORT ALL PERSON"<<endl;
cout<<"******************************************************************"<<endl;
    SetConsoleTextAttribute(GetStdHandle(STD_OUTPUT_HANDLE), 15);
        for(int i=0; i<cnt-cnt_del; i++) {
                cout<<"Index..: "<<i<<" Id..: "<<phonelist[i].id<<"\t"<<phonelist[i].name<<"\t\t"<<phonelist[i].surname<<"\t\t"<<phonelist[i].phone<<endl;
            }
        if(cnt==0) {
                SetConsoleTextAttribute(GetStdHandle(STD_OUTPUT_HANDLE), 12);
                cout<<"There is no any record !!!"<<endl;
            }
}

int main() {
    start:
    system("CLS");
    SetConsoleTextAttribute(GetStdHandle(STD_OUTPUT_HANDLE), 12);
cout<<"******************************************************************"<<endl;
    cout<<"\t\t\t PHONEBOOK MAIN MENU"<<endl;
cout<<"******************************************************************"<<endl;
    SetConsoleTextAttribute(GetStdHandle(STD_OUTPUT_HANDLE), 9);
    cout<<"Please Select Action 1 to 7"<<endl;
    SetConsoleTextAttribute(GetStdHandle(STD_OUTPUT_HANDLE), 15);
    cout<<"1-) ADD a person to phonebook"<<endl;
    cout<<"2-) DELETE a person from phonebook"<<endl;
    cout<<"3-) LIST data in phonebook"<<endl;
    cout<<"4-) SEARCH person from phonebook"<<endl;
    cout<<"5-) UPDATE a person from phonebook"<<endl;
    cout<<"6-) SORT date in phonebook"<<endl;
    cout<<"7-) QUIT program"<<endl;
    SetConsoleTextAttribute(GetStdHandle(STD_OUTPUT_HANDLE), 9);
    cout<<"Choice >> ";
    char choice;
    cin>>choice;
        switch(choice) {
            case '1' : {
                func_add(); break;
                     }
            case '2': {
                func_del(); break;
                    }
            case '3' : {
                func_lst(); break;
                     }
            case '4' : {
                func_sch(); break;
                     }
            case '5' : {
                func_upd(); break;
                     }
            case '6' : {
                func_srt(); break;
                     }
            case '7' : {
                SetConsoleTextAttribute(GetStdHandle(STD_OUTPUT_HANDLE), 12);
                cout<<"All record will be lost !!! Are you sure want to exit ? (Y)es-(N)o : ";
                char yes_no;
                cin>>yes_no;
                    if(yes_no=='Y' || yes_no=='y') {
                        return 0;
                        }
                    else {
                        goto start;
                        }
                       }
            default : {
                goto start;
                      }
            }
    SetConsoleTextAttribute(GetStdHandle(STD_OUTPUT_HANDLE), 9);
    system("PAUSE");
    goto start;
} // main fonksiyon
 
Pa help nman po sa string conversion a=1 b=2 c=3 d=4 e=5 .... z=26

Ang output nya po dapat ay:

Enter character: A B C D E

Tapos ang ikakalabasan ay: 01 02 03 04 05

gamit ka ASCII code niyan..

halimbawa..

A = 65 sa ASCII
B = 66 sa ASCII

eh di, every input, magsubtract ka lang ng 65 :thumbsup:
 
Re: -= Having Difficulties in C++ and Java? Be a Part of Thi

up for this thread :)
 
Re: -= Having Difficulties in C++ and Java? Be a Part of Thi

HELP! PAKI-IMPROVE PO, SA BABA PO UNG GAGAWIN.


#include <iostream>
using namespace std;

int IsPrime(int num){
int answer = 1;
for(int i = 2; i <= num/2; i++){
if(num % i == 0){
answer = 0;
break;
}
}
return answer;
}

int main (){

int num;
cout << "Enter a number: ";
while(cin >> num){
int ans = IsPrime(num);
if (ans == 0)
cout << num << " is a COMPOSITE number" << endl;
if( ans != 0 )
cout << num << " is a PRIME number" << endl;
cout << endl << "Enter a number: ";
}
return 0;
}


Kelangan ko to, pero pwede paki-improve?
instead na COMPOSITE number ang output, PRIME FACTORS and lalabas...


ex.
ENTER A NUMBER:
>> 8
2 2 2 or 2.2.2 or 2*2*2

thanks..
 
Re: -= Having Difficulties in C++ and Java? Be a Part of Thi

public class Number{
public static void main(String[] args){
for(int x=1; x<=5; x++)
for(int y=5; y>=1; y--)
System.out.print(x+y);
}
}

Output:
65432765438765498765109876
ng Dr Java

patulong kung paano magiging output niya ay:
1524334251

thanks.
 
Re: -= Having Difficulty in C++? Be a Part of This Thread =-

pahelp naman po.. baka merun kayu jan program ng cyclic group and cyclic notation.. :( ang hirap po kasi d ko magawa
 
Re: -= Having Difficulties in C++ and Java? Be a Part of Thi

public class Number{
public static void main(String[] args){
for(int x=1; x<=5; x++)
for(int y=5; y>=1; y--)
System.out.print(x+y);
}
}

Output:
65432765438765498765109876
ng Dr Java

patulong kung paano magiging output niya ay:
1524334251

thanks.

Code:
int y = 5;
for(int x=1; x<=5; x++){
	System.out.print(x + "" + y);
	y--;
}

- - - Updated - - -

HELP! PAKI-IMPROVE PO, SA BABA PO UNG GAGAWIN.


#include <iostream>
using namespace std;

int IsPrime(int num){
int answer = 1;
for(int i = 2; i <= num/2; i++){
if(num % i == 0){
answer = 0;
break;
}
}
return answer;
}

int main (){

int num;
cout << "Enter a number: ";
while(cin >> num){
int ans = IsPrime(num);
if (ans == 0)
cout << num << " is a COMPOSITE number" << endl;
if( ans != 0 )
cout << num << " is a PRIME number" << endl;
cout << endl << "Enter a number: ";
}
return 0;
}


Kelangan ko to, pero pwede paki-improve?
instead na COMPOSITE number ang output, PRIME FACTORS and lalabas...


ex.
ENTER A NUMBER:
>> 8
2 2 2 or 2.2.2 or 2*2*2

thanks..

dapat minodify mo nalang po yung code na binigay ko dun sa thread na ginawa mo po, same rin naman po yun

Code:
#include <iostream>
using namespace std;

void composite(int num){
	for (int i = 2; i <= num; i++){
		while(num % i == 0){ 
           num = num / i;
           cout << i;             
           if(i<= num)            
               cout << "*";          
        }	      
    }
	cout << endl;
}

int IsPrime(int num){
	int answer = 1;
	for(int i = 2; i <= num/2; i++){
		if(num % i == 0){
			answer = 0;
			break;
		}		
	}
	return answer;
}   

int main (){

	int num;
	cout << "Enter a number: ";
	while(cin >> num){
		if (IsPrime(num))
			cout << num << " is a PRIME number" << endl;
		else
			composite(num);
			
		cout << endl << "Enter a number: ";
	}
	return 0;
}

pwede mo pa po yan mapolish kung gusto mo :)
 
Last edited:
Re: -= Having Difficulty in C++? Be a Part of This Thread =-

thanks dito ts :thumbsup:
 
Re: -= Having Difficulty in C++? Be a Part of This Thread =-

wow nice thred sir ... :D
 
Back
Top Bottom