Turbo C/C++ and other junk compilers help, discussions and queries here

The Incredible

Ambassador of Buzz
hey anubhav thanks for da ci one it worked thanks a lot.

BTW can u tell me da prog only for 5 digits with giving info on which headers files 2 use

don't mention getch
}
void main

itna to mujhe bhi aata hain aur type karte samay time bhi bachega
 

anubhav_har

In the zone
The Incredible said:
hey anubhav thanks for da ci one it worked thanks a lot.

BTW can u tell me da prog only for 5 digits with giving info on which headers files 2 use

don't mention getch
}
void main

itna to mujhe bhi aata hain aur type karte samay time bhi bachega

This is for n digits... so it is valid for five,sx,seven.... Just input hte no. and youll get the reversed no. I have used loops your sir has not... you can see he has used the same two or three lines over and over again... if it was a 15digit no. then what would he have done?????
 

mohit sharma

Journeyman
well ' LET US C++ ' by yaswant kanitkar is i think good for u ,
but computer science with c++ by sumita arora can help u 2 ways by teaching u c++ , as well as will help u as course text ( if u are cbse student of 11th and 12th ).
 

anubhav_har

In the zone
The Incredible said:
i'm cbse 9th

vaise anubhav vo code kam nahi kar raha hai

main 12345 enter karta hun to -11936 jaisa ans aata hai

Which code??? Mine or ur sirs...
I modified your sirs code.. it had errors....
Code:
#include<math.h>
#include<iostream.h>
#include<conio.h>
void main()
{       clrscr();
	long int x,a,b,c=0;
	cout<<"\nEnter the five digit number = ";
	cin>>a;
	x=a;
	b=a%10;
	c=c*10+b;
	a=x/10;
	cout<<"\nA: "<<a<<" B:"<<b<<" C:"<<c;
	b=a%10;
	c=c*10+b;
	a=x/100;
	cout<<"\nA: "<<a<<" B:"<<b<<" C:"<<c;
	b=a%10;
	c=c*10+b;
	a=x/1000;
	cout<<"\nA: "<<a<<" B:"<<b<<" C:"<<c;
	b=a%10;
	c=c*10+b;
	a=x/10000;
	cout<<"\nA: "<<a<<" B:"<<b<<" C:"<<c;
	b=a%10;
	c=c*10+b;
	cout<<"\nA: "<<a<<" B:"<<b<<" C:"<<c;
	cout<<"\nReversed Digit = "<<c;
	getch();
}
the lines cout<<"\nA: "<<a<<" B:"<<b<<" C:"<<c; is only for seeing what is happening in the program... u can omit them... next long int has to be used since int ranges from -32678 to +32678 so no. greater that 23678 will be displayed as garbage... check it out.. if it doesnt run just reply....
 

ashu888ashu888

Core i7 (nehalem) Owner
Hey incredible buddy..jus see this mayb i can help...

Q) WAPC (write a program in C) to ask user for a 5 DIGIT number and print it in reverse order.
-------------------------------------------------------------------------------------------------------------------------

#include<iostream.h>
#include<conio.h>
void main()
{ long int a,b,c,d,e,f,g,h,n;
clrscr();
cout<<"Please enter a 5 DiGIT number:";
cin>>n;
cout<<endl<<endl<<"The 5 DIGIT number entered by you is="<<n;

a=n%10; // This will store the Remainder
b=n/10; // This will store the Quotient
c=b%10;
d=b/10;
e=d%10;
f=d/10;
g=f%10;
h=f/10;

cout<<endl<<endl<<"The 5 DIGIT number in Reverse order is="<<a<<c<<e<<g<<h;

getch();
}

/* OUTPUT:
Please enter a 5 DiGIT number:12345

The 5 DIGIT number entered by you is=12345

The 5 DIGIT number in Reverse order is=54321 */

------------------------------------------------------------------------------------------------------------------------------

Hope this helps u out mate !!:)

Cheers n e-peace...
 

The Incredible

Ambassador of Buzz
anubhav_har said:
Which code??? Mine or ur sirs...
I modified your sirs code.. it had errors....

Of Course of my sir.

BTW i hav yet not modified it as yours.

i'm gonna do rite after i disconnect.

Anindya
 

Thor

Ambassador of Buzz
@ashu888ashu888 :) Actually ur code will just do Fine with ANY 5 digit Number irrespective of the order of occurence of the Digits.

Without Using Loops..ashu888ashu888 's code is just Fine.
Also the CI code from anubhav_har works 4 u...
So Nothing more to add there...
I will only drop in with few helpfull Programming tips:
While u r declaring the Variables..name them in a meaningful way so that when u encounter a variable in ur code u can recall what it does..
Like in 5-digit no. reversal prog. It wud be better if u declare :
long int num,copy,digit1,digit2,digit3,digit4,digit5,quotient.
Where..
num stores the number
copy will store a copy of num It is a good programming practice to unalter the original input. Becoz u may need the original input later in a relatively bigger Program.So a single step copy=num will do it. Then u can do all ur operations on copy keeping num safely unaltered..
digit1 Stores the 1st Digit [or Last of Original Number

digit2 Stores 2nd Digit [or 4th of Original]
digit3...
digit4...
digit5...
quotient stores the quotient after each step.
instead of
b=n/10;
d=b/10;
f=d/10;
.....
to store the quotient if u write
quotient=quotient/10 then after each step only the latest quotient is stored thus reducing ur burden of more variables...
so a better and modeified code [from Point of view of Healthy Programming Practices] wud be:

#include<iostream.h>
#include<conio.h>

void main()
{
long int num,copy,quotient,digit1,digit2,digit3,digit4,digit5;
clrscr();
cout<<"Please enter a 5 DiGIT number:";
cin>>num;
copy=num; // Copy Stores a Duplicate of Num
cout<<endl<<endl<<"The 5 DIGIT number entered by you is="<<copy;

digit1=copy%10;
quotient=copy/10;
digit2=quotient%10;
quotient=quotient/10;
digit3=quotient%10;
quotient=quotient/10;
digit4=f%10;
digit5=quotient/10; //As quotient/10 yields a single digit ->the 1st of Original and Last for Reversed Number

cout<<endl<<endl<<"The 5 DIGIT number in Reverse order is="<<digit1<<digit2<<digit3<<digit4<<digit5;
getch();
}


So that wraps that up except.... the program prints the digits of original number in reverse..does it actuall reverses the Number ??? No.
So here u go...


#include<iostream.h>
#include<conio.h>

void main()
{
long int num,copy,revnum=0,remainder;
cout<<"Enter the 5 digit Number: ";
cin>>num;
copy=num;
remainder=copy%10;
revnum=revnum*10+remainder;
copy=copy/10;
remainder=copy%10;
revnum=revnum*10+remainder;
copy=copy/10;
remainder=copy%10;
revnum=revnum*10+remainder;
copy=copy/10;
remainder=copy%10;
revnum=revnum*10+remainder;
copy=copy/10;
remainder=copy%10;
revnum=revnum*10+remainder;
cout<<"\nThe Reversed Number is :"<<revnum;
getch();
}


Which is similar to ur sirs code.. except 4 variable names which r made clearer.
 

The Incredible

Ambassador of Buzz
Hey Anubhav!

Thanks a lot!


Since u don't mind so, I'm some more progs which i've to make b4 my half-yearly exams.

I don't know how to make them so if u gimme da progs alongwith basic concepts, it wud b mor helpful.

Here's 2nd & 3rd part of Question Bank


Use of "if" statement :-

1. To get da gr8er no. among 2 given no.s

2. While purchasing certain items, a discount of 10% if offered if da quantity purchased is more than 1000. If quantity n price per item r entered thru keyboard. WAP to calculate da total expenses.

3. Da current yr n da yr in which da employee joind da organisation r entered thru da keyboard. If da no. of yr for which da employee has served da organisation is gr8er than 3 yrs then a bonus of Rs. 2500/- is given to da employee. If da yr of service isn't gr8er than 3 yrs, then da prog shud not do anything.


Use of "if-else" statement:-

1. whether a no. is even or odd.

2. If his basic salary is less than Rs.1500/-, then HRA - House Rent Aloowance = 10% of BS & DA Dearness Allowance = 90% of BS. If his BS is either equal to or above than Rs.1500/- then HRA = Rs. 500/- & DA = 98% of BS. If da employee's salary is inputed thru keyboard. Write a prog to find his gross salary (Net Salary).

3. Temperature conversion prog that gives da user the option of converting "Fahrenheit to Celsius" or "Celsius to Fahrenheit" & depending upon user's choice carries out da conversation.

4. WAP to calculate & print roots of a quadratic equation ( ax2 + bx + c ).

5. WAP to check da given no. is Palendrome or not. [Note:- What is a Palendrome?]

6. WAP to read 4 values a,b,c & d from da terminal n calculate da ratio of (a+b) to (c-d) & print da result, if (c-d) isn't equal to zero.

I know that da query is very very long, i'm heartily sorry for that but i'm in need so kindly plz help me.

Bye.

Anindya
 

anubhav_har

In the zone
Here are most of the programs.
Greater of two numbers...
#include<iostream.h>
#include<conio.h>
void main()
{
clrscr();
int a,b;
cout<<"\nEnter two numbers:";
cin>>a>>b;
if(a>b)
cout<<a<<" is greater than "<<b;
if(b>a)
cout<<b<<" is greater than "<<a;
getch();
}

Discount program
#include<iostream.h>
#include<conio.h>
void main()
{
clrscr();
int quan;
float price,total,disc,finalexp;
cout<<"\nEnter quantity:";
cin>>quan;
cout<<"\nEnter price per item:";
cin>>price;
total=quan*price;
disc=(0.1*total);
if(quan>1000)
{
finalexp=total-disc;
cout<<"\nFinal costs with discount is:"<<finalexp;
}
if(quan<1000)
{
cout<<"\nFinal costs with discount is:"<<finalexp;
}
getch();
}

Bonus program
#include<iostream.h>
#include<conio.h>
void main()
{
clrscr();
int yrjoin,curyr,bonus;
cout<<"\nEnter year of joining:";
cin>>yrjoin;
cout<<"\nEnter current year :";
cin>>curyr;
if(curyr<yrjoin)
{
cout<<"\nCUrrent year is less than joining year... Not possible...";
}
if((curyr-yrjoin)>=3)
{
bonus=2500;
cout<<"\nThe employee gets an bonus of:"<<bonus;
}
getch();
}

No is odd or even..
#include<iostream.h>
#include<conio.h>
void main()
{
clrscr();
int no;
cout<<"\nEnter number:";
cin>>no;
if(no%2==0)
{
cout<<"\nNo is even.....";
}
else
{
cout<<"\nNo is odd......";
}
getch();
}

Basic salary program
#include<iostream.h>
#include<conio.h>
void main()
{
// clrscr();
float bs,hra,bsda,net;
cout<<"\nEnter Basic Salary:";
cin>>bs;
if(bs<1500)
{
hra=0.10*bs;
bsda=0.90*bs;
net=bs+hra+bsda;
}
else
{
hra=500;
bsda=0.98*bs;
net=bs+hra+bsda;
}
cout<<"\nThe net salary is:"<<net;
// getch();
}

Temp conv.
#include<iostream.h>
#include<conio.h>
void main()
{
// clrscr();
int opt;
float cel,fah;
cout<<"\nEnter\n1 for cel to fah\n2 for fah to cel\n";
cin>>opt;
if(opt==1)
{
cout<<"\nEnter temp in celcius:";
cin>>cel;
fah=((9*cel)+160)/5;
cout<<"\nThe temp is fahrenheit:"<<fah;
}
else
{
cout<<"\nEnter temp in fahrenhiet:";
cin>>fah;
cel=((5*fah)-160)/9;
cout<<"\nThe temp is celcius:"<<cel;
}

// getch();
}

Palindrome
//Pallindrome... It is like 12321... i.e. reverse of 12321 is 12321 same....
#include<iostream.h>
#include<conio.h>
void main()
{
clrscr();
int x,n,rev=0,z;
cout<<"\nEnter number to be reversed:";
cin>>n;
x=n;
while(n!=0)
{
z=n%10;
n=n/10;
rev=(rev*10)+z;
}
if(x==rev)
{
cout<<"\nIt is a palindrome..";
}
else
{
cout<<"\nNot a palindorme..";
}
getch();
}
 

NikhilVerma

Padawan
I think it is very bad on your part to request more programs fro digit users...
When you haven't tried making one on your own...
This won't work dude ! Try to make some programs on your own okay ?
BTW I'm only giving the concept of each program... Try to make them on your own..
If you are unsuccesful...
Try again
And then try once more
After that you should post it over here...

If anyone gives you the programs then he is ruining your future !

###############################################

1) Simple, input two numbers, use if to compare two numbers, e.g if(a>b) , if the condition is true print a else print b.
Dude this is the simplest program. What books are you reading ??

2) Again a simple one... Input the quantity and the price... if(quantity>1000) then price = price - price*0.1 , print price

3) Input two years, if( (yearone - yeartwo) >3 ) print bonus else do nothing

###############################################

1) if (no % 2 ==0) Number is even else odd

2) if (salary < 1500) then [salary = salary + salary*10/100 + salary*90/100] else [salary = salary + 500 + salary*98/100 ]

3) input the choice and the option... For eg option 1 is for C-F and 2 is for reverse...
Then if (option==1) variable = 9*temperature/5 + 32 if (option ==2) variable =(f-32)*5/9

4) Enter a,b,c
If (b^2 - 4*a*c is less than 0) then give error coz the roots are imaginary
else
root1=(-b+sqrt(b*b-4*a*c))/(2*a)
root2=(-b-sqrt(b*b-4*a*c))/(2*a)
print the roots...

5) Palindrome is a number which on reversing is the same as the first one.
This could be a tough one for you... So here is the number reversal function

Code:
int reverse(int a)
{
	int b=0,temp;
	while (a!=0)
	{
		temp=a%10;
		a=a/10;
		b=(b*10)+temp;
	}
	return b;
}
void

This will reverse and return the number... Now all you have to do is store it in a variable and check if they are equal or not..

6) input a,b,c,d if ((c-d) >0) then print (a+b)/(c-d) else print error....
 

anubhav_har

In the zone
Hey Nikhil what you told is correct... but the dude needs it for his exams now.. so why not give it to him.. maybe he is not able to do it... Maybe he can but does not want to... but as he requested it from us we have given him the programs...
 

The Incredible

Ambassador of Buzz
Thanks Anubhav!

A Milliondollar thanks.



BTW Nikhil, ur arguement is absolutely fine.

But let me tel u that v hardly get any theoretical classes.

in our practicals da teacher comes n asks us sum progs 2 make but don't giv us mor info n then he departs after that u hav 2 search him in da whole school 2 get mor info.

v haven't given any buk.

there's a buk in lib but in it there's nothing abt C++

i searched bukstalls but they 2 hav only a question bank.

so that's why i opted it here n as my compu exam is on 30th i need 2 work out which is not possible as i hav 2 luk for other sub also.

Hopt u understud.


BTW any1 knowing da other 2 progs.
Nikhil if u know plz tel me, plz i'm in need.

Anindya
 

tuxfan

Technomancer
I agree with Nikhil. Why give code? What will this fella learn then? That is why I gave him hints in broadest terms and other over-enthu people gave him code. C'mon guys, you are not helping him by giving him code. :|
 

mach

Broken In
The Incredible said:
Thanks Anubhav!

A Milliondollar thanks.



BTW Nikhil, ur arguement is absolutely fine.

But let me tel u that v hardly get any theoretical classes.

in our practicals da teacher comes n asks us sum progs 2 make but don't giv us mor info n then he departs after that u hav 2 search him in da whole school 2 get mor info.

v haven't given any buk.

there's a buk in lib but in it there's nothing abt C++

i searched bukstalls but they 2 hav only a question bank.

so that's why i opted it here n as my compu exam is on 30th i need 2 work out which is not possible as i hav 2 luk for other sub also.

Hopt u understud.


BTW any1 knowing da other 2 progs.
Nikhil if u know plz tel me, plz i'm in need.

Anindya

hi there,
i kinda agree with nikhil and tuxfan here..
Guys by handing out the source code.. u r making him dependant..
y giv out the code
u can just explain him the flow or the logic sing an algorithm.. i am sure most of us here are well versed in writing a simple algorithm explaining teh steps to perform

@ incredible

ur exams are on the 30th.. i understand u r a bit worried..
but my friend a simple question..
U r aware of forums.. u know how to search (especially google by what i see among the other posts)
there are parctically 100's of sites on the web which explain u teh concepts of c/c++ more than books (they also giv relevant examples on most needed concepts and many can even be downloaded some r just in kbs-mbs in size).. so stating that u couldnt find a book in collz library.. i find is a huge understatement!!!
sorry if u get offended.. but i just feel that instead of depending on others to solve ur problem completely.. u shuld put some self-effort
 

anubhav_har

In the zone
heys guys after reading som many comments I completely agree with you....

Hey Incredible sorry won't give you any more codes...
You can downlaod C++ ebook from
Code:
*www.planetpdf.com/codecuts/pdfs/eckel/TIC2Vone.zip
*www.planetpdf.com/codecuts/pdfs/eckel/TIC2Vtwo.zip
As for your other two programs...
for the quadratic... roots of the equations are (-b+sqroot((b*b)-(4*a*c)))/2a and (b+sqroot((b*b)-(4*a*c)))/2a,.... Now you write the code segment,,

for the ratio one if(c-d>0) then evaluate (a+b)/(c-d)
I cant tell you more than that..
 

ashu888ashu888

Core i7 (nehalem) Owner
hey Incredible,buddy plz try out these common things urself...

There are also a couple of sites wich can help u as mentioned by so many users..Please make an effort as to how the things will work out...

Wenever a problem is given to u..jus try to imagine..wat would u hv done wen u were in tat situation.How would u hv given the numbers to the Compiler and expected an answer..This thinking strategy will help u solve all ur problems.

If u r facing problems in writing the code in C++ syntax (grammar) then u can also consult a lot of books/online tutorials to help u..

But according to my personal experience..its better to get a book of an Indian writer to make u understand the fundamentals and basics of C++

Coz the same program (of 5 digits) was given by me and many other users also...All mean the same thing brother :) onyl that the way of writing is a bit different varying only in variable names...:)

cheers n e-peace....
 

The Incredible

Ambassador of Buzz
C'mon Guys!

i'm not having time to read da buks n uderstand da logics.

i've already mentioned that my compu exams r on 30th.

man do u all want that i shud only concentrate on comp. man this is cbse board i hav other subjects too. this yr only joined this school.

n abt gaining knowledge let me tel u there's a institute around 2 km from my house for learning programming languages such as BASIC C++ COBOL and JAVA. but currently i'm not having time to read n understand them. from 20th my exams r beginning.

also, in case of reading e-buks electricity needs to b there. if u don't trust just join my city nthemn u'll cum to know da condition of electricity.

my ups remains only upto 5 min.

i don't hav any inverter nor generator.

plz let me solve these progs now.

if i ever ask again after my exams like then i requests da administrator to ban me.


PS: If any 1 having code plz provide me.


Anindya
 
Top Bottom