You are on page 1of 36

INDEX

Sr.No. Topic Date Sign.


1. Write a c program that input and output the
string?
2. Write a c program to illustrate the use of
getche(),getchar(),getch() and putchar()?
3. Write a c program to illustrate the use of
Strlen()strcpy(),strcmp(),strcat(),strrev()?
4. Write a c program to check whether a given
string is Palindrome or not?
5. Write a c program to illustrate the
assignment of complete structure?
6. Write a c program to read the
roll,name,marks of the n students in a class
& find the average marks of the class?
7. Write a c program to illustrate returning a
value of structure type via return statement?
8. Write a c program to illustrate passing of
structure variable using call by value?
9. Write a c program to illustrate passing of
structure variable using call by reference?
10. Write a c program to illustrate the concept of
pointers & structure?
11. Write a c program that output the value of a
variable using pointer?
Practical No:1

 Write a c program that input and output the string?


INPUT
#include <stdio.h>

#include<conio.h>

int main()

char array[100];

clrscr();

printf("\n");

printf("Enter a string\n");

scanf("%s", array);

printf("\n");

printf("Your string: %s\n", array);

getch();

}
OUTPUT
Practical No:2

 Write a c program to illustrate the use of


getche(),getchar(),getch() and putchar()?
INPUT
#include<stdio.h>

#include<conio.h>

main()

char c;

printf("\nType a character and press enter Key:-");

c=getchar();

printf("Typed character is:-");

putchar(c);

printf("\nType a character again:-");

c=getche();

printf("\nTyped character is:-");

putchar(c);

printf("\nTyped a character again");

c=getch();

printf("\nTyped character is:-");


putchar(c);

getch();}

OUTPUT
Practical No:3

 Write a c program to illustrate the use of


Strlen()strcpy(),strcmp(),strcat(),strrev()?
INPUT

 Strlen()
#include<stdio.h>

#include <string.h>

#include<conio.h>

int main()

char *str = "practical file of c";

clrscr();

printf("\nLength of string is: %d", strlen(str));

getch();

}
OUTPUT
 strcpy():-
INPUT
#include<stdio.h>

#include<string.h>

#include <conio.h>

int main ()

char str1[]="Hello Geeks!";

char str2[] = "GeeksforGeeks";

char str3[40];

char str4[40];

char str5[] = "GfG";

clrscr();

strcpy(str2, str1);

strcpy(str3, "Copy successful");

strcpy(str4, str5);

printf ("\nstr1: %s\nstr2: %s\nstr3: %s\nstr4: %s\n", str1,


str2, str3, str4);

getch();

}
OUTPUT
 strcmp():-
INPUT
#include <stdio.h>

#include<string.h>

#include<conio.h>

int main()

char str1[20];

char str2[20];

int value;

clrscr();

printf("\nEnter the first string : ");

scanf("%s",str1);

printf("Enter the second string : ");

scanf("%s",str2);

if(strcmp(str1,str2)==0)

printf("strings are same");

else

printf("strings are not same");

getch();

}
OUTPUT
 strcat():-
INPUT
#include <stdio.h>

#include<string.h>

#include<conio.h>

int main()

char str1[20];

char str2[20];

clrscr();

printf("\n*Enter the first string : ");

scanf("%s",str1);

printf("*Enter the second string : ");

scanf("%s",str2);

strcat(str1,str2);

printf("*combined name is:%s",str1);

getch();

}
OUTPUT
 strrev():-
INPUT
#include <stdio.h>

#include<string.h>

#include<conio.h>

int main()

char str1[20];

clrscr();

printf("\n*Enter the first string : ");

scanf("%s",str1);

strrev(str1);

printf("*Reversed name is:%s",str1);

getch();

}
OUTPUT
Practical No:4

 Write a c program to check whether a given string is


Palindrome or not?
INPUT
#include <stdio.h>

#include<string.h>

#include<conio.h>

int main()

char str1[20],str2[20];

printf("\n*Enter the first string : ");

scanf("%s",str1);

strcpy(str2,str1);

strrev(str2);

if(strcmp(str2,str1)==0)

printf("*String is Palindrome");

else

printf("*String is not Palindrome");

getch();

}
OUTPUT
Practical No:5

 Write a c program to illustrate the assignment of


complete structure?
INPUT
#include<stdio.h>

#include<conio.h>

main()

struct student

int roll;

char name[20];

int age;

char Std[8];

};

struct student s1={1001,"Vikas",18,"CIC"};

struct student s2;

clrscr();

s2=s1;

printf("\n*ASSIGNED VALUES ARE:*\n");


printf("Roll no. :%d\n",s2.roll);

printf("Name :%s\n",s2.name);

printf("Age :%d\n",s2.age);

printf("Class :%s\n",s2.Std);

getch();

}
OUTPUT
Practical No:6

 Write a c program to read the roll,name,marks of the


n students in a class & find the average marks of the
class?
INPUT
#include <stdio.h>

#include<string.h>

#include<conio.h>

struct student

int roll,marks;

char name[50];

main()

struct student s[10];

int i,t,avg=0;

int n;

clrscr();

printf("\n*How many record you want to enter*\n");


printf("*Total number of records are=");

scanf("%d",&n);

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

printf("\n*enter the deatils of roll number=%d",i);

printf("\n*enter name:-");

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

printf("*enter marks:-");

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

for(i=1,t=0;i<=n;i++)

t=t+s[i].marks;

printf("\n*Total marks are=%d",t);

avg=t/2;

printf("\n*Average of marks is=%d",avg);

getch();

}
OUTPUT
Practical No:7

 Write a c program to illustrate returning a value of


structure type via return statement?
INPUT
#include<stdio.h>

#include<conio.h>

struct student

int roll;

char name[20];

int age;

};

struct student read_data()

struct student s;

printf("\n*ENTER THE STUDENT RECORD*\n");

printf("#Roll no.:");

scanf("%d",&s.roll);

printf("#Name:");

scanf("%s",s.name);
printf("#Age:");

scanf("%d",&s.age);

return s;

main()

struct student st;

struct student read_data();

clrscr();

st=read_data();

printf("\n*RECORD DEATILS ARE*\n");

printf("#Roll no.:%d\n",st.roll);

printf("#Name:%s\n",st.name);

printf("#Age:%d\n",st.age);

getch();

}
OUTPUT
Practical No:8

 Write a c program to illustrate passing of structure


variable using call by value?
INPUT
#include <stdio.h>

#include <string.h>

#include <conio.h>

struct student

int id;

char name[20];

float percentage;

};

void func(struct student record);

int main()

struct student record;

clrscr();

printf("\n");

record.id=1;
strcpy(record.name, "Mansi");

record.percentage = 86.5;

func(record);

getch();

void func(struct student record)

printf(" Id is: %d \n", record.id);

printf(" Name is: %s \n", record.name);

printf(" Percentage is: %f \n", record.percentage);

}
OUTPUT
Practical No:9

 Write a c program to illustrate passing of structure


variable using call by reference?
INPUT
#include <stdio.h>

#include <string.h>

#include<conio.h>

struct student

int id;

char name[20];

float percentage;

};

void func(struct student *record);

int main()

struct student record;

clrscr();

printf("\n");

record.id=1;
strcpy(record.name, "Gunnu");

record.percentage = 86.5;

func(&record);

getch();

void func(struct student *record)

printf(" Id is: %d \n", record->id);

printf(" Name is: %s \n", record->name);

printf(" Percentage is: %f \n", record->percentage);

}
OUTPUT
Practical No:10

 Write a c program to illustrate the concept of


pointers & structure?
INPUT
#include <stdio.h>

#include <conio.h>

struct person

int age,weight;

};

int main()

struct person *personPtr, person1;


personPtr = &person1;
clrscr();
printf("\n*Enter age: ");
scanf("%d", &personPtr->age);
printf("*Enter weight: ");
scanf("%d", &personPtr->weight);
printf("\n*Displaying*\n");
printf("*Age: %d\n", personPtr->age);
printf("*weight: %d", personPtr->weight);
getch();

OUTPUT
Practical No:11

 Write a c program that output the value of a variable


using pointer?
INPUT
#include<stdio.h>

#include<conio.h>

main()

int alpha;

int *beta;

clrscr();

alpha=1;

beta= &alpha;

printf("\n");

printf("The value %d is stored at address%d\n",alpha, &alpha);

printf("The value %d is stored at address%d\n",beta, &beta);

printf("The value %d is stored at address%d\n",*beta, beta);

getch();

}
OUTPUT

You might also like