SlideShare a Scribd company logo
1 of 6
/* 2’s complement of a number is obtained by scanning it from right to left and complementing all

the bits after the first appearance of a 1. Thus 2’s complement of 11100 is 00100.

Write a C program to find the 2’s complement of a binary number.*/



#include <stdio.h>

#include<conio.h>



void complement (char *a);

void main()

{

char a[16];

int i;

clrscr();

printf("Enter the binary number");

gets(a);

for(i=0;a[i]!='0'; i++)

{

    if (a[i]!='0' && a[i]!='1')

    {

    printf("The number entered is not a binary number. Enter the correct number");

    exit(0);

    }

}

complement(a);
getch();

}

void complement (char *a)

{

int l, i, c=0;

char b[16];

l=strlen(a);

for (i=l-1; i>=0; i--)

{

    if (a[i]=='0')

    b[i]='1';

    else

    b[i]='0';

}

for(i=l-1; i>=0; i--)

{

if(i==l-1)

{

    if (b[i]=='0')

    b[i]='1';

    else

    {

    b[i]='0';

    c=1;
}

}

else

{

    if(c==1 && b[i]=='0')

    {

    b[i]='1';

    c=0;

    }

else if (c==1 && b[i]=='1')

{

    b[i]='0';

    c=1;

}

}

}

b[l]='0';

printf("The 2's complement is %s", b);

}
/* Write a C program to convert a Roman numeral to its decimal equivalent. */



#include<stdio.h>

#include<conio.h>

#include<string.h>

#include<stdlib.h>



void main()

{



int *a,len,i,j,k;

char *rom;



clrscr();



printf("Enter the Roman Numeral:");

scanf("%s",rom);



len=strlen(rom);



for(i=0;i<len;i++)
{

    if(rom[i]=='I')

    a[i]=1;

    else if(rom[i]=='V')

    a[i]=5;

    else if(rom[i]=='X')

    a[i]=10;

    else if(rom[i]=='L')

    a[i]=50;

    else if(rom[i]=='C')

    a[i]=100;

    else if(rom[i]=='D')

    a[i]=500;

    else if(rom[i]=='M')

    a[i]=1000;

    else

    {

        printf("nInvalid Value");

        getch();

        exit(0);

    }

}

k=a[len-1];

for(i=len-1;i>0;i--)
{

    if(a[i]>a[i-1])

    k=k-a[i-1];

    else if(a[i]==a[i-1] || a[i]<a[i-1])

    k=k+a[i-1];

}

printf("nIts Decimal Equivalent is:");

printf("%d",k);

getch();

}

More Related Content

What's hot

New microsoft office word document (2)
New microsoft office word document (2)New microsoft office word document (2)
New microsoft office word document (2)
Syed Umair
 
Introduction to Computer and Programing - Lecture 04
Introduction to Computer and Programing - Lecture 04Introduction to Computer and Programing - Lecture 04
Introduction to Computer and Programing - Lecture 04
hassaanciit
 
Practical write a c program to reverse a given number
Practical write a c program to reverse a given numberPractical write a c program to reverse a given number
Practical write a c program to reverse a given number
Mainak Sasmal
 

What's hot (20)

Add digits of number in c
Add digits of number in c Add digits of number in c
Add digits of number in c
 
Palindrome number program c
Palindrome number program cPalindrome number program c
Palindrome number program c
 
Computer programing w
Computer programing wComputer programing w
Computer programing w
 
Shan
ShanShan
Shan
 
Bcsl 033 data and file structures lab s1-4
Bcsl 033 data and file structures lab s1-4Bcsl 033 data and file structures lab s1-4
Bcsl 033 data and file structures lab s1-4
 
Pratik Bakane C++
Pratik Bakane C++Pratik Bakane C++
Pratik Bakane C++
 
C Programming Example
C Programming Example C Programming Example
C Programming Example
 
C Programming Example
C Programming ExampleC Programming Example
C Programming Example
 
week-17x
week-17xweek-17x
week-17x
 
C Programming Language Part 4
C Programming Language Part 4C Programming Language Part 4
C Programming Language Part 4
 
Double linked list
Double linked listDouble linked list
Double linked list
 
New microsoft office word document (2)
New microsoft office word document (2)New microsoft office word document (2)
New microsoft office word document (2)
 
C program to check leap year
C program to check leap year C program to check leap year
C program to check leap year
 
week-8x
week-8xweek-8x
week-8x
 
งานนำเสนอ อาจารย์ลาวัลย์
งานนำเสนอ อาจารย์ลาวัลย์งานนำเสนอ อาจารย์ลาวัลย์
งานนำเสนอ อาจารย์ลาวัลย์
 
Introduction to Computer and Programing - Lecture 04
Introduction to Computer and Programing - Lecture 04Introduction to Computer and Programing - Lecture 04
Introduction to Computer and Programing - Lecture 04
 
Practical write a c program to reverse a given number
Practical write a c program to reverse a given numberPractical write a c program to reverse a given number
Practical write a c program to reverse a given number
 
One dimensional operation of Array in C- language
One dimensional operation of Array in C- language One dimensional operation of Array in C- language
One dimensional operation of Array in C- language
 
Final ds record
Final ds recordFinal ds record
Final ds record
 
Pratik Bakane C++
Pratik Bakane C++Pratik Bakane C++
Pratik Bakane C++
 

Viewers also liked (10)

ch6
ch6ch6
ch6
 
ch14
ch14ch14
ch14
 
BrainFingerprintingpresentation
BrainFingerprintingpresentationBrainFingerprintingpresentation
BrainFingerprintingpresentation
 
DISTRIBUTED INTERACTIVE VIRTUAL ENVIRONMENT
DISTRIBUTED INTERACTIVE VIRTUAL ENVIRONMENTDISTRIBUTED INTERACTIVE VIRTUAL ENVIRONMENT
DISTRIBUTED INTERACTIVE VIRTUAL ENVIRONMENT
 
PPT (2)
PPT (2)PPT (2)
PPT (2)
 
week-3x
week-3xweek-3x
week-3x
 
week-5x
week-5xweek-5x
week-5x
 
week-2x
week-2xweek-2x
week-2x
 
C code examples
C code examplesC code examples
C code examples
 
week-23x
week-23xweek-23x
week-23x
 

Similar to week-10x

Write an MPI program to accomplish the following for a numbe.pdf
Write an MPI program to accomplish the following for a numbe.pdfWrite an MPI program to accomplish the following for a numbe.pdf
Write an MPI program to accomplish the following for a numbe.pdf
aaryanentp
 
Write an MPI program to accomplish the following for a numbe.pdf
Write an MPI program to accomplish the following for a numbe.pdfWrite an MPI program to accomplish the following for a numbe.pdf
Write an MPI program to accomplish the following for a numbe.pdf
agpcorp
 
Chapter 8 c solution
Chapter 8 c solutionChapter 8 c solution
Chapter 8 c solution
Azhar Javed
 
Qust & ans inc
Qust & ans incQust & ans inc
Qust & ans inc
nayakq
 
Practical write a c program to reverse a given number
Practical write a c program to reverse a given numberPractical write a c program to reverse a given number
Practical write a c program to reverse a given number
Mainak Sasmal
 

Similar to week-10x (20)

Lab. Programs in C
Lab. Programs in CLab. Programs in C
Lab. Programs in C
 
Bca 1st year C langauge .pdf
Bca 1st year C langauge .pdfBca 1st year C langauge .pdf
Bca 1st year C langauge .pdf
 
Write an MPI program to accomplish the following for a numbe.pdf
Write an MPI program to accomplish the following for a numbe.pdfWrite an MPI program to accomplish the following for a numbe.pdf
Write an MPI program to accomplish the following for a numbe.pdf
 
Write an MPI program to accomplish the following for a numbe.pdf
Write an MPI program to accomplish the following for a numbe.pdfWrite an MPI program to accomplish the following for a numbe.pdf
Write an MPI program to accomplish the following for a numbe.pdf
 
PCA-2 Programming and Solving 2nd Sem.pdf
PCA-2 Programming and Solving 2nd Sem.pdfPCA-2 Programming and Solving 2nd Sem.pdf
PCA-2 Programming and Solving 2nd Sem.pdf
 
PCA-2 Programming and Solving 2nd Sem.docx
PCA-2 Programming and Solving 2nd Sem.docxPCA-2 Programming and Solving 2nd Sem.docx
PCA-2 Programming and Solving 2nd Sem.docx
 
data structure and algorithm.pdf
data structure and algorithm.pdfdata structure and algorithm.pdf
data structure and algorithm.pdf
 
C programm.pptx
C programm.pptxC programm.pptx
C programm.pptx
 
C programming
C programmingC programming
C programming
 
Basic c programs updated on 31.8.2020
Basic c programs updated on 31.8.2020Basic c programs updated on 31.8.2020
Basic c programs updated on 31.8.2020
 
Chapter 8 c solution
Chapter 8 c solutionChapter 8 c solution
Chapter 8 c solution
 
Include
IncludeInclude
Include
 
C Programming
C ProgrammingC Programming
C Programming
 
Qust & ans inc
Qust & ans incQust & ans inc
Qust & ans inc
 
C faq pdf
C faq pdfC faq pdf
C faq pdf
 
C lab manaual
C lab manaualC lab manaual
C lab manaual
 
C Programming
C ProgrammingC Programming
C Programming
 
Cpds lab
Cpds labCpds lab
Cpds lab
 
Practical write a c program to reverse a given number
Practical write a c program to reverse a given numberPractical write a c program to reverse a given number
Practical write a c program to reverse a given number
 
Lab Question
Lab QuestionLab Question
Lab Question
 

More from KITE www.kitecolleges.com (16)

ch16
ch16ch16
ch16
 
holographic versatile disc
holographic versatile discholographic versatile disc
holographic versatile disc
 
week-22x
week-22xweek-22x
week-22x
 
week-16x
week-16xweek-16x
week-16x
 
ch8
ch8ch8
ch8
 
Intro Expert Systems test-me.co.uk
Intro Expert Systems test-me.co.ukIntro Expert Systems test-me.co.uk
Intro Expert Systems test-me.co.uk
 
ch17
ch17ch17
ch17
 
ch4
ch4ch4
ch4
 
week-7x
week-7xweek-7x
week-7x
 
week-9x
week-9xweek-9x
week-9x
 
week-14x
week-14xweek-14x
week-14x
 
AIRBORNE
AIRBORNEAIRBORNE
AIRBORNE
 
ch2
ch2ch2
ch2
 
ch3
ch3ch3
ch3
 
Entity Classes and Attributes
Entity Classes and AttributesEntity Classes and Attributes
Entity Classes and Attributes
 
week-20x
week-20xweek-20x
week-20x
 

Recently uploaded

Recently uploaded (20)

Mehran University Newsletter Vol-X, Issue-I, 2024
Mehran University Newsletter Vol-X, Issue-I, 2024Mehran University Newsletter Vol-X, Issue-I, 2024
Mehran University Newsletter Vol-X, Issue-I, 2024
 
Towards a code of practice for AI in AT.pptx
Towards a code of practice for AI in AT.pptxTowards a code of practice for AI in AT.pptx
Towards a code of practice for AI in AT.pptx
 
Introduction to Nonprofit Accounting: The Basics
Introduction to Nonprofit Accounting: The BasicsIntroduction to Nonprofit Accounting: The Basics
Introduction to Nonprofit Accounting: The Basics
 
General Principles of Intellectual Property: Concepts of Intellectual Proper...
General Principles of Intellectual Property: Concepts of Intellectual  Proper...General Principles of Intellectual Property: Concepts of Intellectual  Proper...
General Principles of Intellectual Property: Concepts of Intellectual Proper...
 
Holdier Curriculum Vitae (April 2024).pdf
Holdier Curriculum Vitae (April 2024).pdfHoldier Curriculum Vitae (April 2024).pdf
Holdier Curriculum Vitae (April 2024).pdf
 
Single or Multiple melodic lines structure
Single or Multiple melodic lines structureSingle or Multiple melodic lines structure
Single or Multiple melodic lines structure
 
Spatium Project Simulation student brief
Spatium Project Simulation student briefSpatium Project Simulation student brief
Spatium Project Simulation student brief
 
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)
 
Graduate Outcomes Presentation Slides - English
Graduate Outcomes Presentation Slides - EnglishGraduate Outcomes Presentation Slides - English
Graduate Outcomes Presentation Slides - English
 
Kodo Millet PPT made by Ghanshyam bairwa college of Agriculture kumher bhara...
Kodo Millet  PPT made by Ghanshyam bairwa college of Agriculture kumher bhara...Kodo Millet  PPT made by Ghanshyam bairwa college of Agriculture kumher bhara...
Kodo Millet PPT made by Ghanshyam bairwa college of Agriculture kumher bhara...
 
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
 
ICT role in 21st century education and it's challenges.
ICT role in 21st century education and it's challenges.ICT role in 21st century education and it's challenges.
ICT role in 21st century education and it's challenges.
 
Jamworks pilot and AI at Jisc (20/03/2024)
Jamworks pilot and AI at Jisc (20/03/2024)Jamworks pilot and AI at Jisc (20/03/2024)
Jamworks pilot and AI at Jisc (20/03/2024)
 
Micro-Scholarship, What it is, How can it help me.pdf
Micro-Scholarship, What it is, How can it help me.pdfMicro-Scholarship, What it is, How can it help me.pdf
Micro-Scholarship, What it is, How can it help me.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
 
Sociology 101 Demonstration of Learning Exhibit
Sociology 101 Demonstration of Learning ExhibitSociology 101 Demonstration of Learning Exhibit
Sociology 101 Demonstration of Learning Exhibit
 
How to Create and Manage Wizard in Odoo 17
How to Create and Manage Wizard in Odoo 17How to Create and Manage Wizard in Odoo 17
How to Create and Manage Wizard in Odoo 17
 
SOC 101 Demonstration of Learning Presentation
SOC 101 Demonstration of Learning PresentationSOC 101 Demonstration of Learning Presentation
SOC 101 Demonstration of Learning Presentation
 
HMCS Vancouver Pre-Deployment Brief - May 2024 (Web Version).pptx
HMCS Vancouver Pre-Deployment Brief - May 2024 (Web Version).pptxHMCS Vancouver Pre-Deployment Brief - May 2024 (Web Version).pptx
HMCS Vancouver Pre-Deployment Brief - May 2024 (Web Version).pptx
 
ICT Role in 21st Century Education & its Challenges.pptx
ICT Role in 21st Century Education & its Challenges.pptxICT Role in 21st Century Education & its Challenges.pptx
ICT Role in 21st Century Education & its Challenges.pptx
 

week-10x

  • 1. /* 2’s complement of a number is obtained by scanning it from right to left and complementing all the bits after the first appearance of a 1. Thus 2’s complement of 11100 is 00100. Write a C program to find the 2’s complement of a binary number.*/ #include <stdio.h> #include<conio.h> void complement (char *a); void main() { char a[16]; int i; clrscr(); printf("Enter the binary number"); gets(a); for(i=0;a[i]!='0'; i++) { if (a[i]!='0' && a[i]!='1') { printf("The number entered is not a binary number. Enter the correct number"); exit(0); } } complement(a);
  • 2. getch(); } void complement (char *a) { int l, i, c=0; char b[16]; l=strlen(a); for (i=l-1; i>=0; i--) { if (a[i]=='0') b[i]='1'; else b[i]='0'; } for(i=l-1; i>=0; i--) { if(i==l-1) { if (b[i]=='0') b[i]='1'; else { b[i]='0'; c=1;
  • 3. } } else { if(c==1 && b[i]=='0') { b[i]='1'; c=0; } else if (c==1 && b[i]=='1') { b[i]='0'; c=1; } } } b[l]='0'; printf("The 2's complement is %s", b); }
  • 4. /* Write a C program to convert a Roman numeral to its decimal equivalent. */ #include<stdio.h> #include<conio.h> #include<string.h> #include<stdlib.h> void main() { int *a,len,i,j,k; char *rom; clrscr(); printf("Enter the Roman Numeral:"); scanf("%s",rom); len=strlen(rom); for(i=0;i<len;i++)
  • 5. { if(rom[i]=='I') a[i]=1; else if(rom[i]=='V') a[i]=5; else if(rom[i]=='X') a[i]=10; else if(rom[i]=='L') a[i]=50; else if(rom[i]=='C') a[i]=100; else if(rom[i]=='D') a[i]=500; else if(rom[i]=='M') a[i]=1000; else { printf("nInvalid Value"); getch(); exit(0); } } k=a[len-1]; for(i=len-1;i>0;i--)
  • 6. { if(a[i]>a[i-1]) k=k-a[i-1]; else if(a[i]==a[i-1] || a[i]<a[i-1]) k=k+a[i-1]; } printf("nIts Decimal Equivalent is:"); printf("%d",k); getch(); }