0% found this document useful (0 votes)
11 views

C lab file format-1

Uploaded by

aanku5835
Copyright
© © All Rights Reserved
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
11 views

C lab file format-1

Uploaded by

aanku5835
Copyright
© © All Rights Reserved
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 5

PROGRAMMING IN C LAB

REPORT FILE

Submitted by:
Name of the Students
Class and Section

Prestige Institute Management and Research


Opposite DeenDayal Nagar, Bhind Road, Gwalior
E-mail: [email protected]

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.

3 WAP to calculate simple interest.

4 Write a C program to calculate the electricity bill based on given


consumption slabs and rates.
5. WAP to print the sum and product of digits of an integer.

6 WAP to reverse a number.

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.

18 WAP to perform following operation on string without using Library


function:
a) Length of a string
b) Reverse of a String
19 WAP to create a structure of student (ID, Name, Age) perform Insert and
display operation.
20 WAP to create a union of student (ID, Name, Age) perform Insert and
display operation.
21 WAP to create a structure of student (ID, Name, Age) and access its
members using ->(arrow) operator.

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

You might also like