C Programs
C Programs
#include <stdio.h>
int main(void) {
int term = 7;
printf(" %d ", fibonocci_term(term));
}
int main(){
int num;
int no = 1;
printf("enter a number :");
scanf("%d", & num);
OUTPUT
enter a number :7
7 is odd
3. Implement a function in C that uses pointers to reverse an array in place.
Then, write an equivalent function in Python.
#include <stdio.h>
void reverse_array(int numbers[], int length);
int main(){
int nums[12] = {1,3,5,6,7,8,11,22,33,44,55,66};
int num = 12;
int i = 0;
printf("Array contents before reverse is :\n");
for (i = 0; i < num; i++){
printf("%d \n", nums[i]);
}
reverse_array(nums, num);
OUTPUT
Array contents before reverse is :
1
3
5
6
7
8
11
22
33
44
55
66
Array contents after reverse function is called :
66
55
44
33
22
11
8
7
6
5
3
1
4. Implement the Armstrong number check using both a recursive and an iterative
approach in both C and Python.
https://www.geeksforgeeks.org/program-for-armstrong-numbers/
5. Write a program in C and Python to compare two strings without using string
library functions.
#include <stdio.h>
int my_strcmp(char *s1, char *s2);
int main(){
char str1[] = "aello";
char str2[] = "abcd";
}
int my_strcmp(char *s1, char *s2){
while (*s1 == *s2){
s1++;
s2++;
if(*s1 == '\0')
return 0;
}
OUTPUT
3
9. Check whether a given number is super prime? By using C and Python ( For example
7331 is super prime because 7331 is prime, 733 is prime, 73 is prime,7 is prime, Such
numbers are called super prime)
// super prime
#include <stdio.h>
#include <math.h>
int main(){
int num = 120;
int flag = 0;
while( num > 0){
if(is_prime(num) == 0){
flag = 1;
break;
}
num = num / 10;
}
if(flag == 1){
printf("number is not super prime");
}
else
printf("number is super prime");
}
if(n % i == 0)
{
flag = 1;
break;
}
}
if (flag ==1)
return 0;
else
return 1;
}
10. Implement the Sieve of Eratosthenes algorithm in both C and Python to generate
prime numbers up to a large value
https://www.geeksforgeeks.org/c-program-to-implement-sieve-of-eratosthenes/
19. Write a program in both C and Python to implement a recursive function that
calculates the factorial of a number. Compare the memory usage and execution speed
of both programs when calculating large factorials (e.g., factorial of 100). Why might C
handle this task differently from Python, and how does memory management in each
language affect the result?
#include <stdio.h>
int main()
{
int num = 5;
printf("%d", factorial(num));
}