C / C++ program to print the table for a particular number

Leave a Comment
/* The following C/C++ program will print the table of any number entered. The following program can be extended to print tables for 'n' numbers by inserting the table() function in a loop or making multiple call of it */

Code:
#include<iostream>
#include<conio.h>
using namespace std;
void table (int a)
{
int i=1;
while (i<=10)
{
cout<<a<<"*"<<i<<"="<<a*i<<endl;
i++;
}
}
int main ()
{
int a;
cout<<"Enter Number:";
cin>>a;
cout<<endl<<"Table of Number :"<<a<<endl;
table(a);
getche();
return 0;
}


Output:
Output of C / C++ program to print the table for a particular number
Output of C / C++ program to print the table for a particular number

Read More...

C++ program to copy a text file to another text file

3 comments
/* “fstream" class is used for both reading and writing a file. So we need to copy the contents of a file into another file than we will use “fstream”, it has functions capable of both reading & writing in the file. NOTE: both the text file has to be present initially. */

Code:
#include<iostream>
#include<conio.h>
#include<fstream>
using namespace std;
int main ()
{
fstream a,b;
char ch;
a.open("bunty.txt");
//The file from which the content will be copied
b.open("babli.txt"); //The file to which the content will be copied
while (!a.eof())
{
a.get(ch);
//reading from file object 'a'
cout<<ch;
b<<ch;
//writing to file babli.txt
}
a.close();
b.close();
return 0;
}



Read More...

C / C++ Program to calculate element wise product of 2 arrays : element wise multiplication

Leave a Comment
/* The following C / C++ program require user to enter the elements of arrays having equal number of array elements. Equal number of array elements are required in this program. This program can be extended to any of the data type & to the 'n' number of arrays simultaneously*/

Code:
#include<iostream>
#include<conio.h>
using namespace std;
void main ()
{
int long a[100],b[100],c[100];
int d=0,n;
cout<<"Number of Elements in Arrays: ";
cin>>n;
cout<<"Enter For Array 1"<<endl;
while (d<n)
{
cout<<"Enter the element number "<<d+1<<" : ";
cin>>a[d];
d=d+1;
}
d=0;
cout<<"Enter For Array 2"<<endl;
while (d<n)
{
cout<<"Enter the element number "<<d+1<<" : ";
cin>>b[d];
d=d+1;
}
d=0;
while (d<n)
{
c[d]=a[d]*b[d];
d=d+1;
}
d=0;
cout<<"\nResult of element wise product of array elements:\n";
while (d<n)
{
cout<<c[d]<<"\t";
d=d+1;
}
getche();
}


Output

Output of C / C++ Program to calculate element wise product of 2 arrays : element wise multiplication
Output of C / C++ Program to calculate element wise product of 2 arrays : element wise multiplication
 
Read More...

C / C++ Program to calculate element wise sum of 2 arrays : element wise addition

Leave a Comment
/* The following C / C++ program require user to enter the elements of arrays having equal number of array elements. Equal number of array elements are required in this program. This program can be extended to any of the data type & to the 'n' number of arrays simultaneously*/

Code:
#include<iostream>
#include<conio.h>
using namespace std;
void main ()
{
int long a[100],b[100],c[100];
int d=0,n;
cout<<"Number of Elements in Arrays: ";
cin>>n;
cout<<"Enter For Array 1"<<endl;
while (d<n)
{
cout<<"Enter the element number "<<d+1<<" : ";
cin>>a[d];
d=d+1;
}
d=0;
cout<<"Enter For Array 2"<<endl;
while (d<n)
{
cout<<"Enter the element number "<<d+1<<" : ";
cin>>b[d];
d=d+1;
}
d=0;
while (d<n)
{
c[d]=a[d]+b[d];
d=d+1;
}
d=0;
cout<<"\nResult of element wise sum of array elements:\n";
while (d<n)
{
cout<<c[d]<<"\t";
d=d+1;
}
getche();
}


Output
Output of C / C++ Program to calculate element wise sum of 2 arrays
Output of C / C++ Program to calculate element wise sum of 2 arrays

Read More...

C / C++ Program to find the sum of elements from 2 array of integers

Leave a Comment
/* The following program will ask the user to enter the elements of the integer array & then will return the total sum of the array elements. The following program could be expanded to calculate the sum of 'n' number of arrays & also in order to save the memory we can reuse the same array. Of the data is not required further */

Code:
#include<iostream>
#include<conio.h>
using namespace std;
void main ()
{
int long a[100],b[100],sum=0;
int d=0,e;
cout<<"Number of Elements in Array 1: ";
cin>>e;
cout<<"Enter For Array 1"<<endl;
while (d<e)
{
cout<<"Enter the element number "<<d+1<<" : ";
cin>>a[d];
d=d+1;
}
d=0;
while (d<e)
{
sum=sum+a[d];
d=d+1;
}
d=0;
cout<<"\nNumber of Elements in Array 2: ";
cin>>e;
cout<<"Enter For Array 2"<<endl;
while (d<e)
{
cout<<"Enter the element number "<<d+1<<" : ";
cin>>b[d];
d=d+1;
}
d=0;
while (d<e)
{
sum=sum+b[d];
d=d+1;
}
cout<<"Sum is : "<<sum;
getche();
}


Output:
C / C++ Program to find the sum of elements from 2 array of integers
C / C++ Program to find the sum of elements from 2 array of integers

Read More...

C / C++ Program For Entering Grade & Getting an Automated Remark Using If-Else statements : Grade Automatic Feedbacking / Remarking System

Leave a Comment
/* In the following C / C++ program we need to enter the grade, the student got in the exam & the program will give an automated remark about that grade */

Code:-
#include<iostream>
#include<conio.h>
using namespace std;
void main ()
{
char a;
cout<<"Enter Grade You Got : ";
cin>>a;
if (a=='A' || a=='a')
{
cout<<"Excellent";
}
else if (a=='B' || a=='b')
{
cout<<"Very Good";
}
else if (a=='C' || a=='c')
{
cout<<"Good";
}
else if (a=='D' || a=='d')
{
cout<<"Satisfactory";
}
else if (a=='E' || a=='e')
{
cout<<"Acceptable";
}
else if (a=='F' || a=='f')
{
cout<<"You Failed!";
}
else
{
cout<<"Entered grade is not valid";
}
getche();
}



Output:
C / C++ Program For Entering Grade & Getting an Automated Remark Using If-Else statements : Grade Automatic Feedback / Remarking System
C / C++ Program For Entering Grade & Getting an Automated Remark Using If-Else statements : Grade Automatic Feedback / Remarking System

Read More...

C / C++ Program to find the Smallest number from the array of integers

Leave a Comment
/* The following C / C++ Program will find the smallest number among numbers in the integer array thus entered by the user. We have used while loop to read & write the array*/

Code:-
#include<iostream>
#include<conio.h>
using namespace std;
void main ()
{
int a[100];
int min,b=0,c,n;
cout<<"\nEnter the total number of elements in array(<100):";
cin>>n;
while (b<n)
{
cout<<"Enter the element number "<<b<<" : ";
cin>>c;
a[b]=c;
b=b+1;
}
b=0;
min=a[b];
//assuming that the 1st element is the minimum
while (b<n)
{
if (a[b]<=min)
//if anything else is found to be more larger than the current minimum
{
min=a[b];
}
b=b+1;
}
cout<<"\nSmallest number is : "<<min;
getche();
}



Output:
C / C++ Program to find the Smallest number from the array of integers: Output
C / C++ Program to find the Smallest number from the array of integers
Read More...

C / C++ Program to find the Largest number from the array of integers

Leave a Comment
/* The following C / C++ Program will find the largest number among numbers in the integer array thus entered by the user. We have used while loop to read & write the array*/

Code:-
#include<iostream>
#include<conio.h>
using namespace std;
void main ()
{
int a[100];
int max,b=0,c,n;
cout<<"\nEnter the total number of elements in array(<100):";
cin>>n;
while (b<n)
{
cout<<"Enter the element number "<<b<<" : ";
cin>>c;
a[b]=c;
b=b+1;
}
b=0;
max=a[b];
//assuming that the 1st element is the maximum
while (b<n)
{
if (a[b]>=max)
//if anything else is found to be more larger than the current maximum
{
max=a[b];
}
b=b+1;
}
cout<<"\nLargest number is : "<<max;
getche();
}



Output:
C / C++ Program to find the Largest number from the array of integers
C / C++ Program to find the Largest number from the array of integers

Read More...

C / C++ Program Code To Remove Duplicate Elements From An Array Of Integers

Leave a Comment
/* The Program will first ask the user to enter the maximum limit of the array. Then the user is allowed to enter the array elements specified. The program will remove any of the element which is present in it more than once. Hence the result thus produced is free from duplicate elements */
//CODE:-
#include<stdio.h>
#include<stdlib.h>
int main()
{
    int n, a[10], b[10], count = 0, c, d;
    printf("Enter number of elements:");
    scanf("%d",&n);
    printf("Enter %d integers\n", n);
    for(c=0;c<n;c++)
        scanf("%d",&a[c]); 
//Getting the array elements

    for(c=0;c<n;c++)
//For removing duplicate elements
    {
        for(d=0;d<count;d++)
        {
            if(a[c]==b[d])
                break;
        }
        if(d==count)
        {
            b[count] = a[c];
            count++;
        }
    }
    printf("Array after removing duplicate elements\n");
    for(c=0;c<count;c++)
        printf("%d\t",b[c]);

    system("pause");
    return 0;
}


SCREENSHOT:
C / C++ Program Code To Remove Duplicate Elements From An Array Of Integers: Output after removing duplicate elements
C / C++ Program Code To Remove Duplicate Elements From An Array Of Integers: Output after removing duplicate elements

Read More...

C / C++ Program that count lines, integers, lower case letters, uper case letters, special case letters, words, spaces, consonants & vowels in a paragraph.

Leave a Comment
/* The  following C / C++ Program will count lines, integers, lower case letters, uper case letters, special case letters, words, spaces, consonants & vowels in a paragraph. User has to just enter the words/sentence/paragraph */

//CODE:-
#include<iostream>
#include<iomanip>
#include<stdlib.h>
using namespace std;
int main()
{
const int maxlength = 1000;
char text[maxlength] = {0};
cout<<"Enter few words:\n\n";
cin.getline(text,maxlength);
cout<<"You Have Entered:\n"<<text<<endl;
int space=0;
int vow=0;
int consonants=0;
int special=0;
int ucase=0;
int lcase=0;
int intr=0;
int line=0;
for(int i = 0 ; text[i] != '\0' ; i++)
{
if(isalpha(text[i]))
{
if(text[i]>=65 && text[i]<=90)
{
ucase++;
}
else if(text[i]>=97 && text[i]<=122)
{
lcase++;
}
switch(tolower(text[i]))
{
case 'a':
case 'e':
case 'i':
case 'o':
case 'u':
vow++;
break;
default:
consonants++;
break;
}}
else if(text[i]==' ')
{
space++;
}
else if((text[i]>=0&&text[i]<=47)||(text[i]>=58&&text[i]<=64)||(text[i]>=91&&text[i]<=96)||(text[i]>=123&&text[i]<=127))
{
special++;
}
else if(text[i]>=48 && text[i]<=57)
{
intr++;
}
else if(text[i]=='\n')
{
line++;
}
}
cout<<"No. of vowels="<<vow<<endl;
cout<<"No. of consonants="<<consonants<<endl;
cout<<"No. of spaces="<<space<<endl;
cout<<"No. of words="<<space+1<<endl;
cout<<"No. of special letters="<<special<<endl;
cout<<"No. of upper case letters="<<ucase<<endl;
cout<<"No. of lower case letters="<<lcase<<endl;
cout<<"No. of integers="<<intr<<endl;
cout<<"No. of lines="<<line;
system("pause");
return 0;
}


Screenshots:
C / C++ Program that count lines, integers, lower case letters, uper case letters, special case letters, words, spaces, consonants & vowels in a paragraph.
C / C++ Program that count lines, integers, lower case letters, uper case letters, special case letters, words, spaces, consonants & vowels in a paragraph.

Read More...