PRACTICAL FILE
C PROGRAMMING
CIT113
Session: 2021 - 2022
Submitted to: Dr. Neelam Gupta Submitted by: Sagar Sharma
Designation: Assistant Professor Roll. No. : A1004821111
Institute: AIIT Course: BCA
AMITY INSTITUTE OF INFORMATION TECHNOLOGY
AMITY UNIVERSITY UTTAR PRADESH, NOIDA
Session: 2020 – 2021 (Odd Semester)
Name: Sagar Sharma
Enrollment no. A1004821111
Subject: C programming
Date of Date of
S.No. Experiment Name Remarks
Performance Checking
1 Print in c programming 24/09/2021
2 Program To add two integers 2/10/2021
3 Program to check odd and even 12/10/2021
4 Program to Demonstrate if statement 12/10/2021
5 Program to Calculate rate 12/10/2021
6 Program to Calculate Bonus 12/10/2021
7 Program to Calculate gross 13/10/2021
8 Program to demonstrate Nested if 13/10/2021
9 Program if else (2) 13/10/2021
10 Program if else (3) 13/10/2021
11 Program if else (4) 13/10/2021
12 Program if else (5) 13/10/2021
13 Program to check wow or headache 14/10/2021
14 C program to print all natural numbers from 1 to n 18/10/2021
15 C program to all natural numbers in reverse from n to 1 18/10/2021
16 C program to print all even numbers from 1 to n 18/10/2021
17 . C program to print all Odd numbers from 1 to n 18/10/2021
18 C program to print multiplication table of a number 18/10/2021
19 C program to check positive negative or zero using 18/10/2021
simple if statement
20 . C program to check Leap Year 18/10/2021
21 Switch case suit heart 28/10/2021
22 Switch case gold prize 28/10/2021
23 Switch case employees 28/10/2021
24 Switch case caught, trapped 28/10/2021
25 Switch case two char in case 28/10/2021
26 Write a program to display character A to Z using 2/11/2021
loops ?
27 Write a program to copy without using string copy 2/11/2021
function?
28 Nested loops 2/11/2021
29 Switch case 4/11/2021
30 Find the maximum of the two numbers 6/11/2021
1.Program to print in c programming
#include <stdio.h>
int main()
{
printf("Hello World ");
return 0;
}
2.Program to Add two numbers
#include <stdio.h>
int main()
{
int number1, number2, sum;
printf("Enter two integers: ");
scanf("%d %d", &number1, &number2);
// calculating sum
sum = number1 + number2;
printf("%d + %d = %d", number1, number2, sum);
return 0;
}
3.Program to check Odd and Even Number
#include <stdio.h>
void main() {
int num;
printf("Enter an integer: ");
scanf("%d", &num);
// True if num is perfectly divisible by 2
if(num % 2 == 0)
printf("%d is even.", num);
else
printf("%d is odd.", num);
}
4.Demonstrate if statement
# include <stdio.h>
int main( )
{
int num ;
printf ( "Enter a number less than 10 " ) ;
scanf ( "%d", &num ) ;
if ( num < 10 )
printf ( "What an obedient servant you are !\n" ) ;
return 0 ;
}
5.calculate rate
# include <stdio.h>
int main( )
{
int qty, dis = 0 ;
float rate, tot ;
printf ( "Enter quantity and rate " ) ;
scanf ( "%d %f", &qty, &rate) ;
if ( qty > 1000 )
dis = 10 ;
tot = ( qty * rate ) - ( qty * rate * dis / 100 ) ;
printf ( "Total expenses = Rs. %f\n", tot ) ;
return 0 ;
}
6.Calculate Bonus
# include <stdio.h>
int main( )
{
int bonus, cy, yoj, yos ;
printf ( "Enter current year and year of joining " ) ;
scanf ( "%d %d", &cy, &yoj ) ;
yos = cy - yoj ;
if ( yos > 3 )
{
bonus = 2500 ;
printf ( "Bonus = Rs. %d\n", bonus ) ;
}
return 0 ;
}
7.Calculate Gross
# include <stdio.h>
int main( )
{
float bs, gs, da, hra ;
printf ( "Enter basic salary " ) ;
scanf ( "%f", &bs ) ;
if ( bs < 1500 )
{
hra = bs * 10 / 100 ;
da = bs * 90 / 100 ;
}
else
{
hra = 500 ;
da = bs * 98 / 100 ;
}
gs = bs + hra + da ;
printf ( "gross salary = Rs. %f\n", gs ) ;
return 0 ;
}
8.Nested If
# include <stdio.h>
int main( )
{
int i ;
printf ( "Enter either 1 or 2 " ) ;
scanf ( "%d", &i ) ;
if ( i == 1 )
printf ( "You would go to heaven !\n" ) ;
else
{
if ( i == 2 )
printf ( "Hell was created with you in mind\n" ) ;
else
printf ( "How about mother earth !\n" ) ;
}
return 0 ;
}
9.If statement (2)
# include <stdio.h>
int main( )
{
int a = 300, b, c ;
if ( a >= 400 )
b = 300 ;
c = 200 ;
printf ( "%d %d\n", b, c ) ;
return 0 ;
}
10.if(3)
# include <stdio.h>
int main( )
{
int a = 500, b, c ;
if ( a >= 400 )
b = 300 ;
c = 200 ;
printf ( "%d %d\n", b, c ) ;
return 0 ;
}
11.if(4)
# include <stdio.h>
int main( )
{
int x = 10, y = 20 ;
if ( x == y ) ;
printf ( "%d %d\n", x, y ) ;
return 0 ;
}
12. If(5)
# include <stdio.h>
int main( )
{
int x = 3 ;
float y = 3.0 ;
if ( x == y )
printf ( "x and y are equal\n" ) ;
else
printf ( "x and y are not equal\n" ) ;
return 0 ;
}
13. Wow headache
# include <stdio.h>
int main( )
{
int i = 65 , j = 75 ;
if ( i == j )
printf ( "C is WOW\n" ) ;
else
printf ( "C is a headache\n" ) ;
return 0 ;
}
14. C program to print all natural numbers from 1 to n
#include <stdio.h>
int main()
int i, n;
printf("Enter any number: ");
scanf("%d", &n);
printf("Natural numbers from 1 to %d : \n", n);
for(i=1; i<=n; i++)
printf("%d\n", i);
return 0;
15. C program to all natural numbers in reverse from n to 1
#include <stdio.h>
int main()
int i, start;
printf("Enter starting value: ");
scanf("%d", &start);
for(i=start; i>=1; i--)
printf("%d\n", i);
return 0;
16. C program to print all even numbers from 1 to n */
#include <stdio.h>
int main()
int i, n;
printf("Print all even numbers till: ");
scanf("%d", &n);
printf("Even numbers from 1 to %d are: \n", n);
for(i=1; i<=n; i++)
/* Check even condition before printing */
if(i%2 == 0)
printf("%d\n", i);
return 0;
}
17. C program to print all Odd numbers from 1 to n
#include <stdio.h>
int main()
int i, n;
printf("Print odd numbers till: ");
scanf("%d", &n);
printf("All odd numbers from 1 to %d are: \n", n);
for(i=1; i<=n; i++)
/* If 'i' is odd then print it */
if(i%2!=0)
printf("%d\n", i);
return 0;
}
18.C program to print multiplication table of a number
#include <stdio.h>
int main()
int i, num;
printf("Enter number to print table: ");
scanf("%d", &num);
for(i=1; i<=10; i++)
printf("%d * %d = %d\n", num, i, (num*i));
return 0;
}
19.C program to check positive negative or zero using simple if statement
#include <stdio.h>
int main()
int num;
printf("Enter any number: ");
scanf("%d", &num);
if(num > 0)
printf("Number is POSITIVE");
if(num < 0)
printf("Number is NEGATIVE");
if(num == 0)
printf("Number is ZERO");
return 0;
}
20. C program to check Leap Year
#include <stdio.h>
int main()
int year;
printf("Enter year : ");
scanf("%d", &year);
/*
* If year is exactly divisible by 4 and year is not divisible by 100
* or year is exactly divisible by 400 then
* the year is leap year.
* Else year is normal year
*/
if(((year % 4 == 0) && (year % 100 !=0)) || (year % 400==0))
printf("LEAP YEAR");
else
printf("COMMON YEAR");
return 0;
21. Program for switch case
)# include <stdio.h>
int main( )
int suite = 3 ;
switch ( suite )
{
case 1 :
printf ( "Diamond\n" ) ;
case 2 :
printf ( "Spade\n" ) ;
default :
printf ( "Heart\n" ) ;
printf ( "I thought one wears a suite\n" ) ;
return 0 ;
22. gold medal switch case program
# include <stdio.h>
int main( )
int c = 3 ;
switch ( c )
case '3' :
printf ( "You never win the silver prize\n" ) ;
break ;
case 3 :
printf ( "You always lose the gold prize\n" ) ;
break ;
default :
printf ( "Of course provided you win a prize\n" ) ;
return 0 ;}
23. program switch case employees
# include <stdio.h>
int main( )
int i = 3 ;
switch ( i )
case 0 :
printf ( "Customers are dicey\n" ) ;
case 1 + 0 :
printf ( "Markets are pricey\n" ) ;
case 4 / 2 :
printf ( "Investors are moody\n" ) ;
case 8 % 5 :
printf ( "At least employees are good\n" ) ;
return 0 ;
24. Program Switchcase caught trapped
# include <stdio.h>
int main( )
int k ;
float j = 2.0 ;
switch ( k = j + 1 )
case 3 :
printf ( "Trapped\n" ) ;
break ;
default :
printf ( "Caught!\n" ) ;
return 0 ;
25. program switch case two characters in case
# include <stdio.h>
int main( )
int ch = 'a' + 'b' ;
switch ( ch )
case 'a' :
case 'b' :
printf ( "You entered b\n" ) ;
case 'A' :
printf ( "a as in ashar\n" ) ;
case 'b' + 'a' :
printf ( "You entered a and b\n" ) ;
return 0 ;
26. Write a program to display character A to Z using loops ?
#include <stdio.h>
Int main(){
Char c;
For( c = ‘A’; c <=’Z’; ++c )
Printf(“%c”, c);
Return 0;
}
27. Write a program to copy without using string copy function?
#include <stdio.h>
int main()
char s1[100], s2[100], i;
printf("Enter string s1:");
fgets(s1, sizeof(s1), stdin);
for (i = 0; s1[i]!='\0'; ++i){
s2[i] = s1[i];
s2[i]= '\0';
printf("String s2: %s", s2);
return 0;
28. Nested Loops
#include<stdio.h>
int main() {
int i,j;
for(j=1;j<=5;j++) {
for(i=1;i<=j;i++)
printf("%5d",i);
printf("\n\n"); }
return 0;
29. Switch Case
#include<stdio.h>
int main ()
int i = 2;
switch (i)
{ case 1: printf ("i am in case 1 \n");
Break;
case 2: printf ("i am in case 2 \n");
break;
case 3: printf ("i am in case 3 \n");
break;
default: printf ("i am in default \n");
break;
return 0;
30. Write a program to find maximum Between two no. using if else statement ?
#include<stdio.h>
int main(){
int a,b;
printf("Enter two numbers:\n");
scanf("%d%d", &a, &b);
if(a>b)
printf("%d is a maximum number \n", a);
else
printf("%d is a maximum number \n", b);
return 0;