Skip to content

Commit fc51208

Browse files
author
Udbhav
committed
Added linux module to find sum of digits of a number
1 parent 51f0474 commit fc51208

File tree

2 files changed

+31
-0
lines changed

2 files changed

+31
-0
lines changed

digits_sum/Makefile

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
obj-m += digitsum.o
2+
3+
all:
4+
make -C /lib/modules/$(shell uname -r)/build M=$(PWD) modules
5+
clean:
6+
make -C /lib/modules/$(shell uname -r)/build M=$(PWD) clean

digits_sum/digitsum.c

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
#include <linux/kernel.h>
2+
#include <linux/module.h>
3+
#include <linux/moduleparam.h>
4+
5+
static int n = 5;
6+
module_param(n,int,0);
7+
MODULE_PARM_DESC(n,"given number");
8+
9+
10+
int init_module(void){
11+
12+
static int sum=0;
13+
static int temp=n;
14+
while(temp>0)
15+
{
16+
sum+=(temp%10);
17+
temp/=10;
18+
}
19+
printk(KERN_INFO "Sum_of_digits: %d",sum);
20+
return 0;
21+
}
22+
23+
void cleanup_module(void){
24+
printk(KERN_INFO "goodbye world");
25+
}

0 commit comments

Comments
 (0)