### Home Work May-2019 (c and c++)

1.

Write a program to find the greatest number among three numbers. The numbers must  take from the input terminal

2.
Write a program to print all the odd number between 1 and 10.

3.
Write a program to check whether the given number is Odd or Even.

4.
Find The Errors and Output (If there is no error) from the following:

 (a) main() { int x=2,y=6,z=6; x=y=z; printf(%d",x) } --------------------------------------

 (b) main() { int x, j, k; J = k = 6;  x = 2; x = j*k; printf("%d", x);  } ----------------------------------

 (c) main() { int i, j; (for i=0;i<5;i++) {  for(j=0;j

Hw4(a) there are two mistake in line 4 expected(") before %d and (;) before '}'
Hw4(b) output:36
Hw4(c) there is one mistake in line 3 where expected'(' after for and expected'}' at the end of the program

2. 1.checkmaximum.c

#include

main()
{
int a,b,c;
printf("Enter 1st number: ");
scanf("%d",&a);
printf("Enter 2nd number: ");
scanf("%d",&b);
printf("Enter 3rd number: ");
scanf("%d",&c);

if(a>b)
{
if(a>c)
{
printf("The maximum number is a = %d",a);
}
else
{
printf("The maximum number is c = %d",c);
}
}
else
{
if(b>c)
{
printf("The maximum number is b = %d",b);
}
else
{
printf("The maximum number is c = %d",c);
}
}

}

Checkmaximum.cpp

#include
using namespace std;

class maximum
{
private:
int a,b,c;
public:
void input();
void display();
};
void maximum::input()
{
cout<<"Enter 1st number: ";
cin>>a;
cout<<"Enter 2nd number: ";
cin>>b;
cout<<"Enter 3rd number: ";
cin>>c;
}
void maximum::display()
{
if(a>b)
{
if(a>c)
{
cout<<"The maximum number is a = "<
using namespace std;

class odd
{
public:
void display()
{
for(int i=1;i<=10;i+=2)
{
cout<

main()
{
int a;
printf("Enter a number: ");
scanf("%d",&a);

if(a%2==0)
{
printf("The number %d is an even number.",a);
}
else
{
printf("The number %d is an odd number.",a);
}
}

CheckEvenOdd.copper

#include
using namespace std;

class check
{
private:
int a;
public:
void input()
{
cout<<"Enter a number: ";
cin>>a;
}
void display()
{
if(a%2==0)
{
cout<<"The number "<

main()
{
int x=2,y=6,z=6;
x=y=z;
printf(%d",x)
}
/*
errors in this code:
missing expression " before token % in line 7
missing ; before } token in line 7
*/

(b)
#include

main()
{
int x, j, k;
J = k = 6; x = 2;
x = j*k;
printf("%d", x);
}
/*
errors in this code:
J is not declared in line 6

*/

(c)
#include

main()
{
int i, j;
(for i=0;i<5;i++)
{
for(j=0;j<i; j++)
{
printf(“%d”,i*j);
}
}

/*
errors in this code:
unexpected token ( before for loop in line 6
missing ( in for loop in line 6
missing token } in line 13
unexpected expression “ before token % and ” after specifier in line 10
*/

3. Rownak jahan ritu.May 27, 2019 at 12:19 PM

1.

Write a program to find the greatest number among three numbers. The numbers must take from the input terminal.
c++
#include
using namespace std;
int main()
{
int a,b,c;
cout<<"enter a:";
cin>>a;
cout<<"enter b:";
cin>>b;
cout<<"Enter c:";
cin>>c;
if((a>b)&&(a>c))
cout<<"a";
else if((b>a)&&(b>c))
cout<<"b";
else
cout<<"c";
return 0;
}

c
#include
int main ()
{
int a,b,c;
printf("Enter a=");
scanf("%d",&a);
printf("Enter b=");
scanf("%d",&b);
printf("Enter c=");
scanf("%d",&c);
if((a>b)&&(a>c))
printf("a");
else if((b>a)&&(b>c))
printf("b");
else
printf("c");
return 0;

}
2.
Write a program to print all the odd number between 1 and 10.

c++
#include
using namespace std;
int main()
{
int i=0;
for(i=1;i<=10;)
{
cout<<"odd=";
cout<
int main()
{
int i;
for(i=1;i<=10;i=i+2)
{
printf("odd=%d\n",i);
}
return 0;
}
3.
Write a program to check whether the given number is Odd or Even.
c++
#include
using namespace std;
int main()
{
int num;
cout<<"Enter any number=";
cin>>num;
if(num%2==0)
{
cout<<"this number is even."<
int main()
{
int num;
printf("Enter any number:");
scanf("%d",&num);
if(num%2==0)
{
printf("The number is even. \n",num);
}
else
{
printf("The number is odd. \n",num);
}
return 0;

}
4.
Find The Errors and Output (If there is no error) from the following:

(a)
main()
{ int x=2,y=6,z=6;
x=y=z;
printf(%d",x) } " and ; missing this line...

b)
main()
{ int x, j, k;
J = k = 6; x = 2;
x = j*k; This is right program....output 36
printf("%d", x); }

(c)
main()
{ int i, j;
(for i=0;i<5;i++) this line not allow..it has '(' problem..
{ for(j=0;j<i; j++)
{ printf(“%d”,i*j);
} } this line '}' missing.

4. Rownak jahan ritu.June 24, 2019 at 8:45 AM

1.
c.

#include
int main ()
{
int a,b,c;
printf("Enter a=");
scanf("%d",&a);
printf("Enter b=");
scanf("%d",&b);
printf("Enter c=");
scanf("%d",&c);
if((a>b)&&(a>c))
printf("a");
else if((b>a)&&(b>c))
printf("b");
else
printf("c");
return 0;

}
c++
#include
using namespace std;
int main()
{
int a,b,c;
cout<<"enter a:";
cin>>a;
cout<<"enter b:";
cin>>b;
cout<<"Enter c:";
cin>>c;
if((a>b)&&(a>c))
cout<<"a";
else if((b>a)&&(b>c))
cout<<"b";
else
cout<<"c";
return 0;
}

2.
c
#include
int main()
{
int i;
for(i=1;i<=10;i=i+2)
{
printf("%d\n",i);
}
return 0;
}

c++
#include
using namespace std;
int main()
{
int i=0;
for(i=1;i<=10;)
{
cout<<"odd=";
cout<
int main()
{
int num;
printf("Enter any number:");
scanf("%d",&num);
if(num%2==0)
{
printf("The number is even. \n",num);
}
else
{
printf("The number is odd. \n",num);
}
return 0;

}

c++
#include
using namespace std;
int main()
{
int num;
cout<<"Enter any number=";
cin>>num;
if(num%2==0)
{
cout<<"this number is even."<<endl;
}
else
{
cout<<"this number is odd.";
}
return 0;
}

4.

(a)
main()
{ int x=2,y=6,z=6;
x=y=z;
printf(%d",x) } it has misstake " and ;
--------------------------------------

(b)
main()
{ int x, j, k;
J = k = 6; x = 2; This is right program ..and this output 36.
x = j*k;
printf("%d", x); }

----------------------------------
(c)
main()
{ int i, j;
(for i=0;i<5;i++) This line "(" rong side.
{ for(j=0;j<i; j++)
{ printf(“%d”,i*j);
} } This line "}" misstake.