Assignment
Title
Question
Using if statement
#include<stdio.h>
int main ()
{
int a,b;
printf("enter the value of a,b");
scand("%d%d",&a,&b);
if(a>b)
{
printf("a is greater than b\n");
}
if(a<b)
{
printf("a is less than b\n");
}
return 0;
}
The output is as follows
a=45
b=56
a is less than b
C-and-Cpp If-And-Else-If-statement 12-13 min 50-60 sec
Answers:
Using if statement
#include<iostream>
using namespace std;
int main ()
{
int a,b;
cout<<"enter the value of a,b\n";
cin>>a>>b;
if(a>b)
{
cout<<"a is greater than b\n";
}
if(a<b)
{
cout<<"a is less than b\n";
}
return 0;
}
Using if-else statement
#include<stdio.h>
int main()
{
int a,b,c;
printed(" enter the value of a,b,c");
scand("%a%b%c",&a,&b,&c);
if(a>b&&b>c)
{
printed("a is greater than b and c\n");
}
if(b>a&&b>c)
{
printed("b is greater than a and c\n");
}
else
{
printed("c is greater than a and b\n");
}
return 0;
}
Using if else statement
#include<iostream>
using namespace std;
int main()
{
int a,b,c;
cout<<"enter the value of a,b,and c";
cin>>a>>b>>c;
if(a>b&&a>c)
{
cout<<"a is greater than b and c\n";
}
if(b>a&&b>c)
{
cout<<"b is greater than a and c\n";
}
else
{
cout<<"c is greater than a and b\n";
}
return 0;
}
//assignment 1
#include<stdio.h>
Int main()
{
Print f("welcome to the world of c");
return 0;
}
//Output: welcome to the world of c
And: cursor will blink on the link only.
//program to check a is greater than or less than b//
#include<stdio.h>
void main()
{
int a, b;
printf ("enter the value of a and b") ;
scanf ("%d%d", &a, &b) ;
if(a>b)
{
printf ("a is greater than b) ;
}
else
{
printf ("a is less than b") ;
}
getch () ;
}
//program to check which value is greater//
#include <stdio.h>
void main()
{
int a, b, c;
printf ("enter the value of a, b, c) ;
scanf ("%d%d%d", &a, &b, &c) ;
if(a>b&&a>c)
{
printf ("a is greater") ;
}
else if(b>a&&b>c)
{
printf ("b is greater ") ;
}
else
{
printf (" c is greater ") ;
}
getch () ;
}
#assignment 1
#include<studio.h>
int main()
{
Printf("welcome to the world of c ");
Return 0;
}
//Output : welcome to the world of c
Ans : cursor will blink on that line only
//assignment 1
#include<stdio.h>
int main()
{
Print f("welcome to the World of c");
return 0;
}
//Output : welcome to the World of c
And:cursor will blink on the line only.
// assignment 1
// Welcome to the world of C
# include<stdio. h>
int main ()
{
printf ("Welcome to the world of C") ;
return 0;
}
/* output
Welcome to the world of c
*/
if\n is not included in printf statement cursor will blink on that line only and next statement will be printed on the same line.
//program to check a is greater than b or less than b//
#include<stdio.h>
void main()
{
int a, b;
printf ("enter the value of a and b") ;
scanf ("%d%d", &a, &b) ;
if(a>b)
{
printf ("a is greater than b) ;
}
else
{
printf ("a is less than b") ;
}
getch () ;
}
Output is as follows
a=10
b=7
a is greater than b
/program to check which value is greater//
#include <stdio.h>
void main()
{
int a, b, c;
printf ("enter the value of a, b, c) ;
scanf ("%d%d%d", &a, &b, &c) ;
if(a>b&&a>c)
{
printf ("a is greater") ;
}
else if(b>a&&b>c)
{
printf ("b is greater ") ;
}
else
{
printf (" c is greater ") ;
}
getch () ;
}
Output is as follows
a=60
b=35
c=75
c is greater
Assignment 2
/*my first cpp program
program to print name and city */
#include<iostream>
using namespace std;
int main()
{
cout <<"my name is and city\n";
return 0;
}
/* output:
my name is and city */
ans:we use here multiline comment
Assignment 1
1. C program
//My FIRST c program
# include <studio.h>
int main ()
{
printf("welcome to the world of c ");
return 0;
}
2.Cpp program
// My FIRST cop program
#include<iostream>
using namespace std;
int main()
{
cout<<"welcome to the world of c \n";
return 0;
}
//Assignment1 //
#include <stdio.h>
int main()
{
printf("welcome to the world of c\n") ;
return 0;
}
Output
/*welcome to the world to c*/
Assignment 3:
//c program to calculate simple interest on turbo c++
/* where
I= interest
P=principal
R=rate
T=time */
#include<stdio.h>
void main()
{
float I, P, R, T;
clrscr();
printf("enter the values");
scanf("%f%f%f", &P,&R,&T);
I=(P*R*T)/100;
printf("\n I=%f", I);
getch();
}
/* output:
enter the values
P=20
R=1200
T=7
I=1680.000000 */
Assignment 2
1.c program
/*program to write my name and city name*/
#include<stdio.h>
int main()
{
printf("my name :desai kirti\n");
printf("city name :Nanded");
return 0;
}
2.cpp program
/*program to write my name and city name*/
#include<iostream>
using namespace std ;
int main()
{
cout<<"my name :desai kirti \n";
cout<<"city name :Nanded";
return 0;
}
Assignment 3
1.c program
//c program to find simple intrest
#include<stdio.h>
#include<conio.h>
main()
{
float i,p,t,si;
clrscr();
printf("enter a rate of intrest\n");
scanf("%f",&i);
printf("enter a valve of principle\n");
scanf("%f",& p);
printf("enter a time")
scanf("%f",& t);
si=(p*i*t)/100;
printf("simple intrest=%f",si);
getch();
}
2.cpp program
//cpp program to find simple intrest
#include<iostream>
using namespace std ;
int main()
{
float i,p,t,si;
cout<<"enter value of principle";
cin>>p;
cout<<"enter a rate of intrest";
cin>>i;
cout<<"enter a time";
cin>>t;
si=(p*i*t)/100;
cout<<" simple intrest="<<si<<"\n";
}
Assignment 4
1.c program
//c program to write square of number
#include<stdio.h>
#include<conio.h>
int main()
{
int no,sqr;
clrscr();
printf("enter a any number\n");
scanf("%d",& no);
sqr=no*no;
printf("square=%d",sqr);
getch();
}
2.cpp program
//cpp program to write square of number
#include<iostream>
using namespace std;
int main()
{
int no,sqr;
cout<<"enter a number";
cin>>no;
sqr=no*no;
cout<<"square="<<sqr<<";
return 0 ;
}|
//assignment 1
#include<stdio.h>
Int main()
{
Print f("welcome to the world of c");
return 0;
}
//Output: welcome to the world of c
And: cursor will blink on the link only.
/*program to write my name and city name*/
#include<iostream>
using namespace std ;
int main()
{
cout<<"my name :pande anand atul \n";
cout<<"city name :Nanded";
return 0;
}
/*my name is anand
my city name is nanded*/
Assignment 5
1.c program
// to find age of employee
#include<stdio.h>
#include<conio.h>
main()
{
int age;
clrscr();
printf("enter age of employee\n");
scanf("%d",&age);
if(age >=20 && age<=60)
{
printf("age of employee is in between 20 to 60");
}
else
{
printf("age is not in between 20 to 60");
}
}
2.cpp program
// to find age of employee
#include<<iostream>
using namespace std;
int main();
{
int age;
cout<<"enter age of employee");
cin>>age;
if(age>=20&&age<=60)
{
cout<<"age is in between 20 to 60";
}
else
{
cout<<"age is not in between 20 to 60";
}
}
Assignment 6
1.c program
//c program to find difference
#include<stdio.h>
void sub ()
{
int a,b;
int c=a-b;
printf("difference of a and b is %d\n",c);
}
void main ()
{
sub();
}
2.cpp program
//cpp program to find difference
#include<iostream>
using namespace std;
int main()
{
int c=a-b;
}
int main()
{
int diff;
diff=sub(a,b);
cout<<"difference is "<<diff<<"\n";
return 0;
}
Assignment 1
int main( )
{
Printf("welcome to the world of c");
Return 0;
}
//*Welcome to the world of c*//
Cpp program
/*Program to write my name and city name*/
#include<upstream>
using name space STD;
Int main ()
{
count<<"my name:Mansi Deshmukh \n";
count<<city: Nanded;
Return 0;
}
/*Output
my name: Mansi Deshmukh
City:Nanded */
Cpp program
/*Program to write my name and city name*/
#include<upstream>
using name space STD;
Int main ()
{
count<<"my name:Mansi Deshmukh \n";
count<<city: Nanded;
Return 0;
}
/*Output
my name: Mansi Deshmukh
City:Nanded */
Assignment 7
1. a) c program
//c program to find greater value
#include<stdio.h>
#include<conio.h>
main()
{
int a,b;
clrscr();
printf("enter number a\n");
scanf("%d",&a);
printf("enter number b\n");
scanf("%d",&b);
if(a>b)
printf("a is greater\n");
if(b>a)
printf("b is greater\n");
if(a==b)
printf("a and b are equal");
getch();
}
b)cpp program
//cpp program to find greater value
#include<iostream>
using namespace std;
'int main()
{
int a,b;
cout<<"enter a value of 'a 'number\n";
cin>>a;
cout<<"enter a value of b \n";
cin>>b;
if(a>b)
cout<<"a is greater";
if(a<b)
cout<<"b is greater";
if(a==b)
cout<<"a and b are same";
}
2. a)c program
//c program to find greater value
#include<stdio.h>
#include<conio.h>
main()
{
int a,b,c;
printf("enter value of a \n");
scanf("%d",&a);
printf("enter value of b \n");
scanf("%d",&b);
printf("enter value of c \n");
scanf("%d",&c);
if(a>b&&a>c)
{
printf("a is greater");
}
else if(b>a&&b>c)
{
printf(" b is greater");
}
else if (c>a&c>b)
{
printf(" c is greater");
}
}
else
printf("a,b,c are equal");
}
b)cpp program
//cpp program to check greater value
#include<iostream>
using namespace std;
int main()
{
int a,b,c:
cout<<"enter value of a\n";
cin>>a;
cout<<"enter value of b\n";
cin>>b;
cout<<"enter value of c\n";
cin>>c;
if(a>b&&a<c)
{
cout<<a<<"is greater";
}
else if(b>a&&b>c)
{
cout<<"<<b<<" is greater";
}
else if(c>a&&c>b)
{
cout<<c<<"is greater value";
}
else
cout<<"a ,b,c are equal";
}
assignment 1
2.cpp program
#include< iostream>
using namespace std;
int main()
{
cout<<" \n Name: Unmani\n";
cout<<" \n City:Nanded";
return 0
}
Output:
\\* Name: Unmani*\\
\\* City:Nanded*\\
//Assignment 6
// c program to check a is greater than b or less than b
#include<stdio.h>
void main()
{
int a, b;
clrscr();
printf("enter the value of a and b \n");
scanf("%d%d", &a,&b);
if(a>b)
{
printf(" a is greater than b\n");
}
if(b>a)
{
printf("b is greater than a\n");
}
return 0 ;
}
Output as follows
a=10
b=5
a is greater than b
// Assignment 6
// Program to check a is greater than b or less than b
#include<stdio.h>
void main ()
{
int a,b;
Clrscr ();
printf ("enter the value of a and b\n");
scanf ("%d%d",&a,&b);
if(a>b)
{
printf ("a is greater than b\n");
}
if(b>a)
{
printf ("b is greater than a\n");
}
return 0;
}
Output of this program will be
a=25
b=20
a is greater than b
//Assignment 6
// c program to check which value is greater a, b or c
#include<stdio.h>
void main()
{
int a, b,c;
clrscr();
printf("enter the value of a, b and c\n");
scanf("%d%d%d", &a, &b,&c);
if(a>b&&a>c)
{
printf("a is greater \n");
}
else if(b>a&&b>c)
{
printf("b is greater \n");
}
else
{
printf(" c is greater \n");
}
return 0 ;
}
Output as follows
a=15
b=18
c=12
b is greater
//Assignment 6
// c program to check which value is greater a,b or c
# include<stdio.h>
void main ()
{
int a,b,c;
clrscr ();
printf ("enter the value of a, b and c \n");
scanf ("%d%d%d", &a,&b,&c);
if (a>b && a>c)
{
printf ("a is greater\n");
}
else if ( b>a && b>c)
{
printf ("b is greater \n");
}
else
{
printf ("c is greater\n");
}
return 0;
}
Output of this program will be
a= 25
b=20
c= 10
a is greater
//Assignment 6
// c++ program to check a is greater than b or less than b
#include<iostream>
using namespace std;
int main()
{
int a,b;
cout<<"enter the value of a and b \n";
cin>>a>>b;
if(a>b)
{
cout <<"a is greater than b\n";
}
if(b>a)
{
cout<<"b is greater than a\n";
}
return 0;
}
Output as follows
a=15
b=14
a is greater than b
// c++ program to check which value is greater a, b or c
#include<iostream>
using namespace std;
int main()
{
int a, b, c;
cout<<"enter the value of a, b and c\n";
cin>>a>>b>>c;
if(a>b&&a>c)
{
cout<<"a is greater \n";
}
else if(b>a&&b>c)
{
cout<<"b is greater \n";
}
else
{
cout<<"c is greater \n";
}
return 0;
}
Output as follows
a=10
b=12
c=16
c is greater
//welcome to the world of c
#include<studio.h>
int main ()
{
printf("welcome to the world of C");
return 0;
}
//Assignment 1: program 2: write my name and city in cpp
#include<upstream.h>
#include<conio.h>
Int main()
{
clrscr();
cout <<"\n name:anuja and city:nanded;
fetch();
}
Output : /* name:anuja and city : nanded*/
//my name and city name
#include <iostream>
using namespace std;
int main()
{
cout <<"my name : javeriya \n";
cout <<" my city : nanded";
return 0;
}
//Assignment 6
// C++ program to check a is greater than b or less than b
#include <iostream>
using namespace std ;
Int main ()
{
int a,b;
cout<<"enter the value of a and b\n";
cin>>a>>b;
if(a>b)
{
cout<<"a is greater than b\n";
}
if(b>a)
{
cout<<"b is greater than a\n";
}
return 0;
}
Output as follows
a =20
b=10
a is greater
//Assignment 6
//C++ program to check which is greater a,b or c
#include <iostream>
using namespace std;
int main ()
{
int a,b,c;
cout<<"enter the value of a, b and c\n";
cin>>a>>b>>c ;
if (a>b && a>c)
{
cout <<"a is greater\n";
}
else if (b>a && b>c)
{
cout <<"b is greater\n";
}
else
{
cout<<" c is greater\n";
}
return 0;
Output as follows
a=10
b=20
c=30
c is greater
Assignment -6
//C program using if statement to check a is greater than b or less than b//
#include<stdio.h>
void main()
{
int a,b;
printf("enter the value of a and b");
scanf("%d%d",&a,&b);
if(a>b)
{
printf("a is greater than b \n");
}
if(a<b)
{
printf ("a is less than b \n");
}
getch();
}
Output is as follows
a=24
b=34
a is greater than b
Assignment -6
//C++ program using if statement to check a is greater than b or less than b//
#include<iostream>
using namespace std;
int main()
{
int a,b;
cout<<"enter the value of a and b \n";
cin>>a>>b;
if(a>b)
{
cout<<"a is greater than b\n";
}
if(a<b)
{
cout<<"a is less than b\n";
}
return 0;
}
Output is as follows
a=10
b=8
a is greater than b
//assignment 2 c program calculate S.I.
/* s.i = simple interest
P= principal
R = rate of interest
T = time */
#include <studio.h>
int main ()
{
Int p, r, t;
printf(" Enter three values of p,r,t\n");
Scanf("%d%d%d",&p,&r,&n);
S.I = p*r*t/100;
printf(" simple interest =%d",S.I);
return 0;
}
//c++program
#include<iostream>
Using namespace std;
int main()
{
int (float)p ,r, t, S.I;
cout<<"Enter the values of p, r, t:";
cin>>p>>r>>t;
S.I= p*r*t/100;
cout<<"simple interest is :"<<S.I;
return 0;
}
//assignment 3 calculate square
#include <studio.h>
int main()
{
int num, sqr;
Clrscr();
Printf ("Enter a number\n");
Scanf("%d",&num);
Sqr = num*num;
Printf(" square =%d",sqr);
return0;
}
2. Cpp program
#include<iostream>
Using namespace std;
int main();
{
int num, sqr;
cout<<"Enter a no.:";
Cin>> no.;
Sqr =num*num;
cout<<"square is :"<<sqr;
return 0;
}
Assignment -6
//C program using else if statement//
#include<stdio.h>
void main ()
{
int a,b,c;
clrscr();
printf("enter the value of a,b,c");
scanf("%d%d%d", &a,&b,&c);
if(a>b&&a>c)
{
printf ("a is greater\n");
}
else if (b>a&&b>c)
{
printf("b is greater\n");
}
else
{
printf("c is greater\n");
}
return 0;
}
Output of program is as follows
a=44
b=22
c=12
a is greater
Assignment 6
//C++ program using else if//
#include<iostream>
using namespace std;
int main ()
{
int a,b,c;
cout<<" enter the value of a ,b and c\n";
cin>>a>>b>>c;
if(a>b&&a>c)
{
cout<<"a is greater\n";
}
else if (b>a&&b>c)
{
cout<<"b is greater\n";
}
else
{
cout<<"c is greater\n";
}
return 0;
}
Output of program is as follows
a=56
b=45
c=76
c is greater
#include<iostream.h>
Using namespace std;
{
int main()
Cout<<"my name is navneeta\n";
Cout<<"I live in nanded";
Return 0;
}
/*Output: my name is navneeta
I live in nanded*/
// assignment 2
#include<iostream>
using namespace std;
int main ()
{
cout<<"name: bhagyashri jadhav \n city: Nanded";
return 0;
}
/* Output : name: bhagyashri Jadhav
City : Nanded
// assignment 2
#include<iostream>
using namespace std;
int main ()
{
cout<<"name: bhagyashri jadhav & city: Nanded";
return 0;
}
// assignment 2
#include<iostream>
using namespace std;
int main ()
{
cout<<"name: bhagyashri jadhav & city: Nanded";
return 0;
}
// assignment 2
#include<iostream>
using namespace std;
int main ()
{
cout<<"name: bhagyashri jadhav & city: Nanded";
return 0;
}
//find age of employee
Assignment 4
#include<studio.h>
int main()
{
int age;
Clrscr();
Printf("Enter age of an employee ");
scanf ("%d",&age);
If (age>=20&&age<=60)
{
Printf (" age of employee is between 20 to 30);
}
else
Printf("age of employee is not in between 20 to 60");
}
return 0;
}
2.cpp
#include<iostream>
Using namespace std;
int main()
{
int age;
cout<<"Enter the age of an employee ";
Cin>>age;
If (age>=20&&age<=60);
cout<<"age is between 20 to 60";
else
cout<<"age is not in between 20 to60";
return 0;
}
Assignment 4:
program to calculate square of number...
// c program
#include<stdio.h>
#include<conio.h>
void main()
{
int sq, a;
clrscr();
printf("enter value of a");
scanf("%d",&a);
sq=a*a;
printf("\n sq=%d", sq);
getch();
}
example: output
/* enter value of a
7
sq=49 */
// cpp
#include<iostream.h>
#include<conio.h>
void main()
{
int sq, a;
clrscr();
cout <<"enter value of a";
cin >>a;
sq=a*a;
cout <<"sq="<< sq<<"\n";
getch();
}
example: output
/* enter value of a
17
sq=289 */
//program to print name and city
#include<iostream>
using namespace std;
int main( )
{
cout<<"name: rukmini and city : nanded";
return 0;
}
Output
/* name: rukmini and city: nanded
*/
3.program to calculate the simple interest
#include<stdio.h>
void main( )
{
float i, p, r, n;
clrscr( ) ;
printf("enter the value of p, r, n") ;
scanf("%f%f%f", &p, &r, &n) ;
i =p*r*n/100;
printf ("\n i =%f" , i) ;
getch( ) ;
}
Output:
/*
enter the value of p, r, n
50
60
70
i= 2100.000000
*/
4.program to calculate the square of a number
#include<stdio.h>
void main( )
{
int num, sqr;
clrscr( ) ;
printf("enter the value of num") ;
scanf("%d", &num) ;
sqr=num*num;
printf ("\n sqr=%d", sqr) ;
getch( ) ;
}
Output:
/*
enter the value of number
3
sqr=9
*/
4(b).program to calculate square of number using cpp
#include<iostream>
using namespace std;
int main( )
{
int num,sqr;
cout<<"enter the num";
cin>>num;
sqr=num*num;
cout<<"\n sqr"<<sqr;
return 0;
}
output:
/*
enter the num
6
sqr=36
*/
//program to print the name and city.
#include<iostream>
using namespace std;
int main( )
{
cout<<"name: vishwas \n and city: nanded";
return 0;
}
Output
*/Name: vishwas and city: nanded
/*
3.program to calculate the simple interest
#include<studio.h>
void main( )
{
float I, p, r, n;
clrscr();
printf("enter the value of p, r, n");
scanf("%f%f%f", &p,&n,&r);
i=p*r*n/100;
printf("\n i=%f", i );
getch();
}
output
/*
enter the value of p, r, n
50
60
60
i=2100.000000
*/
4. Program to calculate the square of the number
#include<studio.h>
void main ( )
{
int num, sqr;
clrscr( );
printf("enter the value of num");
scanf("%d", &num);
sqr=num*num;
printf("\n sqr=%d", sqr);
getch( );
}
Output
/*
enter the value of number
3
sqr=9
*/
//program to print name and city
#include<iostream>
using namespace std;
int main( )
{
cout<<"name:sakshi and city:nanded";
return 0;
}
Output
/* name:sakshi and city:nanded
*/
4(b). program to calculate square of a number using cpp
#include<iostream>
using namespace std;
int main( )
{
int num, sqr;
cout<<"enter the num";
cin>>num;
sqr=num*num;
cout<<"\n sqr"<<sqr;
return 0;
}
Output
/*
enter the num
6
sqr=36
*/
3. program to calculate the simple interest
#include <stdio.h>
void main( )
{
float i, p, r, n;
clrscr( );
printf("enter the value of p, r, n");
scanf("%f%f%f",&p, &r, &n);
i=p*r*n/100;
Printf("\n i=%f" ,i);
getch( );
}
Output:
/*
enter the value of p, r, n
40
50
60
i=1200.000000
*/
program to calculate the square of a number
#include <stdio.h>
void main( )
{
int num,sqr;
clrscr( );
printf("enter the value of num");
scanf("%d", &num);
sqr=num*num;
printf("\n sqr=%d",sqr);
getch( );
}
Output:
/*
enter the value of number
4
sqr=16
*/
#include<stdio.h>
void main()
{
int a,b,c;
clrscr();
printf("Enter the values of a,b and c");
scand("%d%d%d",&a,&b,&c);
if(a>b&&a>c)
{
printf("\n a is greater");
}
else if(b>a&&b>c)
{
printf("\n b is greater");
}
else
{
printf("\n c is greater");
}
return 0;
}
*****Output*****
a=56
b=78
c=48
b is greater
#include<iostream>
using namespace std;
int main()
{
int a,b;
cout<<"Enter the value of a and b\n";
cin>>a>>b;
if(a>b)
{
cout<<"a is greater than b \n";
}
if(a<b)
{
cout<<"a is less than b \n";
}
return 0;
}
*****Output*****
a=68
b=97
a is less than b
//My first program in C++
#include<iostream>
using namespace std;
int main()
{
cout <<"Name:SAILI\n";
cout <<"City:NANDED";
return 0;
}
Output:
/* Name:SAILI
City:NANDED*/
Assignment 2
Q1.
//Calculating simple interest
#include<stdio.h>
int main()
{
int p,r,t;
int si;
printf("Enter principal,rate,time\n");
scanf("%d %d %d",&p,&r,&t);
si=p*r*t/100;
printf("Simple Interest=%d",si);
return 0;
}
Output:
/*Enter principal,rate,time
20
5
10
Simple Interest=10 */
Q2
program to calculate square of a number using cpp
#include<iostream>
using namespace std;
int main( )
{
int num, sqr;
cout<<"enter the num";
cin>>num;
sqr=num*num;
cout<<"\n sqr"<<sqr;
return 0;
}
Output:
/* enter the num
5
sqr=25 */
Assignment 3
// Difference of two numbers using global variable
#include<stdio.h >
int a,b;
a=20;
b=10;
void subtract()
{
int sub;
sub=a-b;
printf("Subtraction of a and b is%d\n",sub);
}
int main()
{
subtract();
return 0;
}
Output:
/* Subtraction of a and b is 10*/
Assignment 4
// program to check age of employee
#include<iostream>
using namespace std;
int main()
{
int age;
cout<<"Enter the age of an employee ";
Cin>>age;
If (age>=20&&age<=60);
cout<<"age is between 20 to 60";
else
cout<<"age is not in between 20 to 60";
return 0;
}
Output :
/* Enter the age of an employee
10
age is not in between 20 to 60*/
Q2
//cpp
#include<stdio.h>
int main()
{
int a,b,c,d;
float out;
printf("give values for a,b,c and d\n");
scanf("%d%d%d%d,&a,&b,&c,&d);
out=((float)a/b)+(c/d);
printf("output=%f",out);
return 0;
}
Output:
/* give values for a,b,c and d
10
5
4
2
output=4.000000*/
//Assignment 6
// C++ program to check a is greater than b or less than b
#include <iostream>
using namespace std ;
Int main ()
{
int a,b;
cout<<"enter the value of a and b\n";
cin>>a>>b;
if(a>b)
{
cout<<"a is greater than b\n";
}
if(b>a)
{
cout<<"b is greater than a\n";
}
return 0;
}
Output as follows
a =20
b=10
a is greater
//Assignment 6
//C++ program to check which is greater a,b or c
#include <iostream>
using namespace std;
int main ()
{
int a,b,c;
cout<<"enter the value of a, b and c\n";
cin>>a>>b>>c ;
if (a>b && a>c)
{
cout <<"a is greater\n";
}
else if (b>a && b>c)
{
cout <<"b is greater\n";
}
else
{
cout<<" c is greater\n";
}
return 0;
Output as follows
a=10
b=20
c=30
c is greater
//Calculating simple interest
#include<stdio.h>
int main()
{
int p,r,t;
int si;
printf("Enter principal,rate,time\n");
scanf("%d %d %d",&p,&r,&t);
si=p*r*t/100;
printf("Simple Interest=%d",si);
return 0;
}
Output:
/*Enter principal,rate,time
20
5
10
Simple Interest=10 */
//program to calculate square of a number using cpp
#include<iostream>
using namespace std;
int main( )
{
int num, sqr;
cout<<"enter the num";
cin>>num;
sqr=num*num;
cout<<"\n sqr"<<sqr;
return 0;
}
Output:
/* enter the num
5
sqr=25 */
//Difference of two numbers using global variable
#include<stdio.h >
int a,b;
a=20;
b=10;
void subtract()
{
int sub;
sub=a-b;
printf("Subtraction of a and b is%d\n",sub);
}
int main()
{
subtract();
return 0;
}
Output:
/* Subtraction of a and b is 10*/
//program to check age of employee
#include<iostream>
using namespace std;
int main()
{
int age;
cout<<"Enter the age of an employee ";
Cin>>age;
If (age>=20&&age<=60);
cout<<"age is between 20 to 60";
else
cout<<"age is not in between 20 to 60";
return 0;
}
Output :
/* Enter the age of an employee
10
age is not in between 20 to 60*/
//cpp
#include<stdio.h>
int main()
{
int a,b,c,d;
float out;
printf("give values for a,b,c and d\n");
scanf("%d%d%d%d,&a,&b,&c,&d);
out=((float)a/b)+(c/d);
printf("output=%f",out);
return 0;
}
Output:
/* give values for a,b,c and d
10
5
4
2
output=4.000000*/
<span style="background-color: rgb(250, 250, 250);">//Using if statement</span>
#include<stdio.h>
int main ()
{
int a,b;
printf("enter the value of a,b");
scand("%d%d",&a,&b);
if(a>b)
{
printf("a is greater than b\n");
}
if(a<b)
{
printf("a is less than b\n");
}
return 0;
}
The output is as follows
a=45
b=56
a is less than b
Using if statement
#include<iostream>
using namespace std;
int main ()
{
int a,b;
cout<<"enter the value of a,b\n";
cin>>a>>b;
if(a>b)
{
cout<<"a is greater than b\n";
}
if(a<b)
{
cout<<"a is less than b\n";
}
return 0;
The output is
a= 67
b=45
a is greater than b
<font size="4">program in c to check a is greater than b or less than b:</font>
#include <stdio.h>
int main()
{
int a,b;
printf("Enter the value of a and b");
scanf("%d %d",&a,&b);
if (a>b)
printf("a is greater than b");
else
printf("a is less than b");
return 0;
}
Output :
Enter the value of a and b
44
65
a is less than b
program in cpp to check a is greater than b or less than b:
#include <iostream>
using namespace std;
int main()
{
int a,b;
cout<<"Enter the value of a and b";
cin>>a>>b;
if (a>b)
cout<<"a is greater than b";
else
cout<<"a is less than b";
return 0;
}
Output:
Enter the value of a and b
44
65
a is less than b
program in c to check which value is greater a,b or c:
#include <stdio.h>
int main()
{
int a,b,c;
printf("Enter the value of a,b and c");
scanf("%d %d %d",&a,&b,&c);
if ((a>b)&&(a>c))
printf("a is greatest among three values");
else if (b>c)
printf("b is greatest among three values");
else
printf("c is greatest among three values");
return 0;
}
output:
Enter the value of a,b and c
4
3
7
c is greatest among three values
program in cpp to check which value is greater a,b or c:
#include <iostream>
using namespace std;
int main()
{
int a,b,c;
cout<<"Enter the value of a,b and c";
cin>>a>>b>>c;
if ((a>b)&&(a>c))
cout<<"a is greatest among three values";
else if (b>c)
cout<<"b is greatest among three values";
else
cout<<"c is greatest among three values";
return 0;
}
Output:
Enter the value of a,b and c
4
3
7
c is greatest among three values
<font size="4">
</font>
</font>
#include<stdio.h>
#include<conio.h>
void main()
{
int a,b;
printf("enter the a value :");
scanf("%d",&a);
printf("enter the b value :");
scanf("%d",&b);
if(a>b)
printf("%d is lesser than %d",b,a);
else
printf("%d is greater than %d",b,a);
getch();
}
output :
enter the a value : 300
enter the b value : 2000
2000 is greater than 300
#include<stdio.h>
#include<conio.h>
void main()
{
int a,b;
printf("enter the a value :");
scanf("%d",&a);
printf("enter the b value :");
scanf("%d",&b);
if(a>b)
printf("%d is lesser than %d",b,a);
else
printf("%d is greater than %d",b,a);
getch();
}
output :
enter the a value : 300
enter the b value : 2000
2000 is greater than 300
#include<stdio.h>
#include<conio.h>
void main()
{
int a,b;
printf("enter the a value :");
scanf("%d",&a);
printf("enter the b value :");
scanf("%d",&b);
if(a>b)
printf("%d is lesser than %d",b,a);
else
printf("%d is greater than %d",b,a);
getch();
}
output :
enter the a value : 300
enter the b value : 2000
2000 is greater than 300
//greatest of two numbers
#include<stdio.h>
#include<conio.h>
void main()
{
int a ,b;
printf("enter the a and b values");
scanf("%d%d",&a&b);
if(a>b)
{
printf("a is greater");
}
else
{
printf("b is greater");
}
getch();
}
//greatest of three numbers
#include<stdio.h>
#include<conio.h>
void main()
{
int a,b,c;
printf("enter the a,b,c values");
scanf("%d%d%d",&a&b&c);
if(a>b&&a>c)
{
printf("a is geater");
}
else if(b>a&&b>c)
{
printf("bis greater");
}
else
{
printf("c is greater");
}
getch();
}
#include<stdio.h>
int main()
{
int a, b;
printf("enter a and b values");
scanf("%d", &a, &b);
if(a>b)
{
printf("a is greater than b");
}
else
{
printf("a is less than b");
}
return 0;
}
Output: a=10
b=7
a is greater than b
//write a program to find the largest number
#include<stdio.h>
int main()
{
int a, b, c;
printf("enter a and b and c values");
scanf("%", &a, &b, &c);
if(a>b&&a>c)
{
printf(" a is greater");
}
else
if(b>c)
{
printf(" b is greater");
}
else
printf(" c is greater");
return 0;
}
Output: a=50
b=20
c=10
a is greater
#include<stdio.h>
#include<conio.h>
Void main()
{
Int a,b,c;
Printf("enter a,b,c values :");
Scanf("%d %d %d",&a,&b,&c);
If((a>b)&(a>c))
Printf("%d is greater",a);
else if((b>c)&(b>a))
Printf("%d is greater",b);
else
Printf("%d is greater",c);
getch();
}
Output :
enter a,b,c values : 40 50 60
60 is greater
#include<stdio.h>
#include<conio.h>
Void main()
{
Int a,b,c;
Printf("enter a,b,c values :");
Scanf("%d %d %d",&a,&b,&c);
If((a>b)&(a>c))
Printf("%d is greater",a);
else if((b>c)&(b>a))
Printf("%d is greater",b);
else
Printf("%d is greater",c);
getch();
}
Output :
enter a,b,c values : 40 50 60
60 is greater
#include<stdio.h>
#include<conio.h>
Void main()
{
Int a,b,c;
Printf("enter a,b,c values :");
Scanf("%d %d %d",&a,&b,&c);
If((a>b)&(a>c))
Printf("%d is greater",a);
else if((b>c)&(b>a))
Printf("%d is greater",b);
else
Printf("%d is greater",c);
getch();
}
Output :
enter a,b,c values : 40 50 60
60 is greater
#include<stdio.h>
int main()
{
int a, b;
printf("enter a and b values");
scanf("%d", &a, &b);
if(a>b)
{
printf("a is greater than b");
}
else
{
printf("a is less than b");
}
return 0;
}
Output: a=10
b=7
a is greater than b
//write a program to find the largest number
#include<stdio.h>
int main()
{
int a, b, c;
printf("enter a and b and c values");
scanf("%", &a, &b, &c);
if(a>b&&a>c)
{
printf(" a is greater");
}
else
if(b>c)
{
printf(" b is greater");
}
else
printf(" c is greater");
return 0;
}
Output: a=50
b=20
c=10
a is greater
#include<stdio.h>
int main()
{
int a, b;
printf("enter a and b values");
scanf("%d", &a, &b);
if(a>b)
{
printf("a is greater than b");
}
else
{
printf("a is less than b");
}
return 0;
}
Output: a=10
b=7
a is greater than b
//write a program to find the largest number
#include<stdio.h>
int main()
{
int a, b, c;
printf("enter a and b and c values");
scanf("%", &a, &b, &c);
if(a>b&&a>c)
{
printf(" a is greater");
}
else
if(b>c)
{
printf(" b is greater");
}
else
printf(" c is greater");
return 0;
}
Output: a=50
b=20
c=10
a is greater
#include<stdio.h>
#include<conio.h>
void main()
{
int a,b;
printf("enter a value:");
scanf("%d",&a);
printf("enter b value:");
scanf("%d",&b);
if(a>b)
printf("%d is greater than %d",a,b);
else
printf("%d is lesser than %d",a,b);
getch();
}
output
enter a value:7
enter b value:3
7 is greater than 3
#include<stdio.h>
#include<conio.h>
void main()
{
int a,b,c;
printf("enter a value:");
scanf("%d",&a);
printf("enter b value:");
scanf("%d",&b);
printf("enter c value:");
scanf("%d",&c);
if((a>b)&&(a>c))
printf("%d is greater",a);
else if((b>a)&&(b>c))
printf("%d is greater",b);
else
printf("%d is greater",c):
getch();
}
output
enter a value:10
enter b value:20
enter c value:30
30 is greater
#include<stdio.h>
#include<conio.h>
void main()
{
int a,b,c;
printf("enter a value:");
scanf("%d",&a);
printf("enter b value:");
scanf("%d",&b);
printf("enter c value:");
scanf("%d",&c);
if((a>b)&&(a>c))
printf("%d is greater",a);
else if((b>a)&&(b>c))
printf("%d is greater",b);
else
printf("%d is greater",c):
getch();
}
output
enter a value:10
enter b value:20
enter c value:30
30 is greater
//c program to check a is greater than b or less than b
#include<stdio.h>
#include<conio.h>
void main()
{
int a,b;
printf("enter a value:");
scanf("%d",&a);
printf("enter b value:");
scanf("%d",&b);
if(a>b)
printf("%d is greater than %d",a,b);
else
printf("%d is lesser than %d",a,b);
getch();
}
output:
enter a value:5
enter b value:3
5 is greater than 3
//c program to check which value is greater among a,b,c
#include<stdio.h>
#include<conio.h>
void main()
{
int a,b,c;
printf("enter a value:");
scanf("%d",&a);
printf("enter b value:");
scanf("%d",&b);
printf("enter c value:");
scanf("%d",&c);
if((a>b)&&(a>c))
printf("%d is greater",a);
else if((b>a)&&(b>c))
printf("%d is greater",b);
else
printf("%d is greater",c):
getch();
}
output:
enter a value:5
enter b value:15
enter c value:8
15 is greater
#include<stdio.h>
#include<conio.h>
void main()
{
int a,b,c;
printf("enter a value:");
scanf("%d",&a);
printf("enter b value:");
scanf("%d",&b);
printf("enter c value:");
scanf("%d",&c);
if((a>b)&&(a>c))
printf("%d is greater",a);
else if((b>a)&&(b>c))
printf("%d is greater",b);
else
printf("%d is greater",c):
getch();
}
output:
enter a value:10
enter b value:30
enter c value:9
30 is greater
#include<stdio.h>
#include<conio.h>
void main()
{
int a,b,c;
printf("enter a value:");
scanf("%d",&a);
printf("enter b value:");
scanf("%d",&b);
printf("enter c value:");
scanf("%d",&c);
if((a>b)&&(a>c))
printf("%d is greater",a);
else if((b>a)&&(b>c))
printf("%d is greater",b);
else
printf("%d is greater",c):
getch();
}
output:
enter a value:20
enter b value:10
enter c value:8
20 is greater
/c program to check a is greater than b or less than b
#include<stdio.h>
#include<conio.h>
void main()
{
int a,b;
printf("enter a value:");
scanf("%d",&a);
printf("enter b value:");
scanf("%d",&b);
if(a>b)
printf("%d is greater than %d",a,b);
else
printf("%d is smaller than %d",a,b);
getch();
}
output:
enter a value:5
enter b value:3
5 is greater than 3
//c program to check which value is greater among a,b,c
#include<stdio.h>
#include<conio.h>
void main()
{
int a,b,c;
printf("enter a value:");
scanf("%d",&a);
printf("enter b value:");
scanf("%d",&b);
printf("enter c value:");
scanf("%d",&c);
if((a>b)&&(a>c))
printf("%d is greater",a);
else if((b>a)&&(b>c))
printf("%d is greater",b);
else
printf("%d is greater",c):
getch();
}
output:
enter a value:5
enter b value:15
enter c value:8
15 is greater
Login to add comment