This is a collection of sample programs that use arrays in C + +, I hope the program - this program can be useful.
The first program
#include <iostream.h>
#include <conio.h>
void main () {
char kata[50];
int i,j,vokal=0,huruf=0;
cout<<"Masukkan Kata : ";
cin.get(kata, 50);
j=strlen(kata);
for (i=0;i<j;i++) {
if (kata[i]=='a' || kata[i]=='i' || kata[i]=='u' || kata[i]=='e' ||kata[i]=='o')
{
vokal++;
} else
huruf++;
}
cout<<"Huruf Vokal : "<<vokal<<endl;
cout<<"Huruf non Vokal : "<<huruf<<endl;
getche();
}
The second program
#include <stdio.h>
#include <conio.h>
void main()
{
int i,j;
printf("P\tQ\tP or Q\tP and Q\tNot P\tP xor Q\n");
printf("=================================================\n");
for(i=1;i>=0;i--)
{
for(j=1;j>=0;j--)
{
printf("%d\t%d\t%d\t%d\t%d\t%d\n",i,j,(i || j),(i && j),!i,(i ^ j));
}
}
getch();
}
The third program
#include <iostream.h>
#include <stdio.h>
#include <conio.h>
void main()
{
//deklarasi variabel
int i,n,f=1,f2=1,fibo;
printf("PROGRAM DERET FIBONACCI \n");
printf("------------------------\n");
printf("Silakan Masukkan Nilai n = ");
scanf("%d",&n);
printf("Deret Fibonaccinya Adalah -> 1 \n");
for(i=1;i<=n-2;i++)
{
printf("%d ",f2);
fibo=f+f2;
f = f2;
f2 = fibo;
}
printf("%d\n",fibo);
printf("------------------------\n");
printf("Hasil = %d",fibo);
printf("\n------------------------\n");
getch();
}
Tidak ada komentar:
Posting Komentar