IC Assignment 1
IC Assignment 1
Assignment - 1
K. Bhargav Abhiram
(VU22CSEN0101047)
#include <stdio.h>
int main() {
int start, end;
return 0;
}
Output:
(base) abhiramkotana@Abhirams-MacBook-Air-2 Ic 2 % cd
"/Users/abhiramkotana/Documents/Ic 2/" && gcc 1.c -o 1 &&
"/Users/abhiramkotana/Documents/Ic 2/"1
2 3 5 7 11 13 17 19 23 29 31 37 41 43 47
int main() {
int num, sum = 0, temp, remainder, digits = 0;
temp = num;
while (temp != 0) {
temp /= 10;
++digits;
}
temp = num;
while (temp != 0) {
remainder = temp % 10;
sum += pow(remainder, digits);
temp /= 10;
}
if (sum == num)
printf("%d is an Armstrong number.\n", num);
else
printf("%d is not an Armstrong number.\n", num);
return 0;
}
Output:
(base) abhiramkotana@Abhirams-MacBook-Air-2 Ic 2 % cd
"/Users/abhiramkotana/Documents/Ic 2/" && gcc 2.c -o 2 &&
"/Users/abhiramkotana/Documents/Ic 2/"2
Enter a number: 153
153 is an Armstrong number.
int main() {
int num1, num2;
Code:
Enter the first number: 3
Enter the second number: 39
GCD of 3 and 39 is: 3
LCM of 3 and 39 is: 39
4.Program to calculate the power of a number using a loop.
Code:
#include <stdio.h>
int main() {
int base, exponent, result = 1;
if (exponent == 0) {
if (base == 0) {
printf("0 raised to the power of 0 is undefined.\n");
} else {
printf("%d raised to the power of %d is: 1\n", base, exponent);
}
} else {
for (int i = 1; i <= exponent; i++) {
result *= base;
}
printf("%d raised to the power of %d is: %d\n", base, exponent, result);
}
return 0;
}
Output:
(base) abhiramkotana@Abhirams-MacBook-Air-2 Ic 2 % cd "/Users/abhiramkotana/Documents/Ic 2/"
&& gcc 4.c -o 4 && "/Users/abhiramkotana/Documents/Ic 2/"4
Enter base: 4
Enter exponent: 4
4 raised to the power of 4 is: 256