C++ programming code
#include
#include
int main()
{
int n, status = 1, num = 3, count, c;
cout << "enter the number of prime numbers to print\n";
cin >> n;
if ( n >= 1 )
{
cout << "first " << n <<" prime numbers are :-" << endl;
cout << 2 << endl;
}
for ( count = 2 ; count <=n ; )
{
for ( c = 2 ; c <= (int)sqrt(num) ; c++ )
{
if ( num%c == 0 )
{
status = 0;
break;
}
}
if ( status != 0 )
{
cout << num << endl;
count++;
}
status = 1;
num++;
}
return 0;
}
C++ programming code
#include
#include
main()
{
int n, c, first = 0, second = 1, next;
cout << "enter the number of terms of fibonacci series you want" << endl;
cin >> n;
cout << "first " << n << " terms of fibonacci series are :- " << endl;
for ( c = 0 ; c < n ; c++ )
{
if ( c <= 1 )
next = c;
else
{
next = first + second;
first = second;
second = next;
}
cout << next << endl;
}
return 0;
}
C++ programming code
#include
#include
main()
{
int first[20], second[20], c, n;
cout << "enter the number of elements in the array ";
cin >> n;
cout << "enter elements of first array " << endl;
for ( c = 0 ; c < n ; c++ )
cin >> first[c];
cout << "enter elements of second array " << endl;
for ( c = 0 ; c < n ; c++ )
cin >> second[c];
cout << "sum of elements of two arrays " << endl;
for ( c = 0 ; c < n ; c++ )
cout << first[c] + second[c] << endl;
return 0;
}
No comments:
Post a Comment