Ananyaassinment 6
Ananyaassinment 6
Ananyaassinment 6
int main() {
int number, sum = 0;
printf("Enter an integer:
"); scanf("%d", &number);
while (number != 0)
{ sum += number %
10; number /= 10;
}
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;
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;
}
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