Assignment 3 - Colaboratory
Assignment 3 - Colaboratory
%%file assi3.c
#include <stdio.h>
int main() {
int startRange, endRange;
return 0;
}
!gcc assi3.c
!./a.out
https://colab.research.google.com/drive/1G9h-G2cgCBlr3xhue6zyYdrOPLZExv8o#scrollTo=-pD8c-EZzGNv&printMode=true 1/9
11/18/23, 7:52 PM Assignment 3 - Colaboratory
%%file assi3.c
#include <stdio.h>
return result;
}
int main() {
double base;
int exponent;
// Call the function to calculate the power and display the result
double result = power(base, exponent);
printf("%.2lf raised to the power of %d is: %.2lf\n", base, exponent, result);
return 0;
}
Overwriting assi3.c
!gcc assi3.c
!./a.out
%%file assi3.c
#include <stdio.h>
int main() {
int num1, num2;
// Call the function to find the maximum and display the result
int max = findMax(num1, num2);
printf("The maximum of %d and %d is: %d\n", num1, num2, max);
return 0;
}
Overwriting assi3.c
!gcc assi3.c
!./a.out
https://colab.research.google.com/drive/1G9h-G2cgCBlr3xhue6zyYdrOPLZExv8o#scrollTo=-pD8c-EZzGNv&printMode=true 2/9
11/18/23, 7:52 PM Assignment 3 - Colaboratory
4.To print all strong numbers between given interval using functions.
%%file assi3.c
#include <stdio.h>
int main() {
int start, end;
return 0;
}
Overwriting assi3.c
!gcc assi3.c
!./a.out
https://colab.research.google.com/drive/1G9h-G2cgCBlr3xhue6zyYdrOPLZExv8o#scrollTo=-pD8c-EZzGNv&printMode=true 3/9
11/18/23, 7:52 PM Assignment 3 - Colaboratory
%%file assi3.c
#include <stdio.h>
#include <math.h>
int main(){
int num;
int n = num;
while (n != 0){
lastdigit = n % 10;
power = lastdigit * lastdigit * lastdigit;
sum = sum + power;
n = n / 10;
}
if (sum == num)
return 0;
else
return 1;
}
Overwriting assi3.c
!gcc assi3.c
!./a.out
https://colab.research.google.com/drive/1G9h-G2cgCBlr3xhue6zyYdrOPLZExv8o#scrollTo=-pD8c-EZzGNv&printMode=true 4/9
11/18/23, 7:52 PM Assignment 3 - Colaboratory
%%file assi3.c
#include <stdio.h>
void swap(int , int); //prototype of the function
int main()
{
int a = 10;
int b = 20;
printf("Before swapping the values in main a = %d, b = %d\n",a,b); // printing the value of a and b in main
swap(a,b);
printf("After swapping values in main a = %d, b = %d\n",a,b); // The value of actual parameters do not change by changing the formal
}
void swap (int a, int b)
{
int temp;
temp = a;
a=b;
b=temp;
printf("After swapping values in function a = %d, b = %d\n",a,b); // Formal parameters, a = 20, b = 10
}
Overwriting assi3.c
!gcc assi3.c
!./a.out
%%file assi3.c
#include <stdio.h>
void swap(int *, int *); //prototype of the function
int main()
{
int a = 10;
int b = 20;
printf("Before swapping the values in main a = %d, b = %d\n",a,b); // printing the value of a and b in main
swap(&a,&b);
printf("After swapping values in main a = %d, b = %d\n",a,b); // The values of actual parameters do change in call by reference, a =
}
void swap (int *a, int *b)
{
int temp;
temp = *a;
*a=*b;
*b=temp;
printf("After swapping values in function a = %d, b = %d\n",*a,*b); // Formal parameters, a = 20, b = 10
}
Overwriting assi3.c
!gcc assi3.c
!./a.out
https://colab.research.google.com/drive/1G9h-G2cgCBlr3xhue6zyYdrOPLZExv8o#scrollTo=-pD8c-EZzGNv&printMode=true 5/9
11/18/23, 7:52 PM Assignment 3 - Colaboratory
%%file assi3.c
#include <stdio.h>
int main() {
double base;
int exponent;
// Call the function to calculate the power and display the result
double result = power(base, exponent);
printf("%.2lf raised to the power of %d is: %.2lf\n", base, exponent, result);
return 0;
}
!gcc assi3.c
!./a.out
%%file assi3.c
#include <stdio.h>
int main() {
int terms;
return 0;
}
Overwriting assi3.c
https://colab.research.google.com/drive/1G9h-G2cgCBlr3xhue6zyYdrOPLZExv8o#scrollTo=-pD8c-EZzGNv&printMode=true 6/9
11/18/23, 7:52 PM Assignment 3 - Colaboratory
!gcc assi3.c
!./a.out
%%file assi3.c
#include <stdio.h>
int main() {
int num1, num2;
// Calculate the product using the function and display the result
int result = multiply(num1, num2);
printf("The product of %d and %d is: %d\n", num1, num2, result);
return 0;
}
Overwriting assi3.c
!gcc assi3.c
!./a.out
10.Find the sum of digits of a number. Number must be passed to a function using pointers.
https://colab.research.google.com/drive/1G9h-G2cgCBlr3xhue6zyYdrOPLZExv8o#scrollTo=-pD8c-EZzGNv&printMode=true 7/9
11/18/23, 7:52 PM Assignment 3 - Colaboratory
%%file assi3.c
#include <stdio.h>
return sum;
}
int main() {
int number;
// Input a number
printf("Enter a number: ");
scanf("%d", &number);
return 0;
}
Overwriting assi3.c
!gcc assi3.c
!./a.out
Enter a number: 34
Sum of digits: 7
%%file assi3.c
#include <stdio.h>
int main() {
int num1, num2;
return 0;
}
Overwriting assi3.c
!gcc assi3.c
!./a.out
https://colab.research.google.com/drive/1G9h-G2cgCBlr3xhue6zyYdrOPLZExv8o#scrollTo=-pD8c-EZzGNv&printMode=true 8/9
11/18/23, 7:52 PM Assignment 3 - Colaboratory
https://colab.research.google.com/drive/1G9h-G2cgCBlr3xhue6zyYdrOPLZExv8o#scrollTo=-pD8c-EZzGNv&printMode=true 9/9