## Problem 2.8 :: Write a program to read two floating point numbers using a scanf statement, assign their sum to an integer variable and then output the values of all the three variables.
## Solution ::
## Write down headers yourself.
void main()
{
float a,b;
int sum;
clrscr();
printf("Input float a & b:");
scanf("%f %f",&a,&b);
sum=a+b;
printf("\nThe summition is=%d",sum);
getch();
}
Add two floating point number
Posted by Bijon Labels: ansi c balagurusamy, ansi c solutions, balagurusamy programming solution, c how to program solutions, c programing, c programming tutorial, homework solution, problem solutions, program solutionsBalagurusamy 2_7
Posted by Bijon Labels: ansi c balagurusamy, ansi c solutions, balagurusamy programming solution, c how to program solutions, c programing, c programming tutorial, homework solution, problem solutions, program solutions##Problem 2.7 :: Write a program to do the following:
(a) Declare x and y as integer variables and z as a short integer variable.
(b) Assign two 6 digit numbers to x and y.
(c) Assign the sum of x and y to z.
(d) Output the values of x, y and z.
## solution ::
## Write down headers yourself.
void main()
{
long x,y;
short z;
clrscr();
printf("Input two 6 digit number to x and y:");
scanf("%d %d",&x,&y);
z=x+y;
printf("\nx=%d",x);
printf("\ny=%d",y);
printf("z=%d",z);
getch();
}
Count numbers
Posted by Bijon Labels: ansi c balagurusamy, ansi c solutions, balagurusamy programming solution, c how to program solutions, c programing, c programming tutorial, homework solution, problem solutions, program solutions## Problem 2.6 :: Write program to count and print the number of negative and positive numbers in a given set of numbers. Test your program with a suitable set of numbers. Use scanf to read the numbers. Reading should be terminated when the value 0 is encountered.
## Solution ::
## Write down headers yourself.
void main()
{
int a,b=0,c=0;
clrscr();
printf("\nInput positive & negative :");
printf("\nInput 0 to stop");
for(a=0;a<=1000;a++)
{
scanf("%d",&a);
if(a==0)
break;
if(a<0)
b++;
if(a>0)
c++;
}
printf("\nNegative item=%d",b);
printf("\nPositive item=%d",c);
getch();
}
Get the value from user and display prices
Posted by Bijon Labels: ansi c balagurusamy, ansi c solutions, balagurusamy programming solution, c how to program solutions, c programing, c programming tutorial, homework solution, problem solutions, program solutions## Problem 2.5 :: The price of one kg rice is Rs. 16.75 and one kg sugar is Rs. 15. Write a program to get the value from the user and display the prices as follow:
***LIST OF ITEMS***
Item Price
Rice Rs. 16.75
Sugar Rs. 15.00
## Solutions ::
## Write down headers yourself.
void main()
{
float r,s;
clrscr();
printf("Enter the prices:");
scanf("%f %f",&r,&s);
printf("\n\n***LIST OF ITEMS***\n\n");
printf("Item Price\n\n");
printf("Rice Rs.%f",r);
printf("\n\nSugar Rs.%f",s);
getch();
}
Divide two float numbers
Posted by Bijon Labels: ansi c balagurusamy, ansi c solutions, balagurusamy programming solution, c how to program solutions, c programing, c programming tutorial, homework solution, problem solutions, program solutions## Problem 2.4 :: Write a program that requests two float type numbers from the user and then divides the first number by the second and display the result along with the numbers.
## Solution ::
## Write down headers yourself.
void main()
{float a,b,x;
clrscr();
printf("Enter two number to divide: ");
scanf("%f %f",&a,&b);
x=a/b;
printf("\n\n%f/%f = %f\n",a,b,x);
getch();
}
Print the even numbers from 1 to 100
Posted by Bijon Labels: ansi c by balagurusamy, ansi c by balaguruswamy, assignment programming, assignment solutions, programming answers, programming assignments, programming c, programming c tutorial## Problem : 2.3 :: write a program that prints the even numbers from 1 to 100.
## Solution ::
## Write down headers yourself.
void main()
{
int a;
clrscr();
printf("EVEN NUMBER FROM 1-100:");
printf("\n");
for(a=1;a<=100;a++)
{
if(a%2==0)
printf("%d ",a);
}
getch();
}
Decimal to Paisa
Posted by Bijon Labels: ansi c balagurusamy, ansi c balaguruswamy, ansi c by balagurusamy, problem solutions, program solution, program solutions, programming, programming analysis, programming answers## Problem 2.2 :: Write a program to read the price of an item in decimal form (like 15.96) and print the output in paisa ( like 1596).
## Solution ::
##Write down headers yourself.
void main()
{float d;
long p;
clrscr();
printf("Enter your taka:");
scanf("%f",&d);
p=d*100;
printf("\n\n%f Taka = %ld Paisa",d,p);
getch();
}
2_1_Harmonik Series for a Given Vlue of n
Posted by Bijon Labels: balaguru solutions, c solutions 2.1## Problem :: Write a program to determine and print the sum of the following harmonic series for a given value of n.
## Solution ::
##Write down headers yourself.
void main()
{
int a,b,n;
float s;
clrscr();
printf("Enter n=");
scanf("%d",&n);
printf(" 1");
for(a=2;a<=n;a++)
{
printf(" +");
printf("1/%d",a);
}
for(b=0;b<=n;b++)
{
s=1+ 1/(1+ (float) (b));
}
printf("= %f",s);
getch();
}
Define a Class "student" with roll number, name and marks in 3 tests of a subject.Declare an array of 10 "student" objects.Using Appropiate Functions, Find the Average of Two Better Marks For Each Student. Print the Roll Number , Name and the Average marks of all the students.
Posted by Bijon Labels: C++ solutions, Exam question solutions### Question ::
Define a Class "student" with roll number, name and marks in 3 tests of a subject.Declare an array of 10 "student" objects.Using Appropriate Functions, Find the Average of Two Better Marks For Each Student. Print the Roll Number , Name and the Average marks of all the students.
###Solution ::
[ Write down headers yourself. ]
class student
{
public:
long roll;
char name[12];
float mark[3];
float in1,in2;
float average;
void getdata()
{
int i;
cout<<"\n\nEnter name:"; cin>>name;
cout<<"\n\nEnter Roll:"; cin>>roll;
cout<<"\n\nEnter Numbers of three subjects:" ; for(i=0;i<3;i++) { cin>>mark[i];
}
if(mark[0]>mark[1]||mark[0]>mark[2])
{ in1=mark[0];
if(mark[1]>mark[2])
in2=mark[1];
else
in2=mark[2];
}
else
{
if(mark[1]>mark[2])
{in1=mark[1]; in2=mark[2];}
else
{in1=mark[2]; in2=mark[1];}
}
average=float(in1+in2)/2;
}
void display()
{
cout<<"\n\nNAME :: "<
cout<<"\n\nROLL :: "<
cout<<"\n\nAVERAGE OF TWO BETTER MARKS :: "<
}
};
void main()
{ int i,j;
clrscr();
student s[10]; //You can change the number '10'. This is the number of students.
for(i=0;i<10;i++) //If you change student number you have to change '10' according
s[i].getdata();
s[j].display();
getch();
}
Define a class to represent a bank account.
Posted by Bijon Labels: Balagurusamy solutions, C++ solutions
###
Define a class to represent a bank account.Including the Following Members : :
### Data Members ::
1.Name of the depositor.
2.Account number.
3.Type of account.
4.Balance amount in account.
###Member Functions : :
1.To assign initial values.
2.To deposite an amount.
2.To withdraw an amount after checking the balance.
4.To display Name and balance.
### Solution ::
Header files should be written yourself.
{
char name[10];
char an[5];
int ba,ty;
public:
void init(void);
//void diposit();
void withdraw(void);
void display(void);
};
void bnac::init(void)
{
int a,d,mid,x;
char c[30];
cout<<"Enter your name::";
cin>>name;
cout<<"\nEnter account number::";
cin>>an;
//an=x;
cout<<"\nWhat type of acc.do you want to open?\n";
p:
cout<<"1.Standard(Min. diposite 500/=) \n\n2.Exclusive(Min. diposite 1000/=)\n\n";
cin>>ty;
if(ty!=1&&ty!=2)
{cout<<"You have pressed wrong button.Please try again.\n";
goto p;}
n:
cout<<"\nEnter amount::";
cin>>d;
if(ty==1&&d<500)
{cout<<"\n\nPlease increase your amount";
goto n;}
if(ty==2&&d<1000)
{cout<<"\n\nPlease increase your amount at minimum 1000";
goto n;}
else
ba=d;
}
void bnac::withdraw(void)
{
int x,y;
l:
cout<<"\n\nEnter your amount to withdraw::";
cin>>x;
if(ty==1)
{if(x>(ba-500))
{cout<<"\n\nplease enter smaller amount.\n";
goto l;}
else
cout<<"\n\nyou can withdraw :: "<
}
if(ty==2)
{if(x>=(ba-1000))
{cout<<"\n\nEnter smaller amount.\n";
goto l;}
else
cout<<"\n\nYou can withdraw :: "<
}
}
void bnac::display()
{
cout<<"\n\nAccount number::"<
cout<<"\n\nNAME\t\tBALANCE\n\n";
cout<
}
void main()
{
js:
clrscr();
int x;
bnac ac;
char i;
cout<<"Initializing account\n\n";
ac.init();
cout<<"Choice your term::\n";
cout<<"1.Withdraw an amount.\n\n2.Display info.";
in:
cin>>x;
if(x==1)
ac.withdraw();
if(x==2)
ac.display();
if(x!=1&&x!=2)
{cout<<"You pressed wrong key.Please try again.";
goto in;}
cout<<"\n\n\n\nDo you want to restrart the program?\n\nPress y for yes or another to quit(Check caps lock is off.)";
cin>>i;
if(i=='y')
goto js;
getch();
}

