Sunteți pe pagina 1din 7

Ans1 :-

#include<stdio.h>
#include<conio.h>
void main()
{
struct studentrecord
{
Char name[30];
int rollno;
int marks[5];
struct dateofbirth
{
int date;
char month[10];
int year;
}dob;
}student[5];

Ans2:-

#include<stdio.h>
#include<conio.h>
void main()
{
struct student record
{
char name[30];
int rollno;
int marks[5];
struct date of birth
{
int date;
char month[10];
int year;
}dob;
}student[5],*ptr;
int i,j;
clrscr();
for(i=1;i<=5;i++)
{
printf("\n\nEnter the name of %d student : ", i);
scanf("%s",&ptr->name);
printf("\n\nEnter the roll number : ");
scanf("%d",&ptr->rollno);
printf("\n\nEnter the marks : ");
for(j=1;j<=5;j++)
{
scanf("%d",&ptr->marks[j]);
}
printf("\n\nEnter the DOB (day_month _name-year): ");
scanf("%d%s%d",&ptr->dob.date,&ptr->dob.month,&ptr->dob.year);
printf("\n\n STUDENT RECORD");
printf("\n\n NAME = %s", ptr->name);
printf("\n\n ROLL NUMBER = %d", ptr->rollno);
printf("\n\n MARKS IN 5 SUBJECTS : ");
for(j=1;j<=5;j++)
{
printf("\n%d",ptr->marks[j]);
}
printf("\n\nDATE OF BIRTH = %d %s %d",ptr->dob.date,ptr->dob.month,ptr-
>dob.year);
}
getch();
}

Ans3:

SOLUTION IN STRUCTURE FORM


#include<stdio.h>
#include<conio.h>
void main()
{
struct book1
{
char book[30];
int pages;
float price;
};
struct book1 bk1;
clrscr();
printf("\n\nSize of elements");
printf("\n\nBook : %d",sizeof(bk1.book));
printf("\n\nPages : %d",sizeof(bk1.pages));
printf("\n\nPrice : %d",sizeof(bk1.price));
printf("\n\nTotal Bytes :%d",sizeof(bk1));
getch();
}

SOLUTION IN UNION FORM


#include<stdio.h>
#include<conio.h>
void main()
{
union result
{
int marks;
char grade;
};
struct res
{
char name[15];
int age;
union result perf;
}data;
clrscr();
printf("\n\nSize of union : %d\n",sizeof(data.perf));
printf("\n\nSize of structure : %d\n",sizeof(data));
getch();
}
Ans5:-
#include<stdio.h>
#include<conio.h>
void main()
{
void concatenate();
void copy();
void compare();
int choice;
clrscr();
printf("\n\nEnter your choice for the following function : ");
printf("\n1. To concatenate " );
printf("\n2. To copy ");
printf("\n3. To compare");
scanf("%d",&choice);
if(choice==1)
{
concatenate();
}
if(choice==2)
{
copy();
}
if(choice==3)
{
compare();
}
getch();
}
void concatenate()
{
struct concat
{
char str1[50],str2[50];
}var1;
printf("\n\nEnter the first string : ");
gets(var1.str1);
printf("\n\nEnter the second string : ");
gets(var1.str2);
printf("\n\nThe concatenated string is : %s %s ",var1.str1,var1.str2);
getch();
}
void copy()
{
struct copy
{
char str1[50],str2[50];
int ch;
}var1;
printf("\n\nEnter the first string : ");
gets(var1.str1);
printf("\n\nEnter the second string : ");
gets(var1.str2);
printf("\n\nWant to copy\n 1.first to second \n 2.second to first : ");
scanf("\n\n%d",&var1.ch);
if (var1.ch==1)
{
printf("\n\nThe copied string is : ");
puts(var1.str1);
}
else if (var1.ch==2)
{
printf("\n\nThe copied string is : ");
puts(var1.str2);
}
}
void compare()
{
int i,j;
char str1[25],str2[25];
printf("\n\nEnter the first string (max 25 characters): ");
for(i=0;i<25;i++)
{
str1[i]=getchar();
}
printf("\n\nEnter the second string : ");
for(j=0;j<25;j++)
{
str2[j]=getchar();
}
for(i=0,j=0;i<25,j<25;i++,j++)
{
if
(str1[i]==str2[j])
{
printf("\n\nThe strings are same");
break;
}
else
{
printf("\n\nNot Same");
}
}
}

Ans6:-

#include<stdio.h>
#include<conio.h>
int fact1[5];
void main()
{
void factorial();
void display();
clrscr();
factorial();
display();
getch();
}
void factorial()
{
int i,j,fact=1;
for(i=1;i<=5;i++)
{
fact=1;
for(j=1;j<=i;j++)
{
fact=fact*j;
}
fact1[i]=fact;
}
}
void display()
{
int i;
for(i=1;i<=5;i++)
{
printf("\nThe factorial of %d is = %d",i,fact1[i]);
}
}

S-ar putea să vă placă și