Professional Documents
Culture Documents
#include <stdio.h>
int main()
{
int A[3][3]; // Matrix 1
int B[3][3]; // Matrix 2
int C[3][3]; // Resultant matrix
C[row][col] = sum;
}
}
return 0;
}
//Write a program to find transpose of 3 x 3 matrix.
#include<stdio.h>
#include<conio.h>
void main(){
int a[3][3],t[3][3];
int i, j;
clrscr();
for(i=0;i<3;i++){
for(j=0;j<3;j++){
printf("Enter value");
scanf("%d",&a[i][j]);
}
}
printf("The elements of the matrix are:\n");
for(i=0;i<3;i++){
for(j=0;j<3;j++) {
printf("%d\t",a[i][j]);
}
printf("\n");
}
for(i=0;i<3;i++){
for(j=0;j<3;j++) {
t[j][i]=a[i][j];
}
}
printf("The transpose matrix is: \n");
for(i=0;i<3;i++){
for(j=0;j<3;j++) {
printf("%d\t",t[i][j]);
}
printf("\n");
}
getch();
}
/*Write a program to declare structure student having member variables are roll-no, name and marks.
Accept data for one student and display it.*/
(Logic - 2 Marks, Syntax – 2 Marks)
Ans: #include<stdio.h>
#include<conio.h>
struct student
{
int roll_no;
char name[20];
float marks;
}s;
void main()
{
clrscr();
printf("Enter student's roll number:");
scanf("%d",&s.roll_no);
printf("\nEnter student's name:");
scanf("%s",s.name);
printf("\nEnter student's marks:");
scanf("%f",&s.marks);
printf("\n\nStudent's details are:");
printf("\nRoll number=%d",s.roll_no);
printf("\nName=%s",s.name);
printf("\nMarks=%f",s.marks);
getch();
}
/*Write a program to declare a structure book having data members, title, author and
price. Accept data and display information for one book.
(Logic – 2 Marks, Syntax-2 Marks) */
#include<stdio.h>
#include<conio.h>
struct book
{
char tit[20];
charauth[20];
int price;
}b1;
void main()
{
printf("enter title of book");
scanf("%s",b1.tit);
printf("enter author name of book");
scanf("%s",b1.auth);
printf("enter price of book");
scanf("%d",&b1.price);
printf("detdails of book are");
printf("\n\t title:%s\n\t author:%s\n\t price:%d",b1.tit,b1.auth,b1.price);
getch();
}
Write a program to find simple interest using structure.
(Logic – 2 Marks, Syntax-2 Marks)
#include<stdio.h>
#include<conio.h>
void main()
{
struct Simple_Interest
{
float p,r,t,si;
}s;
clrscr();
printf("Enter principal amount ");
scanf("%f",&s.p);
printf("Enter rate of interest ");
scanf("%f",&s.r);
printf("Enter time ");
scanf("%f",&s.t);
s.si=(s.p*s.r*s.t)/100;
printf("Simple Interest = %f",s.si);
getch();
}
/*Write a program to declare a structure employee having name, designation and salary.
Accept and display this information for five members.*/
#include<stdio.h>
#include<conio.h>
struct employee
{
char ename[20];
char desg[20];
int salary;
}s[5];
void main()
{
int i;
clrscr();
//Accepting information
printf("Enter details of 5 employees:\n");
for(i=0;i<5;i++)
{
printf("Enter name :");
scanf("%s",s[i].ename);
printf("Enter designation :");
scanf("%s",s[i].desg);
printf("Enter salary :");
scanf("%d",&s[i].salary);
}
//displaying information
printf("The details of emplyoees are :\n");
for(i=0;i<5;i++)
{
printf("%s\t%s\t%d",s[i].ename,s[i].desg,s[i].salary);
printf("\n--------------------\n");
}
}