SlideShare a Scribd company logo
1 of 12
/*
SUBJECT: FUNDAMENTAL COMPUTER ORGANIZATION
COURSE : MCA-1
ROLL NO: 20
COLLAGE : ROLLWALA COMPUTER CENTER,GUJRATUNIVERSITY
NAME : PATEL SANDOIPBHAID.
EMAIL: PATELSANDIP445566@GMAIL.COM
ASSIGNMENT
PRACTICAL2
*/
// programfor CONVERTANYNUMBER SYSTEM TO ANY NUMBER SYSTEM
#include<stdio.h>
#include<conio.h>
intvalidInt(chars[]){
inti,n=0;
for(i=0;s[i]!='0';i++){
//checkno validornot
if(s[i]<'0'|| s[i]>'9')
return-1;
//forconvertnumbertointeger
n*=10;
n+=s[i]-48;
}
returnn;
}
voidmain(){
char s[50],r[50],sr[50];
inti,j,k,l;
intb1,b2,n,b,pn;
floatn1;//nis decimal n1is floating
intflag,ch,point;//flagforchecknoisvalidor not / flag1for check.(point)
do{
n1=0;point=0;
flag=1;i=j=k=0;
ch=1;
s[0]=r[0]=sr[0]='0';
printf("ntPROGRAMFORANYNUMBER SYSTEM TO ANY NYMBER SYSTEM CONVERTIONn");
printf("nYOUHAVETOGIVE BASE1 ANDBASE2 THE NUMBER OF BASE 1 IS CONVERTEDINTO
BASE 2");
do{
printf("nenterbase 1:");scanf("%s",&s);
b1=validInt(s);
if(b1<0){
printf("nnERROR:INVALIDBASETRY AGAIN:");
getch();
}
if(b1>36){
printf("nERROR:MAXIMUMBASE CAN BE 36 TRY AGAIN:");
getch();
continue;
}
}while(b1<0||b1>36);
do{
printf("nenterbase 2:");scanf("%s",&s);
b2=validInt(s);
if(b2<0){
printf("nnERROR:INVALIDBASETRY AGAIN:");
getch();
}
if(b2>36){
printf("nERROR:MAXIMUMBASE CAN BE 36 TRY AGAIN:");
getch();
continue;
}
}while(b2<0||b2>36);
if(b1==b2){
printf("nERROR:BOTHBASEARE SAME TRY AGAIN:");
getch();
continue;
}
printf("enternumber:");scanf("%s",&s);
//forconvertstrings to a numberof base1 systemandthenconvertit intodecimal
n=0;
b=b1;
//checksize of numberinstrings
for(i=0;s[i]!='0';i++);
j=i-1;
l=0;
/*
if pointfoundlike
12.25
program dolike
52.12
case 2:
123.25 = 52.123
//bothare wrong i actuallyneeded
52.12 =12.25 and 123.25 =25.321
my programdo like that
52.12=21.52 and123.45=54.123
so i needto reverse the output
*/
point=0;
k=0;
for(i=j;i>=0;i--){
if(s[i]=='.'){
if(point<1){
point++;
r[l++]=s[i];
continue;
}
else{
printf("n**ERROR:INVALIDNUMBER MULTIPLE FLOATING
POINTS..**",b1);
flag=0;
break;
}
}
//dontreverse value of floatingpoint
if(point)
r[l++]=s[k++];
else
r[l++]=s[i];
}
if(!flag){
getch();
continue;
}
r[l]='0';
// printf("nstredvalueinr= %sn",r);
l--;
//reverse stringinrif it have a floatingvalue
if(point){
for(i=0;i<l;i++,l--){
point=r[i];//herepointisusedastemp
r[i]=r[l];
r[l]=point;
}
}
// printf("nreversedvalue inr= %sn",r);
/*
working
for e.g.1
sandip i l pointer
s p 0 5 s
pandis swaping
a i 1 4
pindas swaping
nd 2 3
pidnas swaping
d 3 3
eg.2
abc
a c 0 2
b 1 1
*/
l=1;
point=0;//requre fordistinguishfloatingnumberinfollowinglogicitbecomes1againif
numberisfloating
//checknumberisvalidornot for base 1
for(i=0;r[i]!='0';i++){
//checkfloatingvalue
if(r[i]=='.'){
l=1;
point++;
continue;
}
//whenbase lessthenorequal t10
if(b1<=10){
j=r[i]-48;
}
else{
if(r[i]>='A')
j=r[i]-55;
else
j=r[i]-48;
}
//if numbervalidthenconvertitintodecimal
if(j<b1&& ((r[i]>='0'&& r[i]<='9') || (r[i]>='A'&& r[i]<='Z')))
{
if(!point){
if(i==0)
n=j;
else
{
l*=b1;//thisisbase restopower
n+=l*j;//n is storingdesimal of anumber
}
}else{
l*=b1;//thisisbase restopower
n1+=(float)j/l;//nisstoringdesimal of anumber
}
}
else{
printf("n**ERROR:INVALIDNUMBER FORBASE %d..**",b1);
flag=0;
break;
}
}
if(!flag){
getch();
continue;
}
if(point){
n1+=n;
printf("ndecimal of (%s)%d =(%f)10",s,b1,n1);
n1-=n;
}else{
printf("ndecimal of (%s)%d =(%d)10",s,b1,n);
}
//convertion
//anyto decimal
//desimal toany
if(b2!=10){
k=n;
l=0;
while(k>0){
j=k%b2;
k/=b2;
if(j<10)
j+=48;
else{
j+=55;
}
r[l++]=j;
}
j=0;
for(i=l-1;i>=j;i--,j++){
k=r[i];
r[i]=r[j];
r[j]=k;
}
if(point){
r[l++]='.';
for(i=0;i<4;i++){
n1*=b2;
j=n1;
n1-=j;
if(j<10)
j+=48;
else{
j+=55;
}
r[l++]=j;
}
}
r[l]='0';
printf("n(%s)base %d= (%s) base %d",s,b1,r,b2);
}
printf("nnPRESSANYKEYTO CONTINUE:");
getch();
printf("nnENTER0 FOREXIT OR ANY NUMBER FORCONTINUE: ");scanf("%d",&ch);
}while(ch!=0);
}
/*
*/

More Related Content

What's hot

What's hot (16)

Function basics
Function basicsFunction basics
Function basics
 
Pratik Bakane C++
Pratik Bakane C++Pratik Bakane C++
Pratik Bakane C++
 
Merge sort
Merge sortMerge sort
Merge sort
 
Pratik Bakane C++
Pratik Bakane C++Pratik Bakane C++
Pratik Bakane C++
 
Include
IncludeInclude
Include
 
Computer science project work
Computer science project workComputer science project work
Computer science project work
 
1 (1)
1 (1)1 (1)
1 (1)
 
Stl algorithm-Basic types
Stl algorithm-Basic typesStl algorithm-Basic types
Stl algorithm-Basic types
 
Pads lab manual final
Pads lab manual finalPads lab manual final
Pads lab manual final
 
Assignement of c++
Assignement of c++Assignement of c++
Assignement of c++
 
C PROGRAMS
C PROGRAMSC PROGRAMS
C PROGRAMS
 
Pratik Bakane C++
Pratik Bakane C++Pratik Bakane C++
Pratik Bakane C++
 
Pratik Bakane C++
Pratik Bakane C++Pratik Bakane C++
Pratik Bakane C++
 
Bijender (1)
Bijender (1)Bijender (1)
Bijender (1)
 
C mcq practice test 4
C mcq practice test 4C mcq practice test 4
C mcq practice test 4
 
C++ TUTORIAL 8
C++ TUTORIAL 8C++ TUTORIAL 8
C++ TUTORIAL 8
 

Viewers also liked

KGK 2005 nummer 2 CEPAration
KGK 2005 nummer 2 CEPArationKGK 2005 nummer 2 CEPAration
KGK 2005 nummer 2 CEPAration
Marco Hofmans
 
Self Development
Self DevelopmentSelf Development
Self Development
Sofia Rana
 
aspectus company pres 15
aspectus company pres 15aspectus company pres 15
aspectus company pres 15
Lodewijk Hof
 
Mise en scene hospital scenes 1
Mise en scene hospital scenes 1Mise en scene hospital scenes 1
Mise en scene hospital scenes 1
liamsharkey99
 

Viewers also liked (16)

Aplikom_UNSRI_ 5.4 tugas excel_suwanto
Aplikom_UNSRI_ 5.4 tugas excel_suwantoAplikom_UNSRI_ 5.4 tugas excel_suwanto
Aplikom_UNSRI_ 5.4 tugas excel_suwanto
 
The decent cinematography
The decent cinematographyThe decent cinematography
The decent cinematography
 
Javier Garcia - Verdugo Sanchez - Six Sigma Training - W3 Fractional Factoria...
Javier Garcia - Verdugo Sanchez - Six Sigma Training - W3 Fractional Factoria...Javier Garcia - Verdugo Sanchez - Six Sigma Training - W3 Fractional Factoria...
Javier Garcia - Verdugo Sanchez - Six Sigma Training - W3 Fractional Factoria...
 
Aplikasi komputer
Aplikasi komputerAplikasi komputer
Aplikasi komputer
 
Micro analysis
Micro analysis Micro analysis
Micro analysis
 
اسلام کے حقیقی معنی اور مسلمان کی تعریف Who is-muslim
   اسلام کے حقیقی معنی اور مسلمان کی تعریف   Who is-muslim   اسلام کے حقیقی معنی اور مسلمان کی تعریف   Who is-muslim
اسلام کے حقیقی معنی اور مسلمان کی تعریف Who is-muslim
 
Simranpalkandola mise en scene 2
Simranpalkandola mise en scene 2Simranpalkandola mise en scene 2
Simranpalkandola mise en scene 2
 
Realistix Solutions: 10 Places To See Before You Die
Realistix Solutions: 10 Places To See Before You DieRealistix Solutions: 10 Places To See Before You Die
Realistix Solutions: 10 Places To See Before You Die
 
KGK 2005 nummer 2 CEPAration
KGK 2005 nummer 2 CEPArationKGK 2005 nummer 2 CEPAration
KGK 2005 nummer 2 CEPAration
 
Mise en scen 2
Mise en scen 2 Mise en scen 2
Mise en scen 2
 
Storyboard examples
Storyboard examplesStoryboard examples
Storyboard examples
 
A EUCIP Core bevezetéséről diákszemmel
A EUCIP Core bevezetéséről diákszemmelA EUCIP Core bevezetéséről diákszemmel
A EUCIP Core bevezetéséről diákszemmel
 
Self Development
Self DevelopmentSelf Development
Self Development
 
Adnan cv (1)
Adnan cv (1)Adnan cv (1)
Adnan cv (1)
 
aspectus company pres 15
aspectus company pres 15aspectus company pres 15
aspectus company pres 15
 
Mise en scene hospital scenes 1
Mise en scene hospital scenes 1Mise en scene hospital scenes 1
Mise en scene hospital scenes 1
 

Similar to Any number system to any number system convertor

ISCA Final Presentaiton - Compilations
ISCA Final Presentaiton -  CompilationsISCA Final Presentaiton -  Compilations
ISCA Final Presentaiton - Compilations
HSA Foundation
 
Assignment no39
Assignment no39Assignment no39
Assignment no39
Jay Patel
 

Similar to Any number system to any number system convertor (20)

ISCA Final Presentaiton - Compilations
ISCA Final Presentaiton -  CompilationsISCA Final Presentaiton -  Compilations
ISCA Final Presentaiton - Compilations
 
Data struture lab
Data struture labData struture lab
Data struture lab
 
Lab. Programs in C
Lab. Programs in CLab. Programs in C
Lab. Programs in C
 
Sbaw090519
Sbaw090519Sbaw090519
Sbaw090519
 
pattern-printing-in-c.pdf
pattern-printing-in-c.pdfpattern-printing-in-c.pdf
pattern-printing-in-c.pdf
 
Unix Programs
Unix ProgramsUnix Programs
Unix Programs
 
Assignment no39
Assignment no39Assignment no39
Assignment no39
 
C lab-programs
C lab-programsC lab-programs
C lab-programs
 
Fuzail_File_C.docx
Fuzail_File_C.docxFuzail_File_C.docx
Fuzail_File_C.docx
 
Final DAA_prints.pdf
Final DAA_prints.pdfFinal DAA_prints.pdf
Final DAA_prints.pdf
 
7720
77207720
7720
 
C++ file
C++ fileC++ file
C++ file
 
Oops lab manual
Oops lab manualOops lab manual
Oops lab manual
 
C lab programs
C lab programsC lab programs
C lab programs
 
C lab programs
C lab programsC lab programs
C lab programs
 
Let’s talk about microbenchmarking
Let’s talk about microbenchmarkingLet’s talk about microbenchmarking
Let’s talk about microbenchmarking
 
BPOPS203 PRINCIPLES OF PROGRAMMING USING C LAB Manual.pdf
BPOPS203 PRINCIPLES OF PROGRAMMING USING C LAB Manual.pdfBPOPS203 PRINCIPLES OF PROGRAMMING USING C LAB Manual.pdf
BPOPS203 PRINCIPLES OF PROGRAMMING USING C LAB Manual.pdf
 
Computer Practical XII
Computer Practical XIIComputer Practical XII
Computer Practical XII
 
C# labprograms
C# labprogramsC# labprograms
C# labprograms
 
CS6311- PROGRAMMING & DATA STRUCTURE II LABORATORY
CS6311- PROGRAMMING & DATA STRUCTURE II LABORATORYCS6311- PROGRAMMING & DATA STRUCTURE II LABORATORY
CS6311- PROGRAMMING & DATA STRUCTURE II LABORATORY
 

Recently uploaded

Transparency, Recognition and the role of eSealing - Ildiko Mazar and Koen No...
Transparency, Recognition and the role of eSealing - Ildiko Mazar and Koen No...Transparency, Recognition and the role of eSealing - Ildiko Mazar and Koen No...
Transparency, Recognition and the role of eSealing - Ildiko Mazar and Koen No...
EADTU
 

Recently uploaded (20)

Economic Importance Of Fungi In Food Additives
Economic Importance Of Fungi In Food AdditivesEconomic Importance Of Fungi In Food Additives
Economic Importance Of Fungi In Food Additives
 
Transparency, Recognition and the role of eSealing - Ildiko Mazar and Koen No...
Transparency, Recognition and the role of eSealing - Ildiko Mazar and Koen No...Transparency, Recognition and the role of eSealing - Ildiko Mazar and Koen No...
Transparency, Recognition and the role of eSealing - Ildiko Mazar and Koen No...
 
Accessible Digital Futures project (20/03/2024)
Accessible Digital Futures project (20/03/2024)Accessible Digital Futures project (20/03/2024)
Accessible Digital Futures project (20/03/2024)
 
REMIFENTANIL: An Ultra short acting opioid.pptx
REMIFENTANIL: An Ultra short acting opioid.pptxREMIFENTANIL: An Ultra short acting opioid.pptx
REMIFENTANIL: An Ultra short acting opioid.pptx
 
How to Add New Custom Addons Path in Odoo 17
How to Add New Custom Addons Path in Odoo 17How to Add New Custom Addons Path in Odoo 17
How to Add New Custom Addons Path in Odoo 17
 
NO1 Top Black Magic Specialist In Lahore Black magic In Pakistan Kala Ilam Ex...
NO1 Top Black Magic Specialist In Lahore Black magic In Pakistan Kala Ilam Ex...NO1 Top Black Magic Specialist In Lahore Black magic In Pakistan Kala Ilam Ex...
NO1 Top Black Magic Specialist In Lahore Black magic In Pakistan Kala Ilam Ex...
 
Interdisciplinary_Insights_Data_Collection_Methods.pptx
Interdisciplinary_Insights_Data_Collection_Methods.pptxInterdisciplinary_Insights_Data_Collection_Methods.pptx
Interdisciplinary_Insights_Data_Collection_Methods.pptx
 
Wellbeing inclusion and digital dystopias.pptx
Wellbeing inclusion and digital dystopias.pptxWellbeing inclusion and digital dystopias.pptx
Wellbeing inclusion and digital dystopias.pptx
 
How to Manage Call for Tendor in Odoo 17
How to Manage Call for Tendor in Odoo 17How to Manage Call for Tendor in Odoo 17
How to Manage Call for Tendor in Odoo 17
 
Understanding Accommodations and Modifications
Understanding  Accommodations and ModificationsUnderstanding  Accommodations and Modifications
Understanding Accommodations and Modifications
 
Details on CBSE Compartment Exam.pptx1111
Details on CBSE Compartment Exam.pptx1111Details on CBSE Compartment Exam.pptx1111
Details on CBSE Compartment Exam.pptx1111
 
HMCS Max Bernays Pre-Deployment Brief (May 2024).pptx
HMCS Max Bernays Pre-Deployment Brief (May 2024).pptxHMCS Max Bernays Pre-Deployment Brief (May 2024).pptx
HMCS Max Bernays Pre-Deployment Brief (May 2024).pptx
 
Unit 3 Emotional Intelligence and Spiritual Intelligence.pdf
Unit 3 Emotional Intelligence and Spiritual Intelligence.pdfUnit 3 Emotional Intelligence and Spiritual Intelligence.pdf
Unit 3 Emotional Intelligence and Spiritual Intelligence.pdf
 
dusjagr & nano talk on open tools for agriculture research and learning
dusjagr & nano talk on open tools for agriculture research and learningdusjagr & nano talk on open tools for agriculture research and learning
dusjagr & nano talk on open tools for agriculture research and learning
 
AIM of Education-Teachers Training-2024.ppt
AIM of Education-Teachers Training-2024.pptAIM of Education-Teachers Training-2024.ppt
AIM of Education-Teachers Training-2024.ppt
 
FICTIONAL SALESMAN/SALESMAN SNSW 2024.pdf
FICTIONAL SALESMAN/SALESMAN SNSW 2024.pdfFICTIONAL SALESMAN/SALESMAN SNSW 2024.pdf
FICTIONAL SALESMAN/SALESMAN SNSW 2024.pdf
 
How to Manage Global Discount in Odoo 17 POS
How to Manage Global Discount in Odoo 17 POSHow to Manage Global Discount in Odoo 17 POS
How to Manage Global Discount in Odoo 17 POS
 
21st_Century_Skills_Framework_Final_Presentation_2.pptx
21st_Century_Skills_Framework_Final_Presentation_2.pptx21st_Century_Skills_Framework_Final_Presentation_2.pptx
21st_Century_Skills_Framework_Final_Presentation_2.pptx
 
COMMUNICATING NEGATIVE NEWS - APPROACHES .pptx
COMMUNICATING NEGATIVE NEWS - APPROACHES .pptxCOMMUNICATING NEGATIVE NEWS - APPROACHES .pptx
COMMUNICATING NEGATIVE NEWS - APPROACHES .pptx
 
Python Notes for mca i year students osmania university.docx
Python Notes for mca i year students osmania university.docxPython Notes for mca i year students osmania university.docx
Python Notes for mca i year students osmania university.docx
 

Any number system to any number system convertor