C lab file format-1
C lab file format-1
REPORT FILE
Submitted by:
Name of the Students
Class and Section
i
TABLE OF CONTENT
S.NO. PROGRAM Pg. No
1 Write a program (WAP) to find the greatest number among three input
numbers.
2 WAP to check if an input integer number is even or odd.
7 WAP to compute the sum of the first n terms of the following series S =
1/2+1/3+1/4+……
8 WAP to compute the sum of the first n terms of the following series S =1-
2+3-4+5……….
9 Write a function that checks whether a given string is Palindrome or not.
Use this function to find whether the string entered by user is Palindrome
or not.
10 Write a function that swaps two numbers. WAP to call it by value and call
by reference.
11 WAP to print a triangle of stars as follows (take number of lines from
user):
*
***
*****
*******
*********
12 WAP to perform following actions on an array entered by the user:
i) Print the even-valued elements
ii) Print the odd-valued elements
iii) Calculate and print the sum and average of the elements of array
iv) Print the maximum and minimum element of array
v) Print the array in reverse order.
13 Write a program which takes the radius of a circle as input from the user,
passes it to another function that computes the area and the circumference
ii
of the circle and displays the value of area and circumference from the
main() function.
14 Write programs to perform following operations on strings:
a) Show address of each character in string
b) Concatenate two strings without using strcat function.
c) Concatenate two strings using strcat function.
d) Compare two strings
e) Calculate length of the string (use pointers)
f) Convert all lowercase characters to uppercase
g) Convert all uppercase characters to lowercase
h) Calculate number of vowels
i) Reverse the string
15 WAP to calculate Factorial of a number (i)using recursion, (ii) using
iteration
16 Write programs to perform following operations (2-D array
implementation):
a) Sum
b) Difference
17 WAP to count frequency of each element of an array.
PROGRAM-1
iii
Write a Program to print the sum and product of digits of an integer.
#include <stdio.h>
void sum_and_product(int number) {
int sum = 0, product = 1, digit;
if (number == 0) {
sum = 0;
product = 0;
}
while (number != 0) {
digit = number % 10; // Extract the last digit
sum += digit; // Add the digit to sum
product *= digit; // Multiply the digit to product
number /= 10; // Remove the last digit
}
printf("Sum of digits: %d\n", sum);
printf("Product of digits: %d\n", product);}
int main() {
int num;
printf("Enter an integer: ");
scanf("%d", &num);
sum_and_product(num);
return 0;
}
OUTPUT:
iv
1