Jumat, 25 Maret 2016

tugas pertemuan 4
dev c++ 4.1

#include <iostream>

/* run this program using the console pauser or add your own getch, system("pause") or input loop */
using namespace std;
int main(int argc, char** argv) {
int i;

for (i=1; i<=4; i++){
cout<<i;
}
return 0;
}
 
4.1 bentuk flowchat



dev c++ 4.2

#include <iostream>
using namespace std;

/* run this program using the console pauser or add your own getch, system("pause") or input loop */

int main(int argc, char** argv) {
int i;
for(i=0;i<=10;i++){
if(i%2==1){
cout<<i<<",";
}
}
return 0;
}
 bentuk flowchat 4.2



dev c++ 4.3

#include <iostream>

/* run this program using the console pauser or add your own getch, system("pause") or input loop */
using namespace std;
int main(int argc, char** argv) {
int i,n,jum=0,x;
float rata;
cout<<"Masukkan jumlah data= "; cin>>n;
for(i=1;i<=n; i++){
cout<<"Data ke-"<<i<<": "; cin>>x;
jum+=x;
}
rata=jum/n;
cout<<endl;
cout<<"Rata-rata= "<<rata;
return 0;
}

betuk flowchat 4.3


dev c++ 4.4

#include <iostream>
#include <cstdlib>

/* run this program using the console pauser or add your own getch, system("pause") or input loop */

using namespace std;

int main(int argc, char** argv) {
   int y,x,rata;
   float jumlah;
 
   jumlah =0;
   y =1;
   x =0;
   while (!(x < 0)){
      jumlah = jumlah + x;
      cout<<"Data ke-"<<y<<" = ";
      cin>>x;
   y=y+1;
   }
   cout<<"Jumlah bilangan integer positif adalah "<<jumlah<<endl;
   rata = jumlah /(y-2);
   cout<<"Rata-ratanya adalah "<<jumlah<<" / "<<(y-2)<<" = "<<rata<< endl;

return 0;
}

bentuk flowchat 4.4


bentuk dev c++  4.7

#include <iostream>

using namespace std;

/* run this program using the console pauser or add your own getch, system("pause") or input loop */

int main(int argc, char** argv) {
int a,b,i;
int pangkat=1;
cout<<"      Menghitung Hasil Pngkat"<<endl<<endl;
cout<<"Masukkan bilangan       = "; cin>>a;
cout<<"Masukkan jumlah pangkat = ";cin>>b;
for(i=1;i<=b;i++){
pangkat*=a;
}cout<<a<<"pangkat"<<b<<"="<<pangkat;
return 0;
}

bentuk flowchat 4.7



dev c++ 4.8

#include <iostream>
#include <cstdlib>

/* run this program using the console pauser or add your own getch, system("pause") or input loop */

using namespace std;

int main(int argc, char** argv) {
   int i, jumlah, b, a;
   i =1;
   jumlah =0;

   cout<<"Masukkan nilai a = ";
   cin>>a;
   cout<<"Masukkan nilai b = ";
   cin>>b;
 
   while (!(i>abs(b)))
   {
      jumlah =jumlah+a;
      i =i+1;
   }
   if (b<0)
   {
      jumlah =-jumlah;
   }
   cout<<a<<" x "<<b<< " = " <<jumlah<<endl;
 
   system("PAUSE");

return 0;
}

bentuk flowchat 4.8




Tidak ada komentar:

Posting Komentar