RAGHU INSTITUTE OF TECHNOLOGY
RAGHU INSTITUTE OF TECHNOLOGY
DEPARTMENT OF CSE
College Code: 3J
R13 Syllabus
C PROGRAMMING LAB MANUAL
====================================================================
Exercise 4
a) Write a C Program to print the multiplication table of a given number n up to a given
value, where n is entered by the user.
b) Write a C Program to enter a decimal number, and calculate and display the binary
equivalent of that number.
c) Write a C Program to check whether the given number is Armstrong number or not.
====================================================================
SPECIFICATION :
(4)(a) Write a c program to print the multiplication table of a given number n up to a
given value ,where n is entered by the user.
ALGORITHM:
Step1: Start
Step2: Declare i, and n
Step3: Read n
Step4:
Step4.1: i is initialized as 1 and condition i<=n is checked and I is
incremented in steps of 1 do , until loop fails
Step4.2: second iteration is checked where j is initialized as 1 & j<=10 and j is
incremented until loop fails
Step5: Display table, i*j
Step6: Stop
Department of Computer Science & Engg
RAGHU INSTITUTE OF TECHNOLOGY
FLOWCHART:
Start
Declare i, and n
Read n
true
false
For I in steps of 1 where i<=n
false
true
For j in terms of 1 where j<=10
Display
table
Stop
Department of Computer Science & Engg
RAGHU INSTITUTE OF TECHNOLOGY
PROGRAM:
PROGRAM
/* C Program to display multiplication table */
Program name:
// wk4a.c
/* Done By : C-Faculty
#include<stdio.h>
#include<curses.h>
int main()
{
int i,j,n;
clear();
printf(enter n);
scanf(%d,&n);
for(i=1;i<=n;i++)
{
for(j=1;j<=10;j++)
{
printf(%d*%d=%d,i,j,i*j);
}
}
return(0);
}
Department of Computer Science & Engg
Dated: 15/10/2013*/
RAGHU INSTITUTE OF TECHNOLOGY
PROCEDURE FOR EXECUTING THE PROGRAM:
Step 1: After typing the program, press ESC button+shift+: and then type wq(to save the
program and quit)
Step 2: Now compile the program by using the following command
cc wk4a.c lcurses -lm
Step 3: Now go for running the program by using the command
./a.out
Step 4: To create an executing file use the command
cc wk4a.c -curses o multiplication
EXPECTED I/P AND O/P:
enter n 1
1*1=1
1*2=2
1*3=3
1*4=4
1*5=5
1*6=6
1*7=7
1*8=8
1*9=9
1*10=10
Department of Computer Science & Engg
RAGHU INSTITUTE OF TECHNOLOGY
ORIGINAL OUTPUT :
Output (1): enter n 1
1*1=1
1*2=2
1*3=3
1*4=4
1*5=5
1*6=6
1*7=7
1*8=8
1*9=9
1*10=10
Output (2): enter n 2
2*1=2
2*2=4
2*3=6
2*4=8
2*5=10
2*6=12
2*7=14
2*8=16
2*9=18
2*10=20
--xXx-Department of Computer Science & Engg
RAGHU INSTITUTE OF TECHNOLOGY
SPECIFICATION:
(4)(b). Write a c program to enter a decimal number, and calculate and display the binary
equivalent of that number.
ALGORITHM:
Step1: Start
Step2: Declare d, i, j, rem[100]
Step3: Read d
Step4: i is initialized as 0 and condition d>0 is checked and incremented until loop
fails.
Step6: j is initialized as i-1 and condition j=0 is checked and j is decremented until loop fails.
Step6: Display rem[i]
Step7: Stop
Department of Computer Science & Engg
RAGHU INSTITUTE OF TECHNOLOGY
FLOWCHART:
START
Declare d, i, j, reminder[100]
Read d
False
For i=0 in steps of 1 do loop where d>0
true
For j=i-1 in steps of one loop
where j=0
true
Display rem[i]
STOP
Department of Computer Science & Engg
false
RAGHU INSTITUTE OF TECHNOLOGY
PROGRAM
/*C Program to convert decimal to binary */
Program name:
// wk4a.c
/* Done By : C-Faculty
#include<stdio.h>
#include<curses.h>
int main()
{
int d,i,j,rem[100];
clear();
printf("enter your decimal number:\n");
scanf("%d",&d);
for(i=0;d>0;i++)
{
rem[i]=d/2;
d=d/2;
i++;
}
printf("binary number is:\n\n");
for( j=i-1;j=0 ;j--)
{
printf("%d",rem[i]);
}
return(0);
Department of Computer Science & Engg
Dated: 15/10/2013*/
RAGHU INSTITUTE OF TECHNOLOGY
PROCEDURE FOR EXECUTING THE PROGRAM:
Step 1: After typing the program, press ESC button+shift+: and then type wq(to save the
program and quit)
Step 2: Now compile the program by using the following command
cc wk4b.c lcurses -lm
Step 3: Now go for running the program by using the command
./a.out
Step 4: To create an executing file use the command
cc wk4b.c -curses o decimalbin
EXPECTED I/P AND O/P:
Output(1): enter your decimal number 8
binary number is: 1000
Output(2): enter your decimal number 11
binary number is: 1101
ORIGINAL OUTPUT :
Output(1): enter your decimal number 8
binary number is: 1000
Output(2): enter your decimal number 11
binary number is: 1101
VIVA VOCE QUESTIONS:
What is a binary number?
Ans)in mathematics and computer science the binary numeral system or base-2 numeral system
Department of Computer Science & Engg
RAGHU INSTITUTE OF TECHNOLOGY
Represents numeric values using two symbols typically 0 and 1
What is decimal number?
Ans) decimal range is from (0-9) total 10 numbers so the base of decimal number is 10
--xXx--
Department of Computer Science & Engg
RAGHU INSTITUTE OF TECHNOLOGY
SPECIFICATION:
(4). Write a C program to check whether the number is Armstrong number or not.
ALGORITHM:
Step1: Start
Step2: Declare n, temp, sum0 and r
Step 3: Read n
Step4: Compute tempn
Step5: While(n!=0)
Do
5.1: rn%10
5.2: sumsum+(r*r*r)
5.3: nn/10
Done
Step6: Check sum==temp
Step6.1: Display it is an Armstrong number
Step7: Else display it is not an Armstrong number
Step8: Stop
Department of Computer Science & Engg
RAGHU INSTITUTE OF TECHNOLOGY
FLOWCHART:
Start
Declare n, temp, sum=0 and r
Read n
While(n!=0)
rn%10
sumsum+(r*r*r)
nn/10
false
true
Check
sum==temp
It is an Armstrong
number
Display it is not an
Armstrong number
Stop
Department of Computer Science & Engg
RAGHU INSTITUTE OF TECHNOLOGY
PROGRAM
/* C Program to Check whether the given number is Armstrong or not */
Program name:
// wk4c.c
/* Done By : C-Faculty
Dated: 15/10/2013*/
#include<stdio.h>
#include<curses.h>
int main()
{
int n,temp,sum=0,r;
printf(enter n);
scanf(%d,&n);
temp=n;
while(n!=0)
{
r=n%10;
sum=sum+(r*r*r);
n=n/10;
}
if(sum==temp)
printf(%d is an Armstrong number,temp);
else
printf(%d is not an Armstrong number,temp);
return(0);
}
Department of Computer Science & Engg
RAGHU INSTITUTE OF TECHNOLOGY
PROCEDURE FOR EXECUTING THE PROGRAM:
Step 1: After typing the program, press ESC button+shift+: and then type wq(to save the
program and quit)
Step 2: Now compile the program by using the following command
cc wk4c.c lcurses -lm
Step 3: Now go for running the program by using the command
./a.out
Step 4: To create an executing file use the command
cc wk4c.c -curses o armstrong
EXPECTED I/P AND O/P:
Output (1): enter n 153
153 is an Armstrong number
Output (2): enter n 245
245 is not an Armstrong number
ORIGINAL OUTPUT :
Output (1): enter n 153
153 is an Armstrong number
Output (2): enter n 245
245 is not an Armstrong number
--xXx--
Department of Computer Science & Engg