Professional Documents
Culture Documents
Program 1
Write a C++ program to print numbers from 1 to 10 using for loop.
Code
#include <iostream.h>
#include <conio.h>
#include <stdlib.h>
int main()
{
system("cls");
int a;
cout<<" The numbers from 1 to 10 are as follows:"<<endl;
for(a=1;a<=10;a++)
{
cout<<a<<endl;
}
system("pause");
return 0;
}Output
NAME:Vishwas Bhati
ROLL NUMBER:
Program 2
Write a C++ program to find the factorial of a number taking the input from the user.
Code
#include<iostream.h>
#include<conio.h>
int main()
{
clrscr();
int n, f=1;
cout<<"Enter the Number :";
cin>>n;
for (int i= 1; i<= n;i++)
{
f*=i;
}
cout<<"Factorial of "<<n<<" is "<<f;
getch();
return 0;
}
Output
NAME:Vishwas Bhati
ROLL NUMBER:
Program 3
Write a C++ program to input characters and change their case.
Code
#include <iostream.h>
#include <stdio.h>
int main()
{
char ch;
do
{
cout<<" Enter a character:";
ch=getchar();
if(ch=='\n')
ch=getchar();
cout<<endl;
if(ch>=65&&ch<=90)
ch=ch+32;
else
if(ch>=97&&ch<=122)
ch=ch-32;
putchar(ch);
cout<<endl;
}
while(ch!='0');
3
NAME:Vishwas Bhati
ROLL NUMBER:
Output
NAME:Vishwas Bhati
ROLL NUMBER:
Program 4
Write a C++ program to read a string and print its length.
Code
#include <iostream.h>
#include <string.h>
#include <stdio.h>
int main()
{
char astr[51];
int length;
cout<<"\n Enter a string (max 50 characters)\n ";
gets(astr);
length=strlen(astr);
puts(astr);
cout<<"\n The length of the string is :"<<length<<"\n";
return 0;
}
Output
NAME:Vishwas Bhati
ROLL NUMBER:
Program 5
Write a C++ program to count number of character entered.
Code
#include <iostream.h>
int main(){
int chcount=0;
const char ent='\n';
char ch;
cout<<"Enter character \n";
cin.get(ch);
while(ch!=ent)
{ chcount++;
cout.put(ch);
cin.get(ch);
}
cout<<"\n The number of characters ="<<chcount<<"\n";
return 0;
}
Output
NAME:Vishwas Bhati
ROLL NUMBER:
Program 6
Write a C++ program to whether two strings contain equal number of characters
Code
#include <iostream.h>
#include <string.h>
int main()
{
char string1[50],string2[50];
cout<<"Enter strings \n";
cin.getline(string1,50);
cin.getline(string2,50);
if (strlen(string1)==strlen(string2))
cout<<"\n Both strings contain equal number of characters"<<"\n";
else
cout<<"\n Both strings contain different number of characters"<<"\n";
return 0;
}
Output
NAME:Vishwas Bhati
ROLL NUMBER:
Code
#include <iostream.h>
#include <stdlib.h>
#include <conio.h>
int main() {
clrscr();
float marks[50];
for (int i=0;i<50;i++)
{
cout<<"Enter the marks of student"<<i+1<<":";
cin>>marks[i];
}
cout<<"\n";
for(i=0;i<50;++i)
cout<<"Marks["<<i<<"]="<<marks[i]<<"\n";
return 0;
}
Output
NAME:Vishwas Bhati
ROLL NUMBER:
Program 8
Write a C++ program to check of a string is palindrome or not
Code
#include <iostream.h>
int main()
{
char inputString[100];
int l, r, length = 0;
cout << "Enter a string for palindrome check\n";
cin >> inputString;
while(inputString[length] != '\0')
length++;
l = 0;
r = length -1;
NAME:Vishwas Bhati
ROLL NUMBER:
Output
10
NAME:Vishwas Bhati
ROLL NUMBER:
Program 9
Write a C++ program to print the largest element of an array(using functions)
Code
#include <iostream.h>
#include <stdlib.h>
int main()
{
system("cls");
float large (float arr[],int n);
char ch;
int i=0;
float amount[50],biggest;
for(i=0;i<50;i++)
{
cout<<"Enter element no. "<<(i+1)<<"\n";
cin>>amount[i];
cout<<"More elements? (y/n) \n";
cin>>ch;
if(ch!='y')
11
NAME:Vishwas Bhati
ROLL NUMBER:
}
float large(float arr[],int n)
{
float max=arr[0];
for(int j=1;j<n;++j)
{
if (arr[j]>max)
max=arr[j];
}
return max;
}
Output
12
NAME:Vishwas Bhati
ROLL NUMBER:
Program 10
Write a C++ program to calculate interest amount using function overloading. Calculate
interest amount using function overloading.
Code
#include <iostream.h>
#include <stdlib.h>
NAME:Vishwas Bhati
ROLL NUMBER:
NAME:Vishwas Bhati
ROLL NUMBER:
Output
15
NAME:Vishwas Bhati
ROLL NUMBER:
16
NAME:Vishwas Bhati
ROLL NUMBER: