Solve The Following Problems
Solve The Following Problems
The concept of generating table of any number is multiply particular number from 1 to 10.
num * 1
num * 2
num * 3
num * 4
num * 5
num * 6
num * 7
num * 8
num * 9
num * 10
Example
#include<iostream.h>
#include<conio.h>
void main(){
inti,no,table=1;
clrscr();
cout<<"Enter any num : ";
cin>>no;
cout<<"Table of "<<no;
for(i=1;i< =10;i++){
table=no*i;
cout<<" \n"<<table;
cout<<"\n";
}
getch();
}
Sort an Array Elements in Ascending Order in C++
Sort an array elements means arrange elements of array in Ascending Order and Descending Order. You
#include<iostream.h>
#include<conio.h>
void main(){
Inti,a[10],temp,j;
clrscr();
cout<<"Enter any 10 num in array: \n";
for(i=0;i<=10;i++)
cin>>a[i];
cout<<"\nData before sorting: ";
for(j=0;j<10;j++)
cout<<a[j];
for(i=0;i<=10;i++)
{
for(j=0;j<=10-i;j++)
{
if(a[j]>a[j+1])
{
temp=a[j];
a[j]=a[j+1];
a[j+1]=temp;
}
}
}
cout<<"\nData after sorting: ";
for(j=0;j<10;j++)
cout<<a[j];
getch();
}
Program in C++ to Convert Binary to Decimal
In this types of program we takes a binary number as input and converts it into decimal number.
Multiply each digits of the binary number starting from the last with the powers of 2
respectively.
#include<iostream.h>
#include<conio.h>
void main()
{
clrscr();
longintbin_number,dec_number=0,i=1, rem;
cout<<"Please Enter any Binary Number: ";
cin>>bin_number;
while(bin_number!=0)
{
rem=bin_number%10;
dec_number=dec_number+rem*i;
i=i*2;
bin_number=bin_number/10;
}
cout<<"Equivalent Decimal value:"<<dec_number;
getch();
}
C++ program to Count Frequency of Characters
Frequency of character in any string means how many times a particular character is present in any
string. For example; suppose we have string hitesh in this word h repeated 2 times, it is the frequency of h
in string hitesh.
Count Frequency of Characters in C++
#include<iostream.h>
#include<stdio.h>
#include<conio.h>
void main()
{
inti,count=0;
charch[20],c;
clrscr();
cout<<"Enter Any String: ";
gets(ch);
cout<<"Enter any Character form string: ";
cin>>c;
for(i=0;ch[i]!='\0';i++)
{
if(ch[i]==c)
count++;
}
if(count==0)
{
cout<<"Given character not found";
}
else
{
cout<<"Repetition of "<<c<<" "<<count<<" times";
}
getch();
}
C++ Program to Delete Vowels from Given String
To delete all the vowels (i.e., a, A, e, E, i, I, o, O, u, U) from the string in C++ program. In case of english
alphabet their are 5 lower case letter and 5 captipal letter, in this programming code we remove all small as
well as capital letter from given string. You can also see this code in C Programming Language, C Program
#include<iostream.h>
#include<stdio.h>
#include<conio.h>
#include<string.h>
void main()
{
charstr[20];
intlen,i, j;
clrscr();
cout<<"Please Enter any String: ";
gets(str);
len=strlen(str);
for(i=0;i<len;i++)
{
if(str[i]=='a'||str[i]=='e'||str[i]=='i'||str[i]=='o'||str[i]=='u'||str[i]=='A'||
str[i]=='E'||str[i]=='I'||str[i]=='O'|| str[i]=='U')
{
for(j=i; j<len;j++)
str[j]=str[j+1];
len--;
}
}
cout<<"After Deleting the vowels, the String is:"<<str;
getch();
}