0% found this document useful (0 votes)
28 views42 pages

21BCA0005 Cy-1

The document contains a series of C programming exercises for students in the School of Information Technology and Engineering. Each exercise includes a specific aim, algorithm, and program code to perform tasks such as displaying personal information, calculating time, converting days, and determining eligibility for voting. The document serves as a practical guide for students to practice their programming skills.
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
28 views42 pages

21BCA0005 Cy-1

The document contains a series of C programming exercises for students in the School of Information Technology and Engineering. Each exercise includes a specific aim, algorithm, and program code to perform tasks such as displaying personal information, calculating time, converting days, and determining eligibility for voting. The document serves as a practical guide for students to practice their programming skills.
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd

School of Information Technology and Engineering

Cycle Sheet-1

NAME : [Link] KUMAR


REG NO : 21BCA0005
COURSE CODE : ITA2001
COURSE NAME : PROGRAMMING IN C
___________________________________________________________________________
Basic Input/ Output:
1. Write a C program to display your name, register number
and date of birth.
AIM:
To Write a C program to display your name, register number
and date of birth.
Algorithm:
Start.
By using the “printf” key word display the output.
End.
PROGRAM:
//21BCA0005
#include<stdio.h>

int main()

printf("\nName:[Link] kumar");

printf("\nreg no:21BCA0005");

printf("\ndob: 09/05/2004");

return 0;
}

SCREENSHOT OF PROGRAM AND OUTPUT:

2. Write a C program to accept two “time” from the user in


hours, minutes and seconds. Add them and display the result in
hours, minutes and seconds.
Aim:
To Write a C program to accept two “time” from the user in
hours, minutes and seconds. Add them and display the result in
hours, minutes and seconds.
Algorithm:
Start.
By using the “printf” key word display the output.
End.
PROGRAM:
#include<stdio.h>

int main()

int h1, h2,m1,m2, s1, s2, eh, em, h, m, s;

printf("enter the first time hours, minutes, seconds");

scanf("%d%d%d", &h1, &m1, &s1);

printf("enter the second time in hours, minutes, seconds"); scanf("%d


%d%d",&h2, &m2, &s2);

s=s1+s2;

em=s/60;

m=em+m1+m2;

eh=m/60;

h=eh+h1+h2; s=s`;

m=m`;

printf("%d hours %d minutes %d seconds",h,m,s);

SCREENSHOT OF PROGRAM AND OUTPUT:


3. Write a C program to convert specified days into years,
weeks and days. Ignore leap year.
Aim:
To Write a C program to convert specified days into years,
weeks and days. Ignore leap year.
Algorithm:
Start.
By using the “printf” key word display the output.
End.
PROGRAM:
#include<stdio.h>
int main()
{
int y,w,d;
printf("enter the no of days"); scanf("%d",&d);
y=d/365;
w=(d65)/7;
d=(d65) %7;
printf(" %d years %d weeks %d days",y,w,d);
}
SCREENSHOT OF PROGRAM AND OUTPUT:

4. Write a C program that accepts the employee name, ID


number, total number of hours worked in a month and the
salary per hour. Display the name, ID number and the total
salary (limited to two decimal places) of the employee.
Aim:
To Write a C program that accepts the employee name, ID
number, total number of hours worked in a month and the
salary per hour. Display the name, ID number and the total
salary (limited to two decimal places) of the employee.
Algorithm:
Start.
By using the “printf” key word display the output.
End.

PROGRAM:
#include <stdio.h>

int main()

char name[30];

int hour,ID;

double sal, salary;

printf("Input the employee name: ");

scanf("%s",name);

printf("Input the Employees ID: ");

scanf("%d", &ID);
printf("Input the total number of hrs worked in a month: ");

scanf("%d", &hour);

printf("Salary amount per hour: ");

scanf("%lf", &sal);

salary = sal*hour;

printf("\nEmployee Name : %s",name);

printf("\nEmployee ID : %d",ID);

printf("\nTotal Salary : %.2lf rupees",salary);

return 0;

SCREENSHOT OF PROGRAM AND OUTPUT:

5. There are 50 p coins and Re 1 coins in a box. Given that the


box contains 'X' number of 50 p coins and the number of Re 1
coins is twice as the number of 50 p coins, write a C program to
determine the total amount in the box. For example, if the
number of 50 p coins is 11 then the number of one rupee coins
is 22 and amount of ruppees in the box is 27 and 50 p.

Aim:
To write the above coding of input and show its output.

Algorithm:
Start.
By using the “printf” key word display the output.
End.
PROGRAM:
#include<stdio.h>

int main()

int X,Y;

float tp,tr,amt;

printf("Enter the number of 50 paise in the box 'X':");

scanf("%d",&X);

Y=2*X;
printf("The number of 1 rupee coins is twice as the number of 50 p
coins '2X': %d",Y);

tp=0.50*X;

tr=1*Y;

amt=tp+tr;

printf("\nTotal Amount: %.2f",amt);

return 0;

SCREENSHOT OF PROGRAM AND OUTPUT:

6. Given that three students Adam, Alice and Bob scored an


average of 'a' marks in a test and 'x' as mark of Adam and 'y' as
mark of Alice, develop a flowchart and write a Python code to
determine the mark scored by Bob. For example, if average
marks is 50, marks scored by Adam and Alice is 60 and 55 then
mark scored by Bob is 35.
Aim:
To write the output of the above program.
Algorithm:
Start.
By using the “printf” key word display the output.
End.

PROGRAM:
#include<stdio.h>
int main()
{
float x,y,z, avg;
printf("enter the marks of adam and alice: ");
scanf("%f%f",&x,&y);
printf("enter the average marks:");
scanf("%f",&avg);
z=(avg 3)-(x+y);
printf("marks scored by bob: %f",z);
return 0;
}
SCREENSHOT AND OUTPUT FOR PROGRAM:

Conditional Statements:
7. Using conditional operators, check whether a person is
eligible for voting or not. Accept the age as input. If the age is
greater than or equal to 18, he/ she is eligible for voting.
Aim:
To Using conditional operators, check whether a person is
eligible for voting or not. Accept the age as input. If the age is
greater than or equal to 18, he/ she is eligible for voting
Algorithm:
Start.
By using the “printf” key word display the output.
End.
PROGRAM:
#include <stdio.h>

int main()

int age;

printf("Enter the age of person : ");

scanf("%d", &age);

if (age >= 18)

printf("the person eligible for voting");

else

printf("the person not eligible for voting");

return 0;

SCREENSHOT OF PROGRAM AND OUTPUT:


8. Write a C program to accept the total price from the user and
calculate the final amount to be paid (Final amount= Total Price
– Discount) according to following criteria:
Total price Discount
>10000 20%
>7000 and <=10000 15%
<=7000 10%
Aim:
To write the coding of the above problem and show its output.
Algorithm:
Start.
By using the “printf” key word display the output.
End.
PROGRAM:
#include <stdio.h>

int main()

int total,final;

printf("Enter the total amount:");

scanf("%d",&total);

if(total>10000)

final =total - (20*(total/100));

else if(total>7000&&total<=10000)

final = total -(15*(total/100));

else if(total<7000)

final = total -(10*(total/100));

printf("The final amount is :%d",final);


return 0;

SCREENSHOT OF PROGRAM AND OUTPUT:

9. Write a C program to calculate the late submission charges


with respect to the number of days elapsed.
Till five days: Rs 2/day.
Six to ten days: Rs 3/day.
11 to 15 days: Rs 4/day
After 15 days: Rs 5/day
Aim:
To write the ouput of the above program.
Algorithm:
Start.
By using the “printf” key word display the output.
End.
PROGRAM:
#include <stdio.h>

int main()

int days,charges;

printf("Enter the number of days : ");

scanf("%d",&days);

if(days<=5)

charges = 2*days;

else if(days>=6&&days<=10)

charges=3*days;

else if(days>=11&&days<=15)

{
charges=4*days;

else if (days>15)

charges =5*days;

printf("The total charge is:%drupees",charges);

return 0;

SCREENSHOT OF PROGRAM AND OUTPUT:

10. Using logical operators, write a C program to check whether


a given year is a leap year or not. Logic: If a year is a century
year (year ending with 00) and if it‟s perfectly divisible by 400,
then it‟s a leap year.
Aim:
To write the output of the above program.
Algorithm:
Start.
By using the “printf” key word display the output.
End.
PROGRAM:
#include<stdio.h>

main()

int year;

printf("Enter the year to check for a leap year:");

scanf ("%d", &year);

if ((year % 4 == 0 && year % 100 != 0) || (year % 400 == 0))

printf("The entered year is a leap year.");

Else

{
printf("The entered year is not a leap year.");

SCREENSHOT OF PROGRAM AND OUTPUT:

11. Write a C program to accept two integers as input. Request


the user to enter „+‟, „-„, „/‟, „*‟ to perform addition,
subtraction, division and multiplication respectively. Use switch
case for implementing the same.
Aim:
To write the output of the program.
Algorithm:
Start.
By using the “printf” key word display the output.
End.
PROGRAM:
#include <stdio.h>

int main() {

char op;

double first, second;

printf("Enter an operator (+, -, *, /): ");

scanf("%c", &op);

printf("Enter two operands: ");

scanf("%lf %lf", &first, &second);

switch (op) {

case '+':

printf("%.1lf + %.1lf = %.1lf", first, second, first + second);

break;

case '-':

printf("%.1lf - %.1lf = %.1lf", first, second, first - second);

break;

case '*':

printf("%.1lf * %.1lf = %.1lf", first, second, first * second);

break;
case '/':

printf("%.1lf / %.1lf = %.1lf", first, second, first / second);

break;

// operator doesn't match any case constant

default:

printf("Error! operator is not correct");

return 0; }

SCREENSHOT OF PROGRAM AND OUTPUT:

12. Write a C program to accept date and month as input and


display the date with the appropriate suffix and year as output.
Use switch case for implementing the same.
For example,
Input: 21 March
Output: 21st March

Aim:
To write the output of the above program.
Algorithm:
Start.
By using the “printf” key word display the output.
End.
PROGRAM:
#include<stdio.h>

int main()

int day;

char month [10];

printf("Enter date :");


scanf("%d %s",&day, &month);

printf("%d",day);

switch(day)

case 1:

case 21:

case 31:

printf("st");

break;

case 2:

case 22:

printf("nd");

break;

case 3:

printf("rd");

break;

default:

printf("th");

}
printf("%s",month);

return 0;

SCREENSHOT OF PROGRAM AND OUTPUT:

Looping Statements:
13. Write a C program to accept an integer as input and find the
sum of odd and even digits separately. If the sum of odd and
even digits is same, display the message “Matching”.
Otherwise, display the message “Not matching”. For example,
suppose the user has entered the number 1223. The sum of
odd digits is 4 (3+1) and the sum of even digits is 4 (2+2).
Aim:
To write the output of the abo e program.
Algorithm:
Start.
By using the “printf” key word display the output.
End.
PROGRAM:
#include <stdio.h>

int main()

int size,i,a[10];

int Even_sum = 0, Odd_sum=0;

printf("\n Enter the size of an array :");

scanf("%d",&size);

printf("\n Enter the Array elements\n");

for(i=0;i<size;i++)

scanf("%d",&a[i]);

for(i=0;i<size;i++)

if(a[i] % 2 == 0)

{
Even_sum = Even_sum + a[i];

else

Odd_sum = Odd_sum + a[i];

if(Even_sum == Odd_sum)

printf("\nMATCHING!!!");

else

printf("\nNOTMATCHING");

return 0;

SCREENSHOT OF PROGRAM AND OUTPUT:


14. Write a C program to accept an integer as input and find the
frequency of each digit. For example, suppose the user has
entered the number 1323. The frequency of digit 1 is 1, 3 is 2
and that of 2 is 1.

Aim:
To write the output of the above program.
Algorithm:
Start.
By using the “printf” key word display the output.
End.
PROGRAM:
#include <stdio.h>

int main()

int arr[100], freq[100];

int size, i, j, count;

printf("Enter size of array: ");

scanf("%d", &size);

printf("Enter elements in array: ");

for(i=0; i<size; i++)

scanf("%d", &arr[i]);

freq[i] = -1;

for(i=0; i<size; i++)

count = 1;

for(j=i+1; j<size; j++)

{
if(arr[i]==arr[j])

count++;

freq[j] = 0;

if(freq[i] != 0)

freq[i] = count;

printf("\nFrequency of all elements of array: \n");

for(i=0; i<size; i++)

if(freq[i] != 0)

printf("%d occurs %d times\n", arr[i], freq[i]);

return 0;
}

SCREENSHOT OF PROGRAM AND OUTPUT:

15. Write a C program to find the sum of the following series.


Accept the value of „x‟ and „n‟ from the user.
x-x 2 +x3 -x 4 +…xn
Aim:
To Write a C program to find the sum of the following series.
Accept the value of „x‟ and „n‟ from the user.
Algorithm:
Start.
By using the “printf” key word display the output.
End.
PROGRAM:
#include <stdio.h>
#include <math.h>
void main()
{
int x,sum,ctr;
int i,n,m,mm,nn;
printf("Input the value of x :");
scanf("%d",&x);
printf("Input number of terms : ");
scanf("%d",&n);
sum =x; m=-1;
printf("The values of the series: \n");
printf("%d\n",x);
for (i = 1; i < n; i++)
{
ctr = ( i +1);
mm = pow(x, ctr);
nn = mm * m;
printf("%d \n",nn);
sum = sum + nn;
m = m * (-1);
}
printf("\nThe sum = %d\n",sum);
}
SCREENSHOT AND OUTPUT OF PROGRAM:
16. Write a C program to find the sum of the following series.
Accept the value of „n‟ from the user.

Aim:
To Write a C program to find the sum of the following series.
Accept the value of „n‟ from the user.
Algorithm:
Start.
By using the “printf” key word display the output.
End.
PROGRAM:

#include <stdio.h>
#include <math.h>
long int factorial(int n)
{
int i;
long int fact=1;
if(n==1) return fact;
for(i=n;i>=1;i--)
fact= fact * i;
return fact;
}
int main()
{
int i,N,x=1;
float sum;
int count=1,cnt=0;
printf("Enter total number of terms: ");
scanf("%d",&N);
sum=0.0f;
for(i=1;i<=N;i++)
{
sum = (sum + ( (float)(x) )/ (float)
(factorial(count)));
count = (count+1);

}
printf("Sum of the series is: %f\n",sum);
return 0;
}
17. Write a C program to print the pattern:

Aim:
To Write a C program to print the pattern
Algorithm:
Start.
By using the “printf” key word display the output.
End.
PROGRAM:
#include<stdio.h>
int main()

int n, r, c, s;

printf("Enter number of rows: ");

scanf("%d",&n);

for(r=1;r<=n;r++)

for(s=1;s<=n-r;s++) printf(" ");

for(c=1;c<=r;c++) printf("* ");

printf("\n");

return 0;

SCREENSHOT OF PROGRAM AND OUTPUT:


18. Write a C program to print the Floyd‟s triangle:
Aim:
To Write a C program to print the Floyd‟s triangle.

Algorithm:
Start.
By using the “printf” key word display the output.
End.
PROGRAM:
#include <stdio.h>
void main()
{
int i,j,n,p,q;
printf("Input number of rows : ");
scanf("%d",&n);
for(i=1;i<=n;i++)
{
if(i%2==0)
{ p=1;q=0;}
else
{ p=0;q=1;}
for(j=1;j<=i;j++)
if(j%2==0)
printf("%d",p);
else
printf("%d",q);
printf("\n");
}
}

SCREENSHOT AND OUTPUT OF THE PROGRAM:


****THANKYOU****

You might also like