Nisaidieni swali hili la programming

uvivu huo endelea kusoma sisi hatukupata elimu kwa mtelezo huooo mburura weeee
 
Dogo swali jepesi hivyo unashindwa kugoogle mbona code za c na c++ nyingi sana labda ingekuwa java ngoja nikusaidie
 
Dogo swali jepesi hivyo unashindwa kugoogle mbona code za c na c++ nyingi sana labda ingekuwa java ngoja nikusaidie
Google nimejaribu, sijafanikiwa. Its urgent nisaidie tafadhari
 
Google nimejaribu, sijafanikiwa. Its urgent nisaidie tafadhari
Poa ngoja niinstall text editor naona dev yangu inasumbua mdogo wangu kitambo sana ayo mambo
 
Reactions: Paa
Katika picha
I am not that good kwenye C infact sijajifunza C, ila nimejaribu kuandika swali lako kwenye C++, nadhan ukipata idea hautashindwa ku convert kwenda kwenye C!!

Angalia hii code, kama patakua na marekebisho nitaongeza... ila naimani member wengine watatoa mawazo zaidi!!!

Version ONE, nimeweka kila kitu kwenye main function...
Code:
#include <iostream>

using namespace std;

int main()
{
    //local variables for sum and product of numbers
    int sum;
    int product;

    //for loop begins from here...
    for(int counter = 1; counter<=8; counter++){


        //takes the counter variable and find the sum of it...
        sum = counter+counter;

        //takes the counter variable and find the product of it...
        product = counter*counter;

        //display the sum of counter variable
        cout<< counter << "+" << counter << "=" << sum <<endl;


        //display the product of counter variable
        cout<< counter << "*" << counter << "=" << product <<endl;

    }

    return 0;
}


Version TWO, Nimejaribu kutenga codes kwenye functions 2 na kufanya "function prototyping"!

Code:
#include <iostream>

using namespace std;

void sumAndProduct(); //function prototyping...

int main()
{
    //calling "sumAndProduct" function
    sumAndProduct();
 
    return 0;
}


void sumAndProduct(){
 
    //local variables for sum and product of numbers
    int sum;
    int product;

    //for loop begins from here...
    for(int counter = 1; counter<=8; counter++){


        //takes the counter variable and find the sum of it...
        sum = counter+counter;

        //takes the counter variable and find the product of it...
        product = counter*counter;

        //display the sum of counter variable
        cout<< counter << "+" << counter << "=" << sum <<endl;


        //display the product of counter variable
        cout<< counter << "*" << counter << "=" << product <<endl;

    }

}

Same code in JAVA:

Code:
package com.company;

public class Main {

    public static void main(String[] args) {
   int sum, product;
// for loop begins here...
   for(int counter = 1; counter<=8; counter++){
//     sum of counter
       sum = counter+ counter;
//        product of counter
        product = counter*counter;
//        display sum of counter
        System.out.println(counter + "+" + counter + "=" + sum);

//        display product of counter
        System.out.println(counter + "*" + counter + "=" + product);
    }
    }
}
 
Reactions: Paa
Umesaidia kuharibu elimu ya bongo. Huyo hatasoma tena mbali ya kucopy na kupaste jibu.




 
Huu unaitwa uvivu yaani unaleta swali hata hujaonesha wewe umeshindwa wapi!? [emoji855]
 

Similar Discussions

Cookies are required to use this site. You must accept them to continue using the site. Learn more…