0% found this document useful (0 votes)
9 views

NumberSystem programming sadiq

The document provides instructions for a programming session focused on problem-solving using the C language. It includes various number system conversions, such as decimal to binary, octal, and hexadecimal, along with corresponding C code examples for each conversion. The session emphasizes discipline, note-taking, and the recording of the class for future reference.
Copyright
© © All Rights Reserved
Available Formats
Download as PPT, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
9 views

NumberSystem programming sadiq

The document provides instructions for a programming session focused on problem-solving using the C language. It includes various number system conversions, such as decimal to binary, octal, and hexadecimal, along with corresponding C code examples for each conversion. The session emphasizes discipline, note-taking, and the recording of the class for future reference.
Copyright
© © All Rights Reserved
Available Formats
Download as PPT, PDF, TXT or read online on Scribd
You are on page 1/ 18

Programming For Problem Solving

sadiq c language
Programming for Problem Solving
INSTRUCTIONS:-
• Please Mute Your Microphone(MIC).
• There is a red Icon of Mic on the screens,
Mute it.
• Make running notes of topic covered.
• Any doubts will be clarified in the end and type your
doubts in the chat box.
• The Sessions are being recorded, so maintain
discipline.
• This session is being recorded, any mischief during the
class is recorded and later action will be taken by
concerned authority .
Number System
Computer architecture supports
Decimal to Binary
Binary to Decimal

2/4 2/3 2/2 2/1 2⁰

16 8 4 2 1
1 1 0 0 1
16 8 0 0 1=25
Conversion of fraction part
Decimal to Octal

(354)₈
Octal to Decimal
Decimal to Hexadecimal

(D97)₁₆
Hexadecimal to Decimal
C Program to convert Decimal to Binary:-
#include<stdio.h>
main()
{
int n,r,s=0,t,b=1;
printf(“Input a decimal number:”);
scanf(“%d”,&n);
t=n;
while(n!=0)
{
r=n%2;
s=s+(b*r);
b=b*10;
n=n/2;
}
printf(“\n %d is binary number “,s);
}

OUTPUT:-
5 101
85 1010101
120 01111000
C Program to convert Decimal to binary:-
#include<stdio.h>
main()
{
int n, r, s=0,t,b=1;
printf(“Input a decimal number:”);
scanf(“%d”,&n);
t=n;
while(n!=0)
{
r=n%10;
s=s+(b*r);
b=b*2;
n=n/10;
}
printf(“\n %d is decimal number “,s);
}

OUTPUT:-
101 5
1010101 85
01111000 120
C Program to convert Decimal to Octal:-
#include<stdio.h>
main()
{
int n,r,s=0,t,b=1;
printf(“Input a decimal number:”);
scanf(“%d”,&n);
t=n;
while(n!=0)
{
r=n%8;
s=s+(b*r);
b=b*10;
n=n/8;
}
printf(“\n %d is octal number “,s);
}

OUTPUT:-
5
85
120
C Program to convert Octal to Decimal:-
#include<stdio.h>
main()
{
int n,r,s=0,t,b=1;
printf(“Input a decimal number:”);
scanf(“%d”,&n);
t=n;
while(n!=0)
{
r=n%10;
s=s+(b*r);
b=b*8;
n=n/10;
}
printf(“\n %d is decimal number “,s);
}
C Program to convert Decimal to
Hexadecimal
#include<stdio.h> :-
main()
{
int n,t,i,j=0,r;
char a[10];
printf(“Input a decimal number”);
Scanf(“%d”,&n);
t=n;
while(n!=0)
{
r=n%16;
if(r<10)
a[j]=48+r;
else
a[j]=55+r;
n=n/16;
j++;
}
printf(“\n %d is a hexadecimal”,t);
for(i=j-1;i>=0;i--)
printf(“%c”,a[i]);
}

You might also like