0% found this document useful (0 votes)
55 views102 pages

FOP Manual

The document contains 51 solutions to programming problems/exercises. Each solution provides the full code for a program that implements the given task. The problems cover basic concepts like input/output, arithmetic operations, conditional statements, loops, functions etc. The solutions demonstrate how to write programs for tasks like printing text, calculating averages, areas, maximum of numbers, character classification, leap years and more using concepts like if-else, switch case, loops, functions etc.

Uploaded by

RK Gaming
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
55 views102 pages

FOP Manual

The document contains 51 solutions to programming problems/exercises. Each solution provides the full code for a program that implements the given task. The problems cover basic concepts like input/output, arithmetic operations, conditional statements, loops, functions etc. The solutions demonstrate how to write programs for tasks like printing text, calculating averages, areas, maximum of numbers, character classification, leap years and more using concepts like if-else, switch case, loops, functions etc.

Uploaded by

RK Gaming
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 102

1

Solution :

2
Solution :

3
Solution :

4
Solution :

5
Solution :

6
Solution :

7
Solution :

8
Solution :

9
Solution :

10
Solution :

11
Solution :

12
Solution :

13
Soultion :

14

15
16
17
18

19
20

21
22

23
24

25 1)
Solution :

2)
Solution :

3)
Solution :

4)
Solution :

5)
Solution :

6)
Solution :

26
Solution :

27
Solution :

28
Solution :

29
Solution :

30
Solution :

31
Solution :

32
Solution :

33
Solution :

34
Solution :

35
Solution :

36
Solution :

37
Solution :

38
Solution :

39
Solution :

40
Solution :

41
Solution :

42
Solution :

43
Solution :

44
Solution :

45
Solution :

46
Solution :

47
Solution :

48
Solution :

49
Solution :
50
Solution :

51
Solution :
KADI SARVA VISHWAVIDYALA
LDRP-ITR GANDHINAGAR
CE/IT DEPARTMENT
FUNDAMENTAL OF PROGRAMMING (CC 103 N) LAB MANUAL

PRACTICAL SET : 1
Write a program to print your address.
#include<stdio.h>
#include<conio.h>
void main()
{
clrscr();
printf("\n\nMY JOB ADDRESS IS");
printf("\n------------------------------------------------");
printf("\n\nL.D.R.P.-ITR,\nMCA Department,\nGandhinagar.");
printf("\n------------------------------------------------");
getch();
}

Write a program to perform average of five variables.


#include<stdio.h>
#include<conio.h>
void main()
{
int a,b,c,d,e;
float avg;
clrscr();
printf("\n\nEnter the five number:===>");
scanf("%d %d %d %d %d",&a,&b,&c,&d,&e);
avg=(float)(a+b+c+d+e)/5;
printf("\n\n\tAverage ===> %f",avg);
getch();
}

Write a program to print area of circle and rectangle.


#include<stdio.h>
#include<conio.h>
void main()
{
float p=3.14,r,area,rarea,l,w;
clrscr();
printf("\n\nEnter the Radious For Circle:===>");
scanf("%f",&r);
printf("\n\nEnter the Length and Width For Rectangle:===>");
scanf("%f",&l,&w);
area=p*r*r;
rarea=l*w;
printf("\n\nArea Of Circle ====> %f",area);
printf("\n\nArea Of Rectangle ====> %f",rarea);
getch();
}

Write a program to convert years into minutes.


#include<stdio.h>
#include<conio.h>
void main()
{
long int year,minute;
clrscr();
printf("\n\nEnter The Year:===>");
scanf("%ld",&year);
minute=year*365*24*60;
printf("Minute Of %ld Year ====> %ld",year,minute);
getch();
}

Write a program to perform all the arithmetic operations together in a single program.
#include<stdio.h>
#include<conio.h>
void main()
{
float no1,no2,sum,mul,sub,div;
clrscr();
printf("\nENTER THE NO1:====>");
scanf("%f",&no1);
printf("\nENTER THE NO2:====>");
scanf("%f",&no2);
sum=no1+no2;
mul=no1*no2;
sub=no1-no2;
div=no1/no2;
printf("\n\nADDITION OF TWO NUMBERS:===>%f",sum);
printf("\n\nSUBTRACTION OF TWO NUMBERS:===>%f",sub);
printf("\n\nMULTIPLICATION OF TWO NUMBERS:===>%f",mul);
printf("\n\nDIVISION OF TWO NUMBERS:===>%f",div);
getch();
}

PRACTICAL SET 2
Write a program to print a character entered by user.
#include<stdio.h>
#include<conio.h>
void main()
{
char ch;
clrscr();
printf(""\n\nEnter the Character:==>"");
scanf(""%c"",&ch);
printf("Entered Character Is:==>%c",ch);
getch();
}

Write a program to convert small letter case to upper letter case.


#include<stdio.h>
#include<conio.h>
void main()
{
char ch;
clrscr();
printf("\n\nEnter the Character:==>");
scanf("%c",&ch);
printf("\t\t");
if(islower(ch))
{
ch=ch-32;
}
printf("Upper Case Character Is:==>%c",ch);
getch();
}

Write a program to swap the values of two variables using third variable.
#include<stdio.h>
#include<conio.h>
void main()
{
int a,b,temp;
clrscr();
printf("ENTER THE VALUE OF A & B:===>");
scanf("%d %d",&a,&b);
temp=a;
a=b;
b=temp;
printf("\t\t\n\n USING THIRD VARIABLE");
printf("\t\t\nVALUE OF A IS:===>%d",a);
printf("\t\t\nVALUE OF B IS:===>%d",b);
getch();
}

Write a program to swap the values of two variables without using third variable.
#include<stdio.h>
#include<conio.h>
void main()
{
int a,b;
clrscr();
printf("ENTER THE VALUE OF A & B:===>");
scanf("%d %d",&a,&b);
a=a+b;
b=a-b;
a=a-b;
printf("\t\n\n WITHOUT THIRD VARIABLE");
printf("\t\t\nVALUE OF A IS:===>%d",a);
printf("\t\t\nVALUE OF B IS:===>%d",b);
getch();
}

Write a program to find maximum and minimum numbers from two numbers by using conditional
#include<stdio.h>
#include<conio.h>
void main()
{
int a,b;
clrscr();
printf("ENTER THE VALUE OF A:===>");
scanf("%d",&a);
printf("ENTER THE VALUE OF B:===>");
scanf("%d",&b);
if(a>b)
{
printf("\n %d IS LARGEST",a);
printf("\n %d IS SMALLEST",b);
}
else if(b>a)
{
printf("\n %d IS LARGEST",b);
printf("\n %d IS SMALLEST",a);
}
else
printf("\n %d and %d both are EQUAL",a,b);
getch();
}

Write a program to demonstrate bitwise operator.


#include<conio.h>
void main()
{

int a = 5, b = 9; // a = 5(00000101), b = 9(00001001)


clrscr();
// The result is 00000001
printf("a = %d, b = %d\n", a, b);
printf("a&b = %d\n", a & b); //Bitwise and

// The result is 00001101


printf("a|b = %d\n", a | b);//Bitwise or

// The result is 00001100


printf("a^b = %d\n", a ^ b); //Bitwise x-or

// The result is 11111010


printf("~a = %d\n", a = ~a); //Complement

// The result is 00010010


printf("b<<1 = %d\n", b << 1);

// The result is 00000100


printf("b>>1 = %d\n", b >> 1);

getch();
}

PRACTICAL SET : 3
Write a program to check whether the entered number is odd or even by using if else statement.
#include <stdio.h>
int 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);

return 0;
}

Write a program to check whether entered character is alphabet, digit or special symbol.
#include <stdio.h>

int main()
{
char ch;

/* Input character from user */


printf("Enter any character: ");
scanf("%c", &ch);

/* Alphabet check */
if((ch >= 'a' && ch <= 'z') || (ch >= 'A' && ch <= 'Z'))
{
printf("'%c' is alphabet.", ch);
}
else if(ch >= '0' && ch <= '9')
{
printf("'%c' is digit.", ch);
}
else
{
printf("'%c' is special character.", ch);
}

return 0;
}

Write a program to find whether entered year is leap year or not.


#include <stdio.h>
int main() {
int year;
printf("Enter a year: ");
scanf("%d", &year);
if (year % 4 == 0) {
if (year % 100 == 0) {
// the year is a leap year if it is divisible by 400.
if (year % 400 == 0)
printf("%d is a leap year.", year);
else
printf("%d is not a leap year.", year);
} else
printf("%d is a leap year.", year);
} else
printf("%d is not a leap year.", year);

return 0;
}

Write a program to check how many days are there in entered month by using switch case.
#include <stdio.h>

int main()
{
int month;
printf("Enter month number(1-12): ");
scanf("%d", &month);

switch(month)
{
case 1:
printf("31 days");
break;
case 2:
printf("28/29 days");
break;
case 3:
printf("31 days");
break;
case 4:
printf("30 days");
break;
case 5:
printf("31 days");
break;
case 6:
printf("30 days");
break;

case.
int main()
{
char ch;

printf("Enter a character: ");


scanf("%c",&ch);

//condition to check character is alphabet or not


if((ch>='A' && ch<='Z') || (ch>='a' && ch<='z'))
{
//check for VOWEL or CONSONANT
switch(ch)
{
case 'A':
case 'E':
case 'I':
case 'O':
case 'U':
case 'a':
case 'e':
case 'i':
case 'o':
case 'u':
printf("%c is a VOWEL",ch);
break;
default:
printf("%c is a CONSONANT",ch);
}
}
else
{

Write a program to get maximum number among three.


#include <stdio.h>

void main()
{
int num1, num2, num3;

printf("Enter the values of num1, num2 and num3\n");


scanf("%d %d %d", &num1, &num2, &num3);
printf("num1 = %d\tnum2 = %d\tnum3 = %d\n", num1, num2, num3);
if (num1 > num2)
{
if (num1 > num3)
{
printf("num1 is the greatest among three \n");
}
else
{
printf("num3 is the greatest among three \n");
}
}
else if (num2 > num3)
printf("num2 is the greatest among three \n");
else
printf("num3 is the greatest among three \n");
}

Write a program to print first 10 integers by using go to statement.


#include <stdio.h>

int main()
{
int counter=1;
int n;
printf("Enter the value of n: ");
scanf("%d",&n);
START:
printf("%d ",counter);
counter++;
if(counter<=n)
goto START;
return 0;
}

Write a program to print addition of first n numbers by using go to statement.


#include <stdio.h>
#include<conio.h>
int main()
{
int counter=1;
int n;
int sum=0;
//enter the value of n (range)
printf("Enter the value of n: ");
scanf("%d",&n);

START:
printf("%d ",counter);
sum=sum+counter;
counter++;
if(counter<=n)
goto START;
printf(" The sum is %d", sum);
return 0;
}

Write a program to find reverse of given numbers. (For example 132-231)


#include <stdio.h>
int main() {
int n, rev = 0, remainder;
printf("Enter an integer: ");
scanf("%d", &n);
while (n != 0) {
remainder = n % 10;
rev = rev * 10 + remainder;
n /= 10;
}
printf("Reversed number = %d", rev);
return 0;
}

Write a program to check whether entered number is Armstrong or not.


#include <stdio.h>
int main() {
int num, originalNum, remainder, result = 0;
printf("Enter a three-digit integer: ");
scanf("%d", &num);
originalNum = num;

while (originalNum != 0) {
remainder = originalNum % 10;
result += remainder * remainder * remainder;
originalNum /= 10;
}
if (result == num)
printf("%d is an Armstrong number.", num);
else
printf("%d is not an Armstrong number.", num);
return 0;
}

Write a program to check whether entered number is palindrome or not.

#include <stdio.h>
int main() {
int n, reversedN = 0, remainder, originalN;
printf("Enter an integer: ");
scanf("%d", &n);
originalN = n;
while (n != 0) {
remainder = n % 10;
reversedN = reversedN * 10 + remainder;
n /= 10;
}
if (originalN == reversedN)
printf("%d is a palindrome.", originalN);
else
printf("%d is not a palindrome.", originalN);
return 0;
}

Write a program to print factorial of a given number.


#include <stdio.h>
int main() {
int n, i;
int fact = 1;
printf("Enter an integer: ");
scanf("%d", &n);
if (n < 0)
printf("Error! Factorial of a negative number doesn't exist.");
else {
for (i = 1; i <= n; ++i) {
fact *= i;
}
printf("Factorial of %d = %d", n, fact);
}
return 0;
}

Write a program to check whether entered number is prime or not.


#include <stdio.h>
int main() {
int n, i, flag = 0;
printf("Enter a positive integer: ");
scanf("%d", &n);

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

// condition for non-prime


if (n % i == 0) {
flag = 1;
break;
}
}

if (n == 1) {
printf("1 is neither prime nor composite.");
}
else {
if (flag == 0)
printf("%d is a prime number.", n);
else
printf("%d is not a prime number.", n);
}

return 0;
}

PRACTICAL SET : 5
Write a program to print Different pattern using For Loop.
1
12
123
1234
12345
#include<stdio.h>

main()
{
int i,j,n;
printf("Enter the value of N:");
scanf("%d",&n);
for(i=1;i<=n;i++)
{
for(j=1;j<=i;j++)
{
printf("%d",j);
}
printf("\n");
}
}

1
22
333
4444
55555
#include<stdio.h>

main()
{
int i,j,n;
printf("Enter the value of N:");
scanf("%d",&n);
for(i=1;i<=n;i++)
{
for(j=1;j<=i;j++)
{
printf("%d",i);
}
printf("\n");
}
}

*****
****
***
**
*
#include<stdio.h>

main()
{
int i,j,n;
printf("Enter the value of N:");
scanf("%d",&n);
for(i=n;i>=1;i--)
{
for(j=1;j<=i;j++)
{
printf("*");
}
printf("\n");
}
}

1
12
123
1234
12345
#include<stdio.h>

main()
{
int i,j,k,n;
printf("Enter the value of N:");
scanf("%d",&n);
for(i=1;i<=n;i++)
{
for(k=1;k<=n-i;k++)
{
printf(" "); /* For extra Spaces to print*/
}
for(j=1;j<=i;j++)
{
printf("%d",j);
}
printf("\n");
}
}

*
**
***
****
*****
****
***
**
*
#include<stdio.h>

main()
{
int i,j,k,n;
printf("Enter the value of N:");
scanf("%d",&n);
for(i=1;i<=n;i++)
{
for(j=1;j<=i;j++)
{
printf("*");
}
printf("\n");
}
for(i=n-1;i>=1;i--)
{
for(j=1;j<=i;j++)
{
printf("*");
}
printf("\n");
}
}

A
23
DEF
78910
KLMNO
#include<stdio.h>

main()
{
int i,j,count=1,n;
char ch='A';
printf("Enter the value of N:");
scanf("%d",&n);
for(i=1;i<=n;i++)
{
for(j=1;j<=i;j++)
{
if(i%2==1)
{
printf("%c",ch);
}
else
{
printf("%d",count);
}
ch++;
count++;
}
printf("\n");
}

PRACTICAL SET : 6
Write a program to print 1 to 5 numbers using array.
#include<stdio.h>

main()
{
int i,a[5];
for(i=0;i<5;i++)
{
a[i]=i+1;
}
for(i=0;i<5;i++)
{
printf("%d\t",a[i]);
}

Write a program to print 1 to 5 reverse numbers using array.


#include<stdio.h>

main()
{
int i,a[5];
for(i=0;i<5;i++)
{
a[i]=5-i;
}
for(i=0;i<5;i++)
{
printf("%d\t",a[i]);
}

Write a program to find sum and average of five numbers.


#include<stdio.h>

main()
{
int i,a[5],sum=0;
float average;
for(i=0;i<5;i++)
{
printf("Enter Value:");
scanf("%d",&a[i]);
sum=sum+a[i];
}
average=sum/5.0;
printf("Sum=%d\tAverage=%f",sum,average);
}

Write a program to find maximum and minimum number from given array.
#include<stdio.h>

main()
{
int i,a[100],n,max,min;

printf("How many numbers?");


scanf("%d",&n);
for(i=0;i<n;i++)
{
printf("Enter Value:");
scanf("%d",&a[i]);
}
max=a[0];
min=a[0];
for(i=0;i<n;i++)
{
if(a[i]<min)
min=a[i];
if(a[i]>max)
max=a[i];
}
printf("Min=%d\tMax=%d",min,max);
}

Write a program to find number of positive, negative and zero from given array.

main()
{
int i,a[100],n,pos=0,neg=0,z=0;

printf("How many numbers?");


scanf("%d",&n);
for(i=0;i<n;i++)
{
printf("Enter Value:");
scanf("%d",&a[i]);
}

for(i=0;i<n;i++)
{
if(a[i]>0)
pos++;
else if(a[i]<0)
neg++;
else
z++;
}
printf("Positive=%d\tNegative=%d\tZeros=%d",pos,neg,z);
}

Write a program to find number of odd and even from given array.
#include<stdio.h>

main()
{
int i,a[100],n,odd=0,even=0;

printf("How many numbers?");


scanf("%d",&n);
for(i=0;i<n;i++)
{
printf("Enter Value:");
scanf("%d",&a[i]);
}

for(i=0;i<n;i++)
{
if(a[i]%2==0)
even++;
else
odd++;
}
printf("Odd=%d\tEven=%d",odd,even);
}

Write a program to sort given n number using array.


#include<stdio.h>

main()
{
int i,j,k,a[100],n,temp;

printf("How many numbers?");


scanf("%d",&n);
for(i=0;i<n;i++)
{
printf("Enter Value:");
scanf("%d",&a[i]);
}
for(i=0;i<n;i++)
{
k=i;
for(j=i+1;j<n;j++)
{
if(a[j]<a[k])
{
k=j; // Find index of the minimum
}
}
if(k!=i)//Replace it.
{
temp=a[i];
a[i]=a[k];
a[k]=temp;
}
}
printf("After sorting:\n");

Write a program to read matrix, display original and transpose of matrix.


#include<stdio.h>

main()
{
int i,j,a[10][10],r,c;

printf("How many rows?");


scanf("%d",&r);
printf("How many columns?");
scanf("%d",&c);
for(i=0;i<r;i++)
{
for(j=0;j<c;j++)
{
printf("Enter Value:");
scanf("%d",&a[i][j]);
}
}
printf("Original Matrix:\n");
for(i=0;i<r;i++)
{
for(j=0;j<c;j++)
{
printf("%d",a[i][j]);
}
printf("\n");

}
printf("Transpose of Matrix:\n");
for(i=0;i<c;i++)
{

PRACTICAL SET : 7
Write a program to copy, reverse, concatenate and find length of a string.
#include<stdio.h>
#include<string.h>

int main()
{
char name1[20],name2[20];
int len;
printf("Enter any name:");
//scanf("%s",name1); // first way to get string
gets(name1); // second way to get string
printf("\nName 1 is ==>%s",name1);

// Copy string
strcpy(name2,name1);
printf("\n\nAfter coping name1 into name2");
printf("\nName 1 is ==>%s",name1);
printf("\nName 2 is ==>%s",name2);

// reverse String
strrev(name2);
printf("\n\nAfter reverse name2");
printf("\nName 2 is ==>%s",name2);

//concatenate String
strcat(name1,name2);
printf("\n\nAfter concatenate name1 and name2");
printf("\nName 1 is ==>%s",name1);
printf("\nName 2 is ==>%s",name2);

//length of string
len=strlen(name1);

Write a program to find length of given string without using string function.
#include<stdio.h>

int main()
{
char str[20];
int len;
printf("Enter any name:");
scanf("%s",str);
printf("\nString is ==>%s",str);

for(len=0;str[len]!='\0';)
len++;
printf("\n\nLength of '%s' is ==>%d",str,len);
return 0;
}

Write a program to copy one string to another string without using string function.
#include<stdio.h>

int main()
{
char str[20],str1[20];
int i;
printf("Enter any name:");
scanf("%s",str);
printf("\nString is ==>%s",str);

for(i=0;str[i]!='\0';i++)
str1[i]=str[i];
str1[i]='\0'; //put null character at the end of string
printf("\n\nAfter coping name1 into name2");
printf("\nName 1 is ==>%s",str);
printf("\nName 2 is ==>%s",str1);
return 0;
}

Write a program to compare two strings.


#include<stdio.h>

int main()
{
char str[20],str1[20];
int i;
printf("Enter First name:");
gets(str);
printf("Enter Second name:");
gets(str1);
printf("\nFirst name is ==>%s",str);
printf("\nSecond name is ==>%s",str1);

for(i=0;(str[i]!='\0')&&(str[i]==str1[i]);i++);

if(str[i]=='\0'&&str1[i]=='\0')
printf("\n\nBoth name are same\n");
else
printf("\n\nBoth name are not same\n");
return 0;
}

Write a program to find given string is palindrome or not.


#include<stdio.h>
#include<string.h>
int main()
{
char str[20],str1[20];
int i;
printf("Enter First name:");
gets(str);

strcpy(str1,str);
strrev(str1);
printf("\nName is ==>%s",str);
printf("\nReverse Name is ==>%s",str1);

for(i=0;(str[i]!='\0')&&(str[i]==str1[i]);i++);

if(str[i]=='\0'&&str1[i]=='\0')
printf("\n\nName is Palindrome\n");
else
printf("\n\nName is not Palindrome\n");
return 0;
}

Write a program to convert a given string into upper case string.


#include<stdio.h>
#include<ctype.h>
int main()
{
char str[20],str1[20];
int i;
printf("Enter any name:");
gets(str);
printf("\nString is ==>%s",str);

for(i=0;str[i]!='\0';i++)
{
str1[i]=toupper(str[i]);
}

str1[i]='\0'; //put null character at the end of string


printf("\n\nAfter coping name1 into name2 in upper case");
printf("\nName 1 is ==>%s",str);
printf("\nName 2 is ==>%s",str1);
return 0;
}

PRACTICAL SET : 8
Write a user defined function (UDF) to print whether entered number is odd or even.
#include<stdio.h>
#include<conio.h>
void oddeven(int);
void main()
{
int n;
clrscr();
printf("\n Enter number::");
scanf("%d",&n);
oddeven(n);
getch();
}
void oddeven(int n)
{
if(n%2==0)
{
printf("\n Even number...");
}
else
{
printf("\n Odd number...");
}
}

Write a program to add first n numbers using user defined function (UDF).
#include<stdio.h>
#include<conio.h>
int sum(int);
void main()
{
int num,ans=0;
clrscr();
printf("\n Enter the number you want to add upto::");
scanf("%d",&num);
ans=sum(num);
printf("\n The sum of %d numbers is %d...",num,ans);
getch();
}
int sum(int num)
{
int add=0;
while(num!=0)
{
add=add+num;
num--;
}
return add;
}

Write a program to find out average of first n numbers using user defined function (UDF).
#include<stdio.h>
#include<conio.h>
float average(int);
void main()
{
int num;
float ans;
clrscr();
printf("\n Enter the number you want to find average upto::");
scanf("%d",&num);
ans=average(num);
printf("\n The average of first %d numbers is %.2f...",num,ans);
getch();
}
float average(num)
{
int add=0,oldn=num;
float avg;
while(num!=0)
{
add=add+num;
num--;
}
avg=(float)add/oldn;
return avg;

PRACTICAL SET : 9
Write a program using structure to get name, roll number, and marks of a student’s of a class and
#include<stdio.h>
#include<conio.h>
struct student
{
int roll,marks;
char name[10];
};
void main()
{
struct student s[3];
int max=0,i,r;
clrscr();
for(i=0;i<=2;i++)
{
printf("\n Enter student name:");
scanf("%s",s[i].name);
printf("\n Enter roll no:");
scanf("%d",&s[i].roll);
printf("\n Enter marks::");
scanf("%d",&s[i].marks);
if(s[i].marks>max)
{
max=s[i].marks;
r=i;
}
}
printf("\n Details of student having maximum marks is:\nName: %s \nRoll no: %d\n Marks:
%d",s[r].name,s[r].roll,s[r].marks);
getch();

Write a program to enter the details (Name, Employee_id, Salary) of employees using the concept of
#include<conio.h>
struct employee
{
int id;
char name[10];
struct salary
{
int basic,DA;
}sal;
}emp;
void main()
{
int total;
clrscr();
printf("\n *** Details of Employee ***");
printf("\n Name of employee:");
scanf("%s",emp.name);
printf("\n Employee id:");
scanf("%d",&emp.id);
printf("\n Basic and DA::");
scanf("%d \n %d",&emp.sal.basic,&emp.sal.DA);
total=emp.sal.basic+emp.sal.DA;
printf("\n Total salary is %d",total);
getch();
}

Write a program to create an employee structure having member’s name, salary, Get data in
employee structure through one function and display data using another function. Use the concept
#include<stdio.h>
#include<conio.h>
#include<string.h>
struct Member
{
int salary;
char name[10];
};
struct Member get_data(struct Member mem);
void print_data(struct Member mem);
void main()
{
struct Member mem,mem_new;
clrscr();
printf("\n *** Details of member ***");
mem_new=get_data(mem);
print_data(mem_new);
getch();
}
struct Member get_data(struct Member mem)
{
printf("\n Enter Member name:");
scanf("%s",mem.name);
printf("\n Enter salary:");
scanf("%d",&mem.salary);
return mem;
}
void print_data(struct Member mem)
{
printf("\n Member having name %s got %d salary...",mem.name,mem.salary);

PRACTICAL SET : 10
Write a program to declare and use pointer variables.
#include<stdio.h>
#include<conio.h>
void main()
{
int p=100,*ptr;
clrscr();
ptr=&p;
printf("\n\n\nValue Of P===>%d and %d",p,*ptr);
printf("\n\n\nAdress Of P===>%u and %u",&p,ptr);
getch();
}

Write a program to swap two values with help of call by value and call by reference.
#include<stdio.h>
#include<conio.h>
void change(int *,int *);
void swap(int,int);
void main()
{
int a,b;
clrscr();
printf("\n\nEnter the a:===>");
scanf("%d",&a);
printf("\n\nEnter the b:===>");
scanf("%d",&b);
change(&a,&b);
printf("\n\nSwaping With Call By Reference\n\n");
printf("Change Value Of A = %d and B = %d",a,b);
swap(a,b);
getch();
}
void change(int *a,int *b)
{
int temp;
temp=*a;
*a=*b;
*b=temp;
}
void swap(int a,int b)
{
int temp;
temp=a;
a=b;
b=temp;

Write a program to find length of string using pointer and without using string functions.
#include<conio.h>

int string_len(char *p);


void main()
{
char s[20];
int i,len;
clrscr();

printf("Enter string = ");


scanf("%s",s);

len=string_len(s);
printf("\nLength of string = %d ",len);
getch();
}

int string_len(char *p)


{
int count=0;
while(*p!='\0')
{
count++;
p++;
}
return count;
}

PRACTICAL SET : 11
Write a program to write the characters into file from standard input and then read the characters
#include<stdio.h>
#include<conio.h>
void main()
{
FILE *fp;
char c;
clrscr();

fp=fopen("input","w");

while((c=getc(stdin))!=EOF)
{
putc(c,fp);
}
fclose(fp);

fp=fopen("input","r");
while((c=getc(fp))!=EOF)
putc(c,stdout);

getch();
}
Write a program that copies the contents of one file into another.
#include<stdio.h>
#include<conio.h>

void main()
{
FILE *fp1,*fp2;
char c;
clrscr();

fp1=fopen("input","r");
fp2=fopen("output","w");
while((c=getc(fp1))!=EOF)
putc(c,fp2);
printf("File copied");
fclose(fp1);
fclose(fp2);
getch();
}

Write a program that appends the content of a file at the end of the other.
#include<stdio.h>
#include<conio.h>
void main()
{
FILE *fp;
char c;
clrscr();
fp=fopen("input","a");
while((c=getchar())!=EOF)
{
putc(c,fp);
}
fclose(fp);

fp=fopen("input","r");
while((c=getc(fp))!=EOF)
putc(c,stdout);
fclose(fp);
getch();
}

You might also like