Poa ngoja niinstall text editor naona dev yangu inasumbua mdogo wangu kitambo sana ayo mamboGoogle nimejaribu, sijafanikiwa. Its urgent nisaidie tafadhari
Poa ngoja niinstall text editor naona dev yangu inasumbua mdogo wangu kitambo sana ayo mambo
Aiseee!!Poa ngoja niinstall text editor naona dev yangu inasumbua mdogo wangu kitambo sana ayo mambo
Nin hujui devAiseee!!
Swala sio kujua au kuto kujua, jamaa anangoja majibu...nadhani usha install "text editor"...Nin hujui dev
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!!Katika picha
#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;
}
#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;
}
}
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);
}
}
}
Njia sahihi ya kuuliza maswali ya programming ni kufanya mweneywe kisha kuweka code yako mpaka ulipofikia kama umeshindwa watu wakusaidie, kwa kupewa tu kwenye basics za namna hii utamaliza kozi hujui unachofanya.Katika picha
==== unamuingiza chaka lakini ni sawa tu. yeye si ataki kusoma vitabu!!Mkuu hapo unatumia Switch case
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); } } }
Swali limesema tumia for loop na sio switch case...Mkuu hapo unatumia Switch case
Wenzako wameweka code wewe unaweka maneno....Mkuu mm naweza kukusaidia lkn kwa language ya python