1. Output : 1 2 3 4 5
Program :
#include <iostream>
using namespace std;
int main() {
int a;
for(a=1;a<6;a++){
cout<<a;
}
return 0;
}
2. Output : 2 4 6 8 10 12 14
Program :
#include <iostream>
using namespace std;
int main() {
int b;
for(b=2;b<=14;b=b+2)
{
cout<<b<<" ";
}
return 0;
}
3. Output : * * * * *
Program :
#include <iostream>
using namespace std;
int main() {
int x;
for(x=1;x<=5;x++)
{
cout<<"*";
}
return 0;
}
4. Output :
*
* *
* * *
* * * *
* * * * *
Program :
#include <iostream>
using namespace std;
int main() {
int a,b;
for(a=1;a<=5;a++)
{
for(b=1;b<=a;b++)
cout<<"*"<<"";
cout<<endl;
}
}
5. Output :
* * * * *
* * * *
* * *
* *
*
Program :
#include <iostream>
using namespace std;
int main() {
int a;
int b;
for(a=1;a<=5;a++)
{
for(b=1;b<=a;b++)
cout<<"*"<<"";
cout<<endl;
}
}
Tidak ada komentar:
Posting Komentar