Skip to content

Commit

Permalink
5-d-20
Browse files Browse the repository at this point in the history
  • Loading branch information
Surajkumarsaw1 committed Mar 29, 2023
1 parent e6ebe47 commit 321d688
Show file tree
Hide file tree
Showing 2 changed files with 60 additions and 8 deletions.
28 changes: 28 additions & 0 deletions .vscode/tasks.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
{
"tasks": [
{
"type": "cppbuild",
"label": "C/C++: gcc build active file",
"command": "/usr/bin/gcc",
"args": [
"-fdiagnostics-color=always",
"-g",
"${file}",
"-o",
"${fileDirname}/${fileBasenameNoExtension}"
],
"options": {
"cwd": "${fileDirname}"
},
"problemMatcher": [
"$gcc"
],
"group": {
"kind": "build",
"isDefault": true
},
"detail": "Task generated by Debugger."
}
],
"version": "2.0.0"
}
40 changes: 32 additions & 8 deletions assignment-5/d/20.c
Original file line number Diff line number Diff line change
Expand Up @@ -14,27 +14,51 @@ For an incorrect choice, an appropriate error message should be displayed.
int main() {
int op, n;



printf("Options : \n\t");
printf("1. Generate and display the first 10 terms of the Fibonacci series. \n\t");
printf("2. ind the sum of the digits of an integer that is input.\n\n\t");
printf("2. Find the sum of the digits of an integer that is input.\n\n\t");
printf("Enter option : ");
scanf("%d",&op);

printf("Enter a number : ");
scanf("%d",&n);

switch (op)
{
case 1:

n = 10;
int f=0, s=1, next;

for (int i = 0; i < n; i++){
if ( i < 2) {
printf("%d, ",i);
}
else {
next = f + s;
if ( i != 9){
printf("%d, ",next);
}
else{
printf("%d\n",next);
}
f = s;
s = next;
}
}

break;

case 2:

int sum = 0, num, count=0;
printf("Enter a number : ");
scanf("%d",&n);
num = n;

while ( n != 0){
count += 1;
sum += n%10;
// printf("%d\n",sum);
n /= 10;
}
printf("Sum of digits of %d : %d\n",num,sum);
// printf("count : %d",count);
break;

default:
Expand Down

0 comments on commit 321d688

Please sign in to comment.