Assignment 06 Introduction To Computing Lab Report Template
Assignment 06 Introduction To Computing Lab Report Template
Aim:
Q1. Write a C program to display the
value of a decimal number in octal
notation.
Algorithm Q1:
(1) START.
(2) Declare variable n, oct, and i.
(3) Initialize oct and i.
(4) Print input statement for user.
(5) Take use input in variable n.
(6) Open a while loop until the variable n is greater than 0.
(7) oct=oct+(n%8) *i, to calculate octal of a decimal number.
(8) Divide the variable n by 8.
(9) Multiply i by 10.
(10) Print Octal Number
(11) STOP
Introduction to Computing Lab (Batch-F3)
Algorithm Q2:
(1) START.
(2) Declare variable n, rem, rev.
(3) Print input statement for user.
(4) Store user input in variable in n.
(5) Run a while loop until n is greater than zero.
(6) Reverse the user input number.
(7) And store the reverse number is the variable rev.
(8) Run a while loop until rev is greater than zero.
(9) Store the last digit of the rev number in the variable rem
(10) Open switch case along with 9 cases for each integer
from 1 to 9. And print in each cases the alphabets of that
integer. Break
(11) Default print alphabets of the number zero, break.
(12) STOP
Introduction to Computing Lab (Batch-F3)
Flowchart Q1:
Introduction to Computing Lab (Batch-F3)
Flowchart Q2:
Introduction to Computing Lab (Batch-F3)
Program Q1:
#include <stdio.h>
int main ()
{
int n,oct=0,i=1;
printf("Enter number in Decimal to convert it into Octal :");
scanf("%d",&n);
while (n>0)
{
oct=oct+(n%8)*i;
n=n/8;
i=i*10;
}
printf("Octal Number is : %d ",oct);
}
Introduction to Computing Lab (Batch-F3)
Program Q2:
#include <stdio.h>
int main ()
{
int n,rem=0,rev=0;
printf("Enter any number : ");
scanf("%d",&n);
while (n>0)
{
rem=n%10;
rev=rev*10+rem;
n=n/10;
}
while (rev>0)
{
rem=rev%10;
rev=rev/10;
switch (rem)
{
case 1:
printf("One ");
break;
case 2:
printf("Two ");
break;
case 3:
printf("Three ");
break;
case 4:
Introduction to Computing Lab (Batch-F3)
printf("Four ");
break;
case 5:
printf("Five ");
break;
case 6:
printf("Six ");
break;
case 7:
printf("Seven ");
break;
case 8:
printf("Eight ");
break;
case 9:
printf("Nine " );
break;
default:
printf("Zero ");
}
}
}
Introduction to Computing Lab (Batch-F3)