You are on page 1of 8

Q. WAP to print first 10 natural numbers.

#include<iostream.h>
#include<conio.h>
void main()
{
clrscr();
int i;
cout<<"natural numbers are:"<<"\n";
for(i=1;i<=10;i++)
cout<<i<<endl;
getch();
}
OUTPUT:
Q. WAP to find minimum and maximum value of a given array.

#include <iostream.h>
#include <conio.h>
void main()
{
int num[100], min, max, i, size;
clrscr();
cout << "Enter the size of your array ... ";
cin >> size;
cout << "Please enter the Values ... \n";
for (i = 0; i < size; i++)
cin >> num[i];
max = num[0];
min = num[0];
for (i = 0; i < size; i++)
{
if (num[i] > max)
max = num[i];
if (num[i] < min)
min = num[i];
}
cout << "The maximum value in the list is " << max << endl;
cout << "The minimum value in the list is " << min << endl;
getch();
}
OUTPUT:
Q. WAP to find total number of vowels, digits and other characters in string.

#include <iostream.h>
#include <conio.h>
#include <ctype.h>
#include <stdio.h>
void main()
{
char str[80];
int i, vc= 0, dc = 0, ot = 0;
clrscr();
cout << "\n\tEnter any string: ";
gets(str);
i = 0;
while (str[i] != '\0')
{
str[i] = tolower(str[i]);
if (((str[i] == 'a')) || ((str[i] == 'e')) || ((str[i] == 'o')) || ((str[i] == 'u')))
vc++;
else
if ((str[i] >= '0') && (str[i] <= '9'))
dc++;
else
ot++;
i++;
}
cout << "\n\tNumber of vowels are : " << vc;
cout << "\n\tNumber of digits are : " << dc;
cout << "\n\tNumber of other characters are : " << ot;
getch();
}
OUTPUT:
Q. WAP to find whether the entered number is prime or not.

#include <iostream.h>
#include <conio.h>
main()
{
int n, i = 2, flag;
cout << "\n\t\t Enter any number => ";
cin >> n;
if ((n == 2) || (n == 3))
cout << n << " is prime";
if (n > 3)
{
while (i < n)
{
if (n % i == 0)
{
flag = 1;
break;
}
i++;
}
}
if (flag == 1)
cout << "\n\n\t\tThe number is not prime ";
else
cout << "\n\n\t\tThe number is prime ";
getch();
}
OUTPUT: