0% found this document useful (0 votes)
5 views

Execution Program

Uploaded by

amol raut
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
5 views

Execution Program

Uploaded by

amol raut
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 10

B.C.C.A.

Part I (Sem II) Component I Session 2020-2021

Assignment No. 1
Q:- Write an algorithm, draw a flowchart. Develop a c++ program to print sum
and product of digit of an integer.

Coding:-
#include<iostream.h>
#include<conio.h>
main()
{
int n,sum=0,prod=1,d,temp;
clrscr();
cout<<"enter any integer value";
cin>>n;
clrscr();
temp=n;
while(temp!=0)
{
d=temp%10;
temp=temp/10;
sum=sum+d;
prod=prod*d;
}
cout<<"number is= "<<n<<endl;
cout<<"sum= "<<sum<<endl;
cout<<"product= "<<prod<<endl;
getch();
}

Output:-

Prof. Shailesh Janbandhu G.S. College of Commerce, Wardha


B.C.C.A. Part I (Sem II) Component I Session 2020-2021

Assignment No:-2

Q.:- Write an algorithm draw a flowchart and develope a c++ program to


reverse a number.

Coding:-
#include<iostream.h>
#include<conio.h>
main()
{
long int num,rev=0,d,temp;
clrscr();
cout<<"enter any digit no:-";
cin>>num;
clrscr();
temp=num;
while(temp!=0)
{
d=temp%10;
temp=temp/10;
rev=(rev*10)+d;
}
cout<<"\t number= "<<num<<endl;
cout<<"\t reverse no= "<<rev<<endl;
getch();
}

Output:-

Prof. Shailesh Janbandhu G.S. College of Commerce, Wardha


B.C.C.A. Part I (Sem II) Component I Session 2020-2021

Assignment No:-3

Q. Write an algorithm, Draw a flowchart and develop a C++ program to


compute the following series.
S=1+1/2+1/3+1/4+1/5……n

Coding:-
#include<iostream.h>
#include<conio.h>
main()
{
int n,i=1;
float s,d;
clrscr();
cout<<"enter the value=";
cin>>n;
clrscr();
while(i<=n)
{
d=1.0/i;
s=s+d;
i++;
}
cout<<"the sum is= "<<s;
getch();
}
Output:-

Prof. Shailesh Janbandhu G.S. College of Commerce, Wardha


B.C.C.A. Part I (Sem II) Component I Session 2020-2021

Assignment No: - 4

Aim : Write an algorithm, draw a flowchart and develop a program to input any
year and check whether it is leap year or not.

Coding:-
#include<iostream.h>
#include<conio.h>
int main()
{
int year;
clrscr();
cout << "Enter a year: ";
cin >> year;
if (year % 4 == 0)
{
if (year % 100 == 0)
{
if (year % 400 == 0)
cout << year << " is a LEAP year.";
else
cout << year << " is not a LEAP year.";
} else
cout << year << " is a LEAP year.";
} else
cout << year << " is not a LEAP year.";
getch();
return 0;
}

Output :

Prof. Shailesh Janbandhu G.S. College of Commerce, Wardha


B.C.C.A. Part I (Sem II) Component I Session 2020-2021

Assignment No:-5
Q. Write a program in C++ to check given number is palindrome or not using
user define function.

Coding:-
#include<iostream.h>
#include<conio.h>
#include<string.h>
main()
{
int k;
char str[10],rstr[10];
clrscr();
cout<<"Enter the string=";
cin>>str;
strcpy(rstr,str);
cout<<"\n\nOriginal string is="<<rstr;
strrev(rstr);
cout<<"\n\nReverse string is="<<rstr;
k=strcmp(rstr,str);
if(k==0)
{
cout<<"\n\nstring is palindrome";
}
else
{
cout<<"\n\nstring is not palindrome";
}
getch();
}

Output:

Prof. Shailesh Janbandhu G.S. College of Commerce, Wardha


B.C.C.A. Part I (Sem II) Component I Session 2020-2021

Assignment no.6
Q. Write a program in c++ to print the following format also write its algorithm
and draw a flowchart.
*
***
*****
*******
Coding:-
#include<iostream.h>
#include<conio.h>
main()
{
int i,j,n,k=1;
clrscr();
cout<<"enter how many rows do you want:- ";
cin>>n;
clrscr();
for(i=1;i<=n;i++)
{
for(j=1;j<=k;j++)
{
cout<<"*";
}
k+=2;
cout<<endl;
}
getch();
}

Output:-

Prof. Shailesh Janbandhu G.S. College of Commerce, Wardha


B.C.C.A. Part I (Sem II) Component I Session 2020-2021

Assignment No.7

Q. Write an algorithm , draw a flowchart and develop a C++ program to swap


two number using pointer.

Coding:-
#include<iostream.h>
#include<conio.h>
void swap(int *a,int *b)
{
int c;
c =*a;
*a=*b;
*b=c;
}
main()
{
int x,y;
clrscr();
cout<<"enter the value for x:- ";
cin>>x;
cout<<"enter the value for y:- ";
cin>>y;
clrscr();
cout<<endl<<"before swap"<<endl;
cout<<"x= "<<x<<endl<<"y= "<<y;
swap(x,y);
cout<<endl<<"after swap"<<endl;
cout<<"x= "<<x<<endl<<"y= "<<y;
getch();
}
Output:-

Prof. Shailesh Janbandhu G.S. College of Commerce, Wardha


B.C.C.A. Part I (Sem II) Component I Session 2020-2021

Assignment No. 8

Q. Write an algorithm and flowchart and develop a c++ function that check to
whether a given number is prime or not. Generate the prime numbers less than
100.

Coding:-
#include<iostream.h>
#include<conio.h>
int prime(n)
{
int k=1,i;
for(i=2;i<=n-1;i++)
{
if(n%i==0)
{
k=0;
break;
}
}
return(k);
}
main()
{
int num, pri;
clrscr();
cout<<"enter any number:- ";
cin>>num;
clrscr();
pri=prime(num);
if(pri==1)
cout<<num<<" is prime number"<<endl;
else
cout<<num<<" is not prime number"<<endl;

getch();
}

Output:

Prof. Shailesh Janbandhu G.S. College of Commerce, Wardha


B.C.C.A. Part I (Sem II) Component I Session 2020-2021

Assignment No:-9

Q.write an algorithm draw a flowchart and develop a c++ program to compute


the factors of a given number.

Coding:-
#include<iostream.h>
#include<conio.h>
main()
{
int num,i;
clrscr();
cout<<"enter any number:- ";
cin>>num;
cout<<"factors of "<<num<<endl;
for(i=1;i<=num;i++)
{
if(num%i==0)
{
cout<<i<<"\t";
}
}
getch();
}

Output:-

Prof. Shailesh Janbandhu G.S. College of Commerce, Wardha


B.C.C.A. Part I (Sem II) Component I Session 2020-2021

Assignment No.10
Aim: Write an algorithm, draw a flowchart and develop a C++ program which
takes the radius of a circle as input from the user, passes it to another function
that computes the area and the circumference of the circle and displays the value
of area and circumference from the main() function.

Coding: -
#include<iostream.h>
#include<conio.h>
float area(float r)
{
float a;
a=3.14*r*r;
return(a);
}
float circum(float);
main()
{
float r,a,c;
clrscr();
cout<<"Enter the Radius:- ";
cin>>r;
a=area(r);
cout<<"Area of Circle= "<<a<<endl;
c=circum(r);
cout<<"Circumference of Circle= "<<c<<endl;
getch();
}
float circum(float c)
{
float ci;
ci=2*3.14*c;
return(ci);
}
Output:-

Prof. Shailesh Janbandhu G.S. College of Commerce, Wardha

You might also like