0% found this document useful (0 votes)
48 views8 pages

4 Questions

The document contains code snippets for 4 different C++ programs: 1) A program to print the first 10 natural numbers using a for loop. 2) A program to find the minimum and maximum values in an array by iterating through it. 3) A program to count the vowels, digits, and other characters in a string. 4) A program to determine if a given number is prime or not using modulo to check for factors.

Uploaded by

Deepak Shakya
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOC, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
48 views8 pages

4 Questions

The document contains code snippets for 4 different C++ programs: 1) A program to print the first 10 natural numbers using a for loop. 2) A program to find the minimum and maximum values in an array by iterating through it. 3) A program to count the vowels, digits, and other characters in a string. 4) A program to determine if a given number is prime or not using modulo to check for factors.

Uploaded by

Deepak Shakya
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOC, PDF, TXT or read online on Scribd
You are on page 1/ 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:

You might also like