Ananyaassinment 6

Download as docx, pdf, or txt
Download as docx, pdf, or txt
You are on page 1of 3

Assignment6

Submitted by-ANANYA HAZRA


ID-241001001141
Batch-F3(gr-B)

1Write a C program to find out the sum of digits of a given


number. Ans :-
#include <stdio.h>

int main() {
int number, sum = 0;

printf("Enter an integer:
"); scanf("%d", &number);

while (number != 0)
{ sum += number %
10; number /= 10;
}

printf("Sum of the digits is: %d\n", sum);

return 0;
}

output:-
Enter an integer: 6547
Sum of the digits is: 22
Write a C program, which will print two-digit numbers whose sum of
both digits
is a multiple of seven. e.g. 16,25,34.......
Ans:-
#include <stdio.h>
int main() {
int tens, units, sum;
for (int i = 10; i <= 99; i++) {
tens = i / 10;
units = i % 10;

sum = tens + units;

if (sum % 7 == 0)
{ printf("%d\n",
i);
}
}
return 0;
}
output:-
16
25
34
43
52
59
61
68
70
77
86
95
3 If a five-digit integer is input through the keyboard,
write a program to print a new number by adding one to
each of its digits. For example, if the number input is
12391, then the output should be displayed as 23402.
Ans:-
int main() {
int number, newNumber = 0, placeValue
= 1; printf("Enter a five-digit
number: "); scanf("%d", &number);
#include <stdio.h>

while (number != 0) {
int digit = number %
10; digit = (digit +
1) % 10;
newNumber = digit * placeValue +
newNumber; placeValue *= 10;
number /= 10;
}

printf("The new number is: %d\n",


newNumber);

return 0;
}

output:-
1. Enter a five-digit number: 12391
The new number is: 23402
2. Enter a five-digit number: 87654
The new number is:-98765

You might also like