C++ PRACTICAL NO : 1
BASIC PROGRAMS
INPUT:1-
/* Online C++ Compiler and Editor */
/* SURAJ SANTOSH CHAVAN M010 57502240010 */
#include <iostream>
using namespace std;
int main()
{
int a,b,c;
start:
cout<< "enter first number: ";
cin>>a;
cout<<endl;
cout << "enter second number: ";
cin>>b;
cout<<endl;
c=a+b;
cout<<"the sum of"<<a<<" and "<<b<<" is: "
<<c<<endl;
goto start;
return 0;
}
OUTPUT:1-
1|Page
INPUT:2-
/* Online C++ Compiler and Editor */
/* SURAJ SANTOSH CHAVAN M010 57502240010 */
#include <iostream>
using namespace std;
int main()
{
int a,b,c;
start:
cout << "enter first number: ";
cin>>a;
cout<<endl;
cout << "enter second number: ";
cin>>b;
cout<<endl;
c=a+b;
cout<<"the sum of "<<a<<" and "<<b<<" is: "
<<c<<endl;
if(a>b)
2|Page
{
cout<<a<<" is greater than "<<b<<endl;
}
else
{
cout<<b<<" is greater than "<<a<<endl;
}
goto start;
return 0;
}
OUTPUT:2-
INPUT:3-
/* Online C++ Compiler and Editor */
/* SURAJ SANTOSH CHAVAN M010 57502240010 */
#include <iostream>
using namespace std;
3|Page
int main()
{
int a,i,c;
start:
cout << "enter number whose multiplication table is to be printed: ";
cin>>a;
cout<<endl;
for(i=1; i<=10; i++)
{
c=a*i;
cout<<a<<" x "<<i<<" = "<<c<<endl;
}
goto start;
return 0;
}
OUTPUT:3-
4|Page
INPUT:4-
/* SURAJ SANTOSH CHAVAN M010 57502240010 */
#include <iostream>
using namespace std;
int main()
{
int a,i,c;
start:
cout << "enter number whose factorial is to be printed: ";
cin>>a;
5|Page
cout<<endl;
c=1;
for(i=1; i<=a; i++)
{
c=i*c;
}
cout<<a<<" ! = "<<c<<endl;
goto start;
return 0;
}
OUTPUT:4-
INPUT:5-
/* Online C++ Compiler and Editor */
/* SURAJ SANTOSH CHAVAN M010 57502240010 */
#include <iostream>
using namespace std;
int main()
{
int a,b,c,i;
start:
cout << "enter number whose raised is to be find: ";
6|Page
cin>>a;
cout<<endl;
cout <<"The number that should be raised : " ;
cin>>b;
cout<<endl;
c=1;
for(i=1;i<=b;i++)
{
c=c*a;
}
cout<<a<<" ^ "<<b<<" = "<<c<<endl;
goto start;
return 0;
}
OUTPUT:5-
7|Page
INPUT:6-
/* Online C++ Compiler and Editor */
/* SURAJ SANTOSH CHAVAN M010 57502240010 */
#include <iostream>
using namespace std;
int main()
{
int i,a;
start:
cout << "enter a number : ";
cin>> a;
cout<<endl<<"your number is: "<<a<<endl;
for(i=1;i<=a;i=i+1)
{
cout<<endl<<i<<" ^ 2 = "<<i*i;
}
goto start;
return 0;
}
OUTPUT:6-
8|Page
INPUT:7-
/* Online C++ Compiler and Editor */
/* SURAJ SANTOSH CHAVAN M010 57502240010 */
#include <iostream>
using namespace std;
int main()
{
int x,a,i,c;
start:
cout << endl <<"Hello dear student";
cout<<endl<<"Enter any number on which operations need to be done:";
cin>>x;
cout<<endl<<"List of operations";
cout<<endl<<"Option 1: to find multiplication table";
cout<<endl<<"Option 2: to find square";
cout<<endl<<"Option 3: to find factorial";
9|Page
cout<<endl<<"Option 4: to check whehter even or odd";
cout<<endl<<"Please select your option:";
cin>>a;
switch(a)
{
case 1:
cout<<endl<<"Multiplication table of"<<x<<" is printed below"<<endl;
for(i=1;i<=10;i++)
{
cout<<endl<<x<<" x "<<i<<" = "<<x*i;
}
break;
case 2:
cout<<endl<<"Square of "<<x<<" = "<<x*x;
break;
case 3:
c=1;
for(i=1;i<=x;i++)
{
c=c*i;
}
cout<<endl<<x<<" ! = "<<c;
break;
case 4:
if(x%2==0)
{
cout<<endl<<x<<"is even number";
}
else
{
10 | P a g e
cout<<endl<<x<<" is odd number";
}
break;
default:
cout<<endl<<"please enter valid options: 1 / 2 / 3 / 4" <<endl;
break;
}
goto start;
return 0;
}
OUTPUT:7-
11 | P a g e
12 | P a g e
INPUT:8-
/* Online C++ Compiler and Editor */
/* SURAJ SANTOSH CHAVAN M010 57502240010 */
#include <iostream>
using namespace std;
int main()
{
int i,n, a[50];
start:
cout<<endl<<"Enter how many numbers to use:";
cin>>n;
for(i=0;i<=n-1;i++)
{
13 | P a g e
cout<<endl<<"enter number "<<i+1<<": ";
cin>>a[i];
}
for(i=0;i<=n-1;i++)
{
cout<<endl<<"the number "<<i+1<<":" <<a[i];
}
goto start;
return 0;
}
OUTPUT:8-
14 | P a g e
15 | P a g e
INPUT:9-
/* Online C++ Compiler and Editor */
/* SURAJ SANTOSH CHAVAN M010 57502240010 */
#include <iostream>
using namespace std;
int main() {
int i, n, a[100];
start:
cout << "Enter how many numbers to use: ";
cin >> n;
for (i = 0; i < n; i++) {
cout << "Enter number " << i + 1 << ": ";
cin >> a[i];
}
for (i = 0; i < n; i++) {
cout << "The number " << i + 1 << ": " << a[i] << endl;
}
int even = 0, odd = 0, sumeven = 0, sumodd = 0;
for (i = 0; i < n; i++) {
if (a[i] % 2 == 0) {
even = even + 1;
sumeven = sumeven + a[i];
} else {
odd = odd + 1;
sumodd = sumodd + a[i];
16 | P a g e
}
}
cout << "Total even numbers: " << even << endl;
cout << "Total odd numbers: " << odd << endl;
cout << "Sum of all even numbers: " << sumeven << endl;
cout << "Sum of all odd numbers: " << sumodd << endl;
goto start;
return 0;
}
OUTPUT:9-
17 | P a g e
18 | P a g e
INPUT:10-
/* Online C++ Compiler and Editor */
/* SURAJ SANTOSH CHAVAN M010 57502240010 */
#include <iostream>
using namespace std;
int multiplication(int); //function declaration
int square(int);
int factorial(int);
int evenorodd(int);
int defaultfunc(int);
int i; //global declaration of variable
double c;
int main()
{
int x,a;
start:
cout<<endl<<"Hello dear student";
cout<<endl<<"Enter any number on which operations need to be done:";
cin>>x;
cout<<endl<<"List of operations";
cout<<endl<<"Option 1: to find multiplication table";
cout<<endl<<"Option 2: to find square";
cout<<endl<<"Option 3: to find factorial";
cout<<endl<<"Option 4: to check whether even or odd";
cout<<endl<<"Please select your options";
cin>>a;
switch(a)
{
19 | P a g e
case 1:
multiplication(x); //function calling
break;
case 2:
square(x); //function calling
break;
case 3:
factorial(x);
break;
case 4:
evenorodd(x);
break;
default:
defaultfunc(x);
break;
}
goto start;
return 0;
}
int multiplication(int x) /*function defination*/
{
int j;
cout<<endl<<"Multiplication table of "<<x<<" is printed below"<<endl;
for(j=1;j<=10;j++)
{
20 | P a g e
cout<<endl<<x<<" x "<<j<<" = "<<x*j;
}
return 1;
}
int square(int x)
{
cout<<endl<<"Square of "<<x<<" = "<<x*x;
return 1;
}
int factorial(int x)
{
c=1;
for(i=1;i<=x;i++)
{
c=c*i;
}
cout<<endl<<x<<" ! = "<<c;
return 1;
}
int evenorodd(int x)
{
if(x%2==0)
{
cout<<endl<<x<<" is even number";
}
else
{
21 | P a g e
cout<<endl<<x<<" is odd number";
}
return 1;
}
int defaultfunc(int x)
{
cout<<endl<<"Please enter valid options: 1 / 2 / 3 / 4" <<endl;
return 1;
}
OUTPUT:10-
22 | P a g e
23 | P a g e