Download as docx, pdf, or txt
Download as docx, pdf, or txt
You are on page 1of 108

INSTITUTE OF CHARTED AND FINANCIAL ANALYSIS OF INDIA UNIVERSITY

(Affiliated to University Grants Commision (UGC), Approved by UGC & Govt.


of Himachal Pradesh)

PRACTICAL FILE
of

COMPUTER PROGRAMMING - II
BACHELOR OF TECHNOLOGY
(Computer Science Engineering)
Submitted by

MANISH KUMAR YADAV

20STUCHPN01004

Batch(2020-2024)
Under guidance of

Mrs. Pooja Sharma


(Assistant Professor)

Department of Computer Science

The ICFAI University, Baddi

DEPAERTMENT OF COMPUTER SCIENCE AND


ENGINEERING THE ICFAI UNIVERSITY, BADDI
HIMACHAL PRADESH-174103

...............................................................................................
INDEX for Practical list
Sr. No. Practical Name Date of Teacher
Practical Signature
1. Write a C program to print “My name”. 09-april-2021
2. Write a C program to print “Welcome to 09-april-2021
the ICFAI UNIVERSITY HP”.
3. Write a C program to add two numbers. 16-april-2021
4. Write a C program to add three numbers. 16-april-2021
5. Write a C program to find square of a 16-april-2021
number.
6. Write a C program to find the cube of a 23-april-2021
number.
7. By using C, do arithmetic operations. 23-april-2021
8. To print the lines on a console without 23-april-2021
entering in printf function.
9. Write a C program to find average of two 30-april-2021
numbers.
10. Write a C program to find average of four 30-april-2021
numbers.
11. Write a C program to find the simple 30-april-2021
interest with the value enter at the time
of program execution.
12. Write a program for char , int and float. 07-may-2021
13. Write a program to find the area of a 07-may-2021
rectangle.
14. Write a program to find the increment 07-may-2021
and decrement operators and also find
(post & pre) operators in case of
increment and decrement operators.
15. Write a program to define the Relational 14-may-2021
operators.
16. Write a program to define the Bitwise 14-may-2021
operators.
17. Write a program to define the Logical 14-may-2021
operators.
18. Write a program to define the Assignment 21-may-2021
operators.
19. Write a program for decision making ‘if’ 21-may-2021
statement.
20. Write a program for decision making ‘if- 21-may-2021
else’ statement.
21. Write a program for decision making ‘if- 28-may-2021
else if ladder’ statement.
22. Write a program for decision making 28-may-2021
‘Switch’ statement.
23. Write any two programs using do- 28-may-2021
while loop statement.
24. Write any two programs while loop 04-june-2021
statement.
25. Write any two programs for loop 04-june-2021
statement.
26. Write any two programs based on type 04-june-2021
conversion/casting.
27. Write any four programs based on storage 11-june-2021
classes.
28. Write any four programs based on 11-june-2021
jumping classes.
29. Write any one program for reverse of a 11-june-2021
number.
30. Write any one program for each 18-june-2021
formatted/unformatted I/O function.
31. Write any one program for each program 18-june-2021
for string function.
32. Write program for function in c. 18-june-2021
33. Write program for function parameters in 25-june-2021
c.
34. Write a program for arrays in c. 25-june-2021
35. Write program for structure in c. 25-june-2021
36. Write program for union in c. 02-july-2021
37. Write program for pointer in c. 02-july-2021
38. Write program for declaration and 02-july-2021
initialization of a variable in c.
39. Write program for to get a number as 09-july-2021
age and display whether the person is
young
or adult in c.
40. Write program to check the given 09-july-2021
character is a vowel or consonant.
41. Write program to reverse the array. 09-july-2021
42. Write program to calculate the factorial 16-july-2021
of a given integer using function.
43. Write a program find the number is 16-july-2021
palindrome or not.
44. Write a program to read n numbers 16-july-2021
into an array A to find the
***Sum of odd numbers.
***Sum of even numbers.
***Average of all numbers.
45. Write a program dynamic 23-july-2021
memory allocation in c.
46. Write a program for file handling in c. 23-july-2021
Practical 1
AIM:- Write a C program to print "Welcome to ICFAI UNIVERSITY HP".

Input Code:-

#include <stdio.h>

int main()

printf("Welcome to the ICFAI UNIVERSITY HP.\n");

return 0;

OUTPUT:-

Practical 2
AIM:- Write a C program to print "My

Name". Input Code:-

#include<stdio.h>

int main()
{

printf("My name is Manish Yadav.");

return 0;

OUTPUT:-

Practical 3
AIM:- Write a C program to add two numbers.

INPUT CODE:-

#include<stdio.h>

int main()

int a,b,c;

printf("Enter the value of a:");

scanf("%d",&a);

printf("Enter the value of b:");

scanf("%d",&b);
c=a+b;

printf("The sum of 'a&b' is %d\n",c);

return 0;

OUPUT:-

Practical 4
AIM:- Write a C program to add three numbers.

INPUT CODE:-

#include<stdio.h>

int main()

int a,b,c,d;

printf("Enter the value of a:");

scanf("%d",&a);

printf("Enter the value of b:");

scanf("%d",&b);
printf("Enter the value of c:");

scanf("%d",&c);

d=a+b+c;

printf("The sum of 'a,b&c' is %d\n",d);

return 0;

OUTPUT:-

Practical 5
AIM:- Write a C program to find the square of a number.

INPUT CODE:-

#include<stdio.h>

int main()

int a;

printf("Enter the value of a:");

scanf("%d",&a);
printf("The square of 'a' is:%d\n",a*a);

return 0;

OUTPUT:-

Practical 6
AIM:- Write a C program to find cube of a number.

INPUT CODE:-

#include<stdio.h>

int main()

int a;

printf("Enter the value of a:");

scanf("%d",&a);

printf("The cube of 'a' is:%d\n",a*a*a);

return 0;

}
OUTPUT:-

Practical 7
AIM:- Write a C program to do operations like multiplication,division,subtraction of two number.

INPUT CODE:-

#include<stdio.h>

int main()

int a,b,c,d;

float e;

printf("Enter the value of a:");

scanf("%d",&a);

printf("Enter the value of b:");

scanf("%d",&b);

c=a-b;

d=a*b;
e=a/b;

printf("The subtraction of 'a&b' is %d\n",c);

printf("The product of 'a&b' is %d\n",d);

printf("The division of 'a&b' is %f\n",e);

return 0;

Output:-

Practical 8
AIM:- Write a C program to print lines on a console without entering 'printf' function.

INPUT CODE:-

#include<stdio.h>

int main()

char a[]="Hello,My name is Manish.";

char b[]="I study in ICFAI

University.";
char c[]="In B Tech CSE.";

printf("%s\n%s\n%s\n",a,b,c);

return 0;

OUTPUT:-

Practical 9
AIM:- Write a C program to find the average of two numbers.

INPUT CODE:-

#include<stdio.h>

int main()

float a,b,c;

printf("Enter the value of a:");

scanf("%f",&a);
printf("Enter the value of b:");

scanf("%f",&b);

c=(a+b)/2;

printf("The average of 'a&b' is %f\n",c);

return 0;

OUTPUT:-

Practical 10
AIM:- Write a C program to find the average of four numbers.

INPUT CODE:-

#include<stdio.h>

int main()

float a,b,c,d,e;
printf("Enter the value of a:");

scanf("%f",&a);

printf("Enter the value of b:");

scanf("%f",&b);

printf("Enter the value of c:");

scanf("%f",&c);

printf("Enter the value of d:");

scanf("%f",&d);

e=(a+b+c+d)/4;

printf("The average of 'a&b' is %f\n",e);

return 0;

OUTPUT:-

Practical 11
AIM:- Write a C program to find the simple interest.
INPUT CODE:-

#include<stdio.h>

int main()

float p,r,t,SI;

printf("Enter the value of p:");

scanf("%f",&p);

printf("Enter the value of r:");

scanf("%f",&r);

printf("Enter the value of t:");

scanf("%f",&t);

SI=(p*r*t)/100;

printf("SI is %f\n",SI);

return 0;

OUTPUT:-
Practical 12
AIM:- Write a C program for char ,int and float.

INPUT CODE:-

#include<stdio.h>

int main()

int a;

char b[]="Manish";

float c,d;

printf("Enter the value of a:");

scanf("%d",&a);

printf("Enter the value of c:");

scanf("%f",&c);

d=a*c;

printf("The product of 'a&c' is %f\n",d);

printf("The character value is :%s\n",&b);

return 0;

OUTPUT:-
Practical 13
AIM:- Write a C program to find the area of

rectangle. INPUT CODE:-

#include<stdio.h>

int main()

float l,b,area;

printf("Length of a rectangle:");

scanf("%f",&l);

printf("Breadth of a rectangle:");

scanf("%f",&b);

area=l*b;

printf("The area of rectangle is %f\n",area);

return 0;
}

OUTPUT:-

Practical 14
AIM:- Write a C program to find the increment and decrement operators alse find (post & pre) operators
in case of increment and decrement operators.

INPUT CODE:-

#include<stdio.h>

int main()

int a,b;

printf("Enter the value of a:");

scanf("%d",&a);

printf("Enter the value of b:");

scanf("%d",&b);

printf ("The value of a before increment:%d\n",a);


printf ("The value of a after increment:%d\n",++a);

printf ("The value of a in pre increment:%d\n",++a);

printf ("The value of a in post increment:%d\n",a++);

printf ("The value of b before decrement:%d\n",b);

printf ("The value of b in pre decrement:%d\n",--b);

printf ("The value of b in post decrement:%d\n",b--);

return 0;

OUTPUT:-

Practical 15
AIM:- Write a C program to define the relational operators.

INPUT CODE:-

#include<stdio.h>

int main()

{
int a,b;

printf("Enter the value of a:");

scanf("%d",&a);

printf("Enter the value of b:");

scanf("%d",&b);

printf ("Check if 'a' is not equal to 'b':%d\n",a!=b);

printf ("Check if 'a' is greater than 'b':%d\n",a>b);

printf ("Check if 'b' is greater than 'a':%d\n",b>a);

printf ("Check if 'a' is less than 'b':%d\n",a<b);

printf ("Check if 'b' is less than 'a':%d\n",b<a);

printf ("Check if 'a' is greater than or equal to 'b':%d\n",a>=b);

printf ("Check if 'b' is greater than or equal to 'a':%d\n",b>=a);

printf ("Check if 'a' is less than or equal to 'b':%d\n",a<=b);

printf ("Check if 'b' is less than or equal to 'a':%d\n",b<=a);

printf ("Check if 'a' is equal to 'b':%d\n",a==b);

return 0;

OUTPUT:-
Practical 16
AIM:- Write a C program to define the bitwise operators.

INPUT CODE:-

#include<stdio.h>

int main()

int a,b;

printf("Enter the value of a:");

scanf("%d",&a);

printf("Enter the value of b:");

scanf("%d",&b);

printf ("a&b is:%d\n",a&b);

printf ("a|b is:%d\n",a|b);

printf ("a^b is:%d\n",a^b);


return 0;

OUTPUT:-

Practical 17
AIM:- Write a C program to define the logical operators.

INPUT CODE:-

#include <stdio.h>

int main()

int a,b;

printf("Enter the value of a:");

scanf("%d",&a);

printf("Enter the value of b:");

scanf("%d",&b);
if((a>5)&&(b<5)){

printf("Both conditions are true\n");

if ((a>=10)||(b>=10)){

printf("At-least one of the condition is true\n");

} if(!

((a>5)&&(b<5))){

// If ((a>5) && (b<5))is true, logical NOT operator will makes it false and vice versa.

printf("Truth value of (a>5) && (b<5)) is False\n");

return 0;

OUTPUT:-
Practical 18
AIM:- Write a C program to define the assignment operators.

INPUT CODE:-

#include <stdio.h>

int main()

int a=10,b=16;

b+=a;

printf("The addition AND assignment is %d\n",b);

b-=a;

printf("The subtraction AND assignment is %d\n",b);

b*=a;

printf("The product AND assignment is %d\n",b); b

%=a;
printf("The modulus AND assignment is %d\n",b);

return 0;

OUTPUT:-

Practical 19
AIM:- Write a C program for decision making 'if'

statement. INPUT CODE:-

#include <stdio.h>

int main()

int a=441,b=7;

if(a%b==0){

printf("'a' is divisible by 'b'.\n");

}
return 0;

OUTPUT:-

Practical 20

AIM:- Write a C program for decision making 'if-else' statement.


AIM20.1:- Write a C program to find the greatest between two numbers using 'if-else' statement.

INPUT CODE:-

#include <stdio.h>

int main()

int a,b;

printf("Enter the value of a:");

scanf("%d",&a);

printf("Enter the value of b:");


scanf("%d",&b);

if(a>b){

printf("'a' is the greatest number.\n");

else if(a==b){

printf("'a' & 'b' are equal.\n");

else {

printf("'b' is the greatest number.\n");

return 0;

OUTPUT:-

AIM20.2:- Write a C program to find the year you entered is leap or not using 'if-else' statement.
INPUT CODE:-

#include <stdio.h>

int main()

int x;

printf("Enter a year:

"); scanf("%d", &x);

if (x % 400 == 0) {

printf("It is a leap year.\n",x);

else if (x % 100 == 0) {

printf("It is not a leap year.\n",x);

else if (x % 4 == 0) {

printf("It is a leap year.\n",x);

else {

printf("It is not a leap year.\n",x);

return 0;

OUTPUT:-
Practical 21
AIM21.1:- Write a C program to find the greatest between three numbers using 'if-else' ladder.

INPUT CODE:-

#include <stdio.h>

int main()

int a,b,c;

printf("Enter the value of a:");

scanf("%d",&a);

printf("Enter the value of b:");

scanf("%d",&b);

printf("Enter the value of c:");

scanf("%d",&c);

if(a>b&&a>c){
printf("a is the greatest number.");

else if(b>a&&b>c){

printf("b is the greatest number.");

else{

printf("c is the greatest number.");

return 0;

OUTPUT:-

Practical 21
AIM21.1:- Write a C program to show the name of the day in a week using 'if-else' ladder.

INPUT CODE:-
#include <stdio.h>

int main()

int x;

printf("Enter a weekday no.:");

scanf("%d",&x);

if(x==1){

printf("MONDAY\n");

else if(x==2){

printf("TUESDAY\n");

else if(x==3){

printf("WEDNESDAY\n");

else if(x==4){

printf("THRUSDAY\n");

else if(x==5){

printf("FRIDAY\n");

else if(x==6){

printf("SATURDAY\n");

else{

printf("SUNDAY\n");
}

return 0;

OUTPUT:-

AIM21.3:- Write a C program to check whether the number is even or odd.

INPUT CODE:-

#include<stdio.h>

int main()

int a;

printf("Enter a:");

scanf("%d",&a);

if(a%2==0){

printf("%d is an even number.\n",a);

}
else{

printf("%d is an odd number.\n",a);

return 0;

OUTPUT:-

AIM21.3:- Write a C program to check whether the number is positive or negative.

INPUT CODE:-

#include<stdio.h>

int main()

int a;

printf("Enter a:");

scanf("%d",&a);

if(a>=0){

printf("%d is a positive number.\n",a);


}

else{

printf("%d is a negative number.\n",a);

return 0;

Practical 22
AIM22.1:- Write a C program to to apply operation on two number using switch statement.

INPUT CODE:-

#include <stdio.h>

int main()

int a,b,d;

char operations;
printf("Enter a:");

scanf("%d",&a);

printf("Enter b:");

scanf("%d",&b);

printf("Operation to perform:");

scanf(" %c",&operations);

switch(operations)

case'+':

d=a+b;

printf("The sum of a&b=%d",d);

break;

case'-':

d=a-b;

printf("The subtraction of a&b=%d",d);

break;

case'*':

d=a*b;

printf("The multiplication of a&b=%d",d);

break;

case'%':
d=a%b;

printf("The modulus of a&b=%d",d);

break;

default:

printf("Operation not applicable");

return 0;

OUTPUT:-

AIM22.2:- Write a C program to to find the day in a week using switch statement.

INPUT CODE:-

#include <stdio.h>

int main()

{
int Weekday;

printf("Enter Weekday:");

scanf("%d",&Weekday);

switch(Weekday)

case 1:

printf("MONDAY");

break;

case 2:

printf("TUESDAY");

break;

case 3:

printf("WEDNESDAY");

break;

case 4:

printf("THRUSDAY");

break;

case 5:

printf("FRIDAY");

break;
case 6:

printf("SATURDAY");

break;

case 7:

printf("SUNDAY");

break;

default:

printf("PLEASE! Enter a valid Weekday.");

return 0;

OUTPUT:-
Practical 23
AIM23.1:- Write a C program, using do while loop print the multiplication table of any number.

INPUT CODE:-

#include <stdio.h>

int main()

int n;

printf("Print table of:");

scanf("%d",&n);

int i=1;

do{

printf("%d*%d=%d\n",n,i,n*i);

i++;

}while(i<=10);

return 0;

OUTPUT:-
AIM23.2:- Write a C program, using do while loop print the multiplication table of any number.

INPUT CODE:-

#include <stdio.h>

int main()

int n;

printf(" Print numbers till:");

scanf("%d",&n);

int i=1;

do{

printf("%d ",i);

i++;

}while(i<=n);
return 0;

OUTPUT:-

Practical 24
AIM24.1:- Write a C program, using while print the multiplication table of any number.

INPUT CODE:-

#include <stdio.h>

int main()

int n;

printf("Print table of:");

scanf("%d",&n);

int i=1;

while(i<=10){
printf("%d*%d=%d\n",n,i,n*i);

i++;

return 0;

OUTPUT:-

AIM24.2:- Write a C program, using while loop print all the numbers from 0 to 200.

INPUT CODE:-

#include <stdio.h>

int main()

int i=0;

while(i<=200){

printf("%d ",i);

i++;

return 0;
}

OUTPUT:-

Practical 25
AIM25.1:- Write a C program, using for loop find the factorial of any number.

INPUT CODE:-

#include <stdio.h>

int main()

int n,a=1,i=1;

printf("Enter n:");

scanf("%d",&n);

for(;i<=n;i++){

a*=i;

printf("The factorial of %d is : %d",n,a);

return 0;
}

OUTPUT:-

AIM25.2:- Write a C program, using for loop print the infinite no. of lines .

INPUT CODE:-

#include <stdio.h>

int main()

int n;

for(int i=1;i<=n;){

printf("INFINITE LOOP RUN.\n");

return 0;

OUTPUT:-
AIM25.3:- Write a C program to find the nth number in a fibonacci series.

INPUT CODE:-

#include <stdio.h>

int main()

int n;

printf("Enter n:");

scanf("%d",&n);

int a=0,b=1,c;

for(int i=1;i<=n-2;i++){

c=a+b;

a=b;

b=c;

}
printf("The %dth fibonacci number is : %d ",n,c);

return 0;

OUTPUT:-

AIM25.4:- Write a C program to check whether the entered number is Armstrong number or not.

INPUT CODE:-

#include <stdio.h>

int main() {

int n,x,r,result=0;

printf("Enter a three-digit integer: ");

scanf("%d",&n);

x=n;

while (x!=0){

r=x%10;
result+=r*r*r;

x/=10;

if (result==n)

printf("%d is an Armstrong number.\n",n);

else

printf("%d is not an Armstrong number.\n",n);

return 0;

OUTPUT:-

Practical 26
Aim26.1: To make use of implicit type

conversion INPUT CODE:-

#include <stdio.h>
int main(void){

int i = 5;

char ch= 'c';

float k = ch + i;

printf("%f", k);

return 0;

OUTPUT:-

AIM 26.2 : Write a program for Explicit type conversion.

INPUT CODE:-

#include <stdio.h>

int main(void){

double num = 48.6658;

int k;

k=(int)num;

printf("%d", k);
return 0;

OUTPUT:-

Practical 27
AIM 27: Write any four programs based on storage

classes. AIM 27.1 : Write a program for auto storage class.

INPUT CODE:-

#include <stdio.h>

int main(void){

int k = 10;

for(k = 0; k<5; k++){

printf("%d",k);

return 0;

OUTPUT:-
AIM 27.2 : Write a program for Extern storage

class. INPUT CODE:-

#include <stdio.h>

extern int num1 = 1;

extern int num2 = 2;

int main()

int num1 = 3;

int num2 = 4;

int add = num1 + num2;

printf("%d + %d = %d ", num1, num2, add);

return 0;

OUTPUT:-
AIM 27.3 : Write a program for static storage

class. INPUT CODE:-

#include <stdio.h>

int main()

static int k;

static char ch;

static float f;

printf("%d,%c,%f",k,ch,f);

return 0;

OUTPUT:-
AIM 27.4 : Write a program for register storage class.

INPUT CODE:-

#include <stdio.h>

int main()

register int k;

printf("%d",k);

OUTPUT:-
Practical 28
AIM 28: Write any four programs based on jumping classes.

AIM 28.1 : Write a program for break jumping class.

INPUT CODE:-

#include <stdio.h>

int main()

for(int k =1; k<10; k++)

{ printf("K =

%d\n",k); if(k>=8){

break;

OUTPUT:-
AIM 28.2 : Write a program for CONTINUE jumping

class. INPUT CODE:-

#include <stdio.h>

int main() {

int i, j;

for (i = 1; i < 3; i++) {

for (j = 1; j < 5; j++)

{ if (j == 2)

continue;

printf("%d\n", j);

return 0;

OUTPUT:-
AIM 28.3 : Write a program for go-to jumping class.

INPUT CODE:-

#include <stdio.h>

int main() {

int i, j;

for (i = 1; i < 5; i++)

{ if (i == 2)

goto there;

printf("%d\n", i);

there:

printf("Two");

return 0;

OUTPUT:-
Practical 29
AIM 29 : Write any one program for reverse of a number.

INPUT CODE:-

#include <stdio.h>

int main()

int n, r = 0;

printf("Enter a number to reverse : ");

scanf("%d", &n);

while (n != 0) {

r = r * 10;

r = r + n%10;

n = n/10;

printf("Reverse of the number = %d\n", r);

return 0;

}
OUTPUT:-

Practical 30
AIM 30: Write any one program for each formatted /unformatted I/O fxn.

AIM 30.1 : Write a program for formatted I/O fxn.

INPUT CODE:-

#include <stdio.h>

int main()

int k;

printf("Enter k : ");

scanf("%d",&k);

printf("k = %d",k);

return 0;

OUTPUT:-
AIM 30.2 : Write a program for unformatted I/O fxn.

INPUT CODE:-

#include<stdio.h>

void main()

char c;

printf("Enter a character : ");

c=getchar();

printf("c = %c ",c);

return 0;

OUTPUT:-
Practical 31
AIM 31: Write any one program for each program for string function.

AIM 31.1 : Write a program for string.

INPUT CODE:-

#include<stdio.h>

void main()

char ch[10]={'M','a','n','i','s','h','\0'};

printf("The is string is : %s",ch);

return 0;

OUTPUT:-
AIM 31.2 : Write a program for find the length of string.

INNPUT CODE:-

#include<stdio.h>

#include<string.h>

void main()

char ch[10]={'M','a','n','i','s','h','\0'};

printf("The length of string is : %d",strlen(ch));

return 0;

OUTPUT:-
AIM 31.3 : Write a program for copy of two string.

INPUT CODE:-

#include<stdio.h>

#include<string.h>

void main()

char ch[10]={'M','a','n','i','s','h','\0'};

char ch1[10];

strcpy(ch1,ch);

printf("Copy of string is : %s",ch1);

return 0;

OUTPUT:-
AIM 31.4 : Write a program for find the concatenation of string.

INPUT CODE:-

#include<stdio.h>

#include<string.h>

void main()

char ch[10]={'M','a','n','i','s','h','\0'};

char ch1[20]={'Y','a','d','a','v','\0'};

strcat(ch,ch1);

printf("string is : %s",ch);

return 0;

OUTPUT:-
AIM 31.5 : Write a program for find the reverse of string.

INPUT CODE:-

#include<stdio.h>

#include<string.h>

void main()

char ch[20];

printf("Enter the string : ");

gets(ch);

printf("The string is : %s\n",ch);

printf("The reverse of the string : %s",strrev(ch));

return 0;

OUTPUT:-
AIM 31.6 : Write a program for comparing the two strings.

INPUT CODE:-

#include<stdio.h>

#include<string.h>

void main()

char ch1[20];

char ch2[20];

printf("Enter the first string : ");

gets(ch1);

printf("Enter the second string : ");

gets(ch2); if(strcmp(ch1,ch2)==0)

printf("String are equal.\n");

else{

printf("String are not equal.\n");


}

return 0;

OUTPUT:-

AIM 31.7 : Write a program for lower case of a string.

INPUT CODE:-

#include<stdio.h>

#include<string.h>

void main()

char ch[20];

printf("Enter the string : ");

gets(ch);

printf("The lowercase of entered string is : %s",strlwr(ch));

return 0;

OUTPUT:-
AIM 31.8 : Write a program for upper case of a string.

INPUT CODE:-

#include<stdio.h>

#include<string.h>

void main()

char ch[20];

printf("Enter the string : ");

gets(ch);

printf("The uppercase of entered string is : %s",strupr(ch));

return 0;

OUTPUT:-
Practical 32
AIM 32: Write program for function in c.

INPUT CODE :-

#include<stdio.h>

float square ( float x );

int main( )

float m, n ;

printf ( "\nEnter some number for finding square \n");

scanf ( "%f", &m );

n = square ( m );

printf ( "\nSquare of the given number %f is %f",m,n );

float square ( float x )

{
float p;

p = x*x;

return (p);

OUTPUT:-

Practical 33
AIM 33: Write program for function parameters in c.

AIM 33.1 : Write a program for function call by value.

INPUT CODE:-

#include <stdio.h>

int sqr(int p);

int main()

int n=10;

printf("Square of %d is %d\n",n, sqr(n));

return 0;
}

int sqr(int p)

p = p*p;

return(p);

OUTPUT:-

AIM 33.2 : Write a program for function call by refrence.

INPUT CODE:-

#include <stdio.h>

void swap(int *x, int *y) {

int temp;

temp = *x;

*x = *y;

*y = temp;
return;

int main ()

int a = 100;

int b = 200;

printf("value of a before swapping : %d\n", a );

printf("value of b before swapping : %d\n", b );

swap(&a, &b);

printf("value of a after swapping : %d\n", a );

printf("value of b after swapping : %d\n", b

);

return 0;

OUTPUT:-
Practical 34
AIM 34: Write program for arrays in c.

AIM 34.1.a : Write a program for declaration without initialization of values using array.

INPUT CODE:-

#include <stdio.h>

int main ()

int a[100];

return 0;

AIM 34.2 : Write a program for declaration with initialization of values using array.

INPUT CODE:-

#include <stdio.h>

int main ()

int a[6]={11,12,21,34,45,65};

printf("The values entered in array are as follow\n");


for(int i=0; i<6; i++){

printf("The value at index %d is %d\n",i,a[i]);

return 0;

OUTPUT:-

AIM 34.3 : Write a program for find average using array.

INPUT CODE:-

#include <stdio.h>

int main ()

int a[6]={11,12,21,34,45,65};

int sum=0;

for(int i=0; i<6; i++){

sum=sum+a[i];

printf("The avg of the entered values is %d\n",sum/5);


return 0;

OUTPUT:-

AIM 34.4 : Write a program for find largest number using array.

INPUT CODE:-

#include <stdio.h>

int main ()

int a[6]={11,12,21,34,45,65},max;

max=a[0];

for(int i=1; i<6; i++){

if(max<a[i]){

max=a[i];

printf("The largest number in array is %d\n",max);

return 0;
}

OUTPUT:-

AIM 34.5 : Write a program for DEFINE THE NUMBER IS EVEN OR ODD using array.

INPUT CODE:-

#include <stdio.h>

int main ()

int a[6]={11,12,21,34,45,65};

for(int i=0; i<6; i++){

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

printf("%d is even\n",a[i]);

else{

printf("%d is odd\n",a[i]);

return 0;
}

OUTPUT:-

AIM 34.6 : Write a program for Two dimensional(2-d) array.

INPUT CODE:-

#include <stdio.h>

int main ()

int a[2][3]={{4,5,6},{8,9,7}};

for(int i=0; i<2; i++){

for(int j=0;j<3;j++){

printf("The value at ith index %d and at jth index %d is %d\n",i,j,a[i][j]);

printf("\n");

return 0;

OUTPUT:-
AIM 34.7 : Write a program for Multi dimensional array.

INPUT CODE:-

#include <stdio.h>

int main ()

int a[2][2][3]={{{4,5,6},{8,9,7}},{{8,1,2},{8,6,2}}};

printf("The elements in the multidimensional array are as follows\n");

for(int i=0; i<2; i++){

for(int j=0;j<2;j++){

for(int k=0; k<3;k++){

printf("%d",a[i][j][k]);

printf("\n");

printf("\n");

return 0;
}

OUTPUT:-

AIM 34.8 : Write a program for find the reverse of array.

INPUT CODE:-

#include <stdio.h>

int main ()

int a[5]={10,20,30,40,50};

printf("The reverse of array is : ");

for(int i=4; i>=0; i--){

printf("%d ,",a[i]);

return 0;

OUTPUT:-
Practical 35
AIM 35: Write program for arrays in c.
AIM 35.1 : Write a program for declaration of structure .

INPUT CODE:-

#include <stdio.h>

struct student{

int stu_r_no;

char stu_name;

float stu_marks;

};

int main ()

return 0;

AIM 35.2 : Write a program for of structure to store data of many students .

INPUT CODE:-
#include <stdio.h>

struct student{

int stu_r_no;

char stu_name[20];

float stu_gpa;

}s[5];

int main ()

for(int i=0; i<5; i++){

printf("Enter the student %d roll number : ",i+1);

scanf("%d",&s[i].stu_r_no);

printf("Enter the student %d name : ",i+1);

scanf("%s",&s[i].stu_name);

printf("Enter the student %d GPA : ",i+1);

scanf("%f",&s[i].stu_gpa);

printf("\n");

for(int i=0; i<5; i++){

printf("Roll Number : %d \n",s[i].stu_r_no);

printf("Name: %s \n",s[i].stu_name);

printf("GPA : %f \n",s[i].stu_gpa);

return 0;

OUTPUT:-
AIM 35.4 : Write a program for nesting structure .

INPUT CODE:-

#include <stdio.h>

struct date{

int day;

char month[20];

int year;

};

struct student{

int stu_r_no;

char

stu_name[20];

float stu_gpa;

struct date d;

}s[5];

int main ()

for(int i=0; i<5; i++){


printf("Enter the student %d roll number : ",i+1);

scanf("%d",&s[i].stu_r_no);

printf("Enter the student %d name :

",i+1); scanf("%s",&s[i].stu_name);

printf("Enter the student %d GPA : ",i+1);

scanf("%f",&s[i].stu_gpa);

printf("Enter the Date of birth of the student in order of dd/mm/yy/ : ");

scanf("%d%s%d",&s[i].d.day,&s[i].d.month,&s[i].d.year);

printf("\n");

for(int i=0; i<5; i++){

printf("Roll Number : %d \n",s[i].stu_r_no);

printf("Name: %s \n",s[i].stu_name);

printf("GPA : %f \n",s[i].stu_gpa);

printf("Date Of Birth : %d-%s-%d \n",s[i].d.day,s[i].d.month,s[i].d.year);

return 0;

OUTPUT:-
Practical 36
AIM 36: Write program for union in c.

AIM 36.1 : Write a program for declaration of union.

#include<stdio.h>

union student{

int stu_rno;

char stu_name[30];

float stu_marks;

};

int main()

return 0;

}
Practical 37
AIM 37: Write programs for pointers in c.

AIM 37.1 : Write a program for declaration of pointer .

INPUT CODE:-

#include<stdio.h>

int main()

int n =15;

int *p;

return 0;

AIM 37.2 : Write a program for operators in pointer

INPUT CODE:-

#include<stdio.h>

int main()

int n =15;

int *p;

p =&n;

return 0;

AIM 37.3 : Write a program for swaping of number using pointer .

INPUT CODE:-

#include <stdio.h>

int main()
{

int x,y,*a,*b,temp;

printf("Enter the value of x and y :

"); scanf("%d%d", &x, &y);

printf("Before Swapping\nx = %d\ny = %d\n", x, y);

a = &x;

b = &y;

temp = *b;

*b = *a;

*a = temp;

printf("After Swapping\nx = %d\ny = %d\n", x, y);

return 0;

OUTPUT:-
AIM 37.4 : Write a program for null pointer .

INPUT CODE:-

#include <stdio.h>

int main()

int *p = NULL;

printf("The Address of p : %x\n", p);

return 0;

OUTPUT:-
AIM 37.5 : Write a program for pointer to array .

INPUT CODE:-

#include <stdio.h>

int main()

int *p;

int a[5]={10,20,30,40,50};

p=&a[0];

int i;

for(int i =0; i<5; i++){

printf("a[%d]: value is %d and address is %p\n",i,*p,p);

p++;

return 0;

OUTPUT:-
AIM 37.6 : Write a program for double pointer .

#include<stdio.h>

int main(){

int a=50,*p,**pp;

p=&a;

pp = &p;

printf("Address of a is %x and address of p is %x\n",p,pp);

printf("value of p is %d and value of pp is %d \n",*p,**pp);

}
OUTPUT:-

AIM 37.7 : Write a program for arithmatic pointer .

AIM 37.7 .a: Write a program for increment operator in pointer.

INPUT CODE:-

#include<stdio.h>

int main(){

int n = 50;

int *p;

p=&n;

printf("Address of p variable is %u \n",p);

p=p+1;

printf("After increment: Address of p variable is %u \n",p);


}

OUTPUT:-
AIM 37.7 .b: Write a program for decrement operator in pointer .

INPUT CODE:-

#include<stdio.h>

int main(){

int n = 50;

int *p;

p=&n;

printf("Address of p variable is %u \n",p);

p=p-1;

printf("After increment: Address of p variable is %u \n",p);

OUTPUT:-
AIM 37.7 .c: Write a program for addition operator in pointer .

INPUT CODE:-

#include<stdio.h>

int main(){

int n = 50;

int *p;

p=&n;

printf("Address of p variable is %u \n",p);

p=p+2;

printf("After Addition: Address of p variable is %u \n",p);

OUTPUT:-
AIM 37.7 .d: Write a program for subtraction operator in pointer .

INPUT CODE:-

#include<stdio.h>

int main(){

int n = 50;

int *p;

p=&n;

printf("Address of p variable is %u \n",p);

p=p-3;

printf("After Subtraction: Address of p variable is %u \n",p);

OUTPUT:-
Practical 38
AIM 38: Write program for declaration and initialization of a variable in c.

INPUT CODE :-

#include<stdio.h>

int main()

int age;

age = 20;

printf("Age = %d \n",age);

return 0;

OUTPUT:-
Practical 39
AIM 39: Write program to get a number as age and display whether the person is young and adult in c.

INPUT CODE :-

#include<stdio.h>

int main()

int age;

printf("Enter Age:");

scanf("%d",&age);

if(age>=18){

printf("You are an adult.\n");

else{

printf("You are young.\n");

return 0;
}

OUTPUT:-

Practical 40
AIM 40: Write program to check the given character is a vowel or consonant.

INPUT CODE :-

#include <stdio.h>

int main() {

char c;

int lowercase_vowel, uppercase_vowel;

printf("Enter an alphabet: ");

scanf("%c", &c);

lowercase_vowel = (c == 'a' || c == 'e' || c == 'i' || c == 'o' || c == 'u');

uppercase_vowel = (c == 'A' || c == 'E' || c == 'I' || c == 'O' || c == 'U');


if (lowercase_vowel || uppercase_vowel)

printf("%c is a vowel.", c);

else

printf("%c is a consonant.", c);

return 0;

OUTPUT:-

Practical 41
AIM 41: Write program to reverse an array.

INPUT CODE :-

#include<stdio.h>

int main()

int size;

printf("Enter the size of array:");

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

printf("Enter the array elements :");

int i;

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

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

printf("Reversed array is:\n");

for(i = size-1; i >= 0; i--)

printf("%d\t",arr[i]);

return 0;

OUTPUT:-
Practical 42
AIM 42: Write program to calculate the factorial of a given integer using function.

INPUT CODE :-

#include <stdio.h>

int fact(int n)

int i,f=1;

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

f=f*i;

return f;

int fact(int);

int main()

int no,factorial;

printf("Enter a number :");

scanf("%d",&no);

factorial=fact(no);

printf("Factorial of the num(%d) = %d\n",no,factorial);

OUTPUT:-
Practical 43
AIM 43: Write program to find the number in palindrome or not.

INPUT CODE :-

#include<stdio.h>

int main()

int n,r,sum=0,temp;

printf("Enter the number = ");

scanf("%d",&n);

temp=n;

while(n>0)

r=n%10;

sum=(sum*10)+r;

n=n/10;
}

if(temp==sum){

printf("It is a palindrome number. ");

else{

printf("It is not a palindrome.");

return 0;

OUTPUT:-

Practical 44
AIM 44: Write program to read n numbers into an array A.

AIM 44.1:Sum of odd numbers.

INPUT CODE :-

#include <stdio.h>
int main()

int n;

int odd_sum=0;

printf("Enter size of array :");

scanf("%d",&n);

int arr[n];

printf("Enter the elements of array :");

for(int i=0; i<n; i++){

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

for(int i=0; i<n; i++)

{ if(arr[i]%2!=0){

odd_sum += arr[i];

printf("The sum of odd elements in the array : %d\n",odd_sum);

return 0;

OUTPUT:-
AIM 44.2: Sum of even numbers.

INPUT CODE :-

#include <stdio.h>

int main()

int n;

int even_sum=0;

printf("Enter size of array :");

scanf("%d",&n);

int arr[n];

printf("Enter the elements of array :");

for(int i=0; i<n; i++){

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

}
for(int i=0; i<n; i++)

{ if(arr[i]%2==0){

even_sum += arr[i];

printf("The sum of even elements in the array : %d\n",even_sum);

return 0;

OUTPUT:-

AIM 44.3: Average of all numbers.

INPUT CODE :-

#include <stdio.h>

int main()
{

int n;

int total_sum=0;

printf("Enter size of array :");

scanf("%d",&n);

int arr[n];

printf("Enter the elements of array :");

for(int i=0; i<n; i++){

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

for(int i=0; i<n; i++)

{ if(arr[i]%2==0){

total_sum += arr[i];

printf("The average of all elements of the array : %d\n",total_sum/n);

return 0;

OUTPUT:-
Practical 45
AIM 45: Write program for dynamic memory allocation in c.

INPUT CODE :-

#include <stdio.h>

#include <stdlib.h>

int main(){

int n;

printf("For how many data items you want to allocate memory dynamically\n");

scanf("%d", &n);

int *ptr;

ptr = (int *) malloc (n*sizeof(int));

if(ptr == NULL){

printf("Memory is not allocated\n");

}else{

printf("Memory is allocated you can enter the value in it dynamically\n");


int i;

for(i = 0; i < n; i++){

ptr[i] = i+1;

printf("The elements entered in the dyanmic memory is as follows\n");

for(i = 0; i < n; i++){

printf("%d ", ptr[i]);;

return 0;

}OUTPUT:-

Practical 46
AIM 46: Write program for file handling in c.
INPUT CODE :-

#include <stdio.h>

#include <string.h>

int main(){

FILE *fp;

char ch[50] = "Welcome_to_ICFAI";

fp = fopen ("new.c","r");

if(fp == NULL){

printf("No exist\n");

}else{

printf("Exist\n");

while(fgets(ch,50,fp)){

printf("%s\n", ch);

fclose(fp);

printf("data allocated successfully loaded\n");

printf("File closed\n");

}
return 0;

OUTPUT:-

You might also like