C Program using Typedef and Structure
Top C Program for Typedef data type
C Program for Typedef Data Type and Using Structure
C Program to print sum of number using typedef.
#include <stdio.h>
#include<conio.h>
void main()
{
typedef int number ;
number n1=15, n2=20;
int add = n1 + n2;
printf("%d", add);
getch();
}
Output:
Sum=35
C Program to print the value using typedef.
#include <stdio.h>
#include <conio.h>
void main()
{
typedef int num;
num i,j;
i=30;
j=50;
printf("Value of i is :%d",i);
printf("\nValue of j is :%d",j);
getch();
}
Output:
Value of i is :30
Value of j is :50
C Program to print the array list using typedef
#include <stdio.h>
#include <conio.h>
typedef int array[5];
int main()
{
array temp = {10, 20, 30, 40,50};
printf("typedef using an
array\n");
for (int i = 0; i < 4;
i++)
{
printf("%d ",
temp[i]);
}
return 0;
}
Output:
Display array list using
typedef
10 20 30 40
C Program to store the name, age,
height and weight using structure and typedef function.
#include <stdio.h>
#include <conio.h>
typedef struct student
{
char name[20];
int age;
int height;
int weight;
} std;
void main()
{
std std1;
printf("Enter the details of student : ");
printf("\nEnter the name of the student:");
scanf("%s",& std1.name);
printf("\nEnter the age of student:");
scanf("%d",& std1.age);
printf("\nEnter the height of the student:");
scanf("%s",& std1.height);
printf("\nEnter the weight of the student:");
scanf("%s",& std1.weight);
printf("\n Name of the student is : %s", std1.name);
printf("\n Age of the student is : %d", std1.age);
printf("\n Name of the student is : %s", std1.
height);
printf("\n Age of the student is : %d", std1.
weight);
getch();
}
Output:-
Enter the details of student
:
Enter the name of the
student: Aman
Enter the age of student:12
Enter the height of the
student:23
Enter the weight of the
student:24
Name of the student is : Aman
Age of the student is : 12
C Program to store the
student record using structure and typedef function.
#include <stdio.h>
#include <conio.h>
#include <string.h>
typedef struct student
{
int rollno;
char name[30];
int phone_no;
}std;
void main()
{
std p1, p2, p3;
p1.rollno = 1;
strcpy(p1.name,"Ram");
p1.phone_no = 9623443; p2.rollno = 2;
strcpy(p2.name,"Shyam");
p2.phone_no = 934567822;
p3.rollno = 3;
strcpy(p3.name,"Krishna");
p3.phone_no = 934567844;
printf("First Student\n");
printf("Roll No : %d\n", p1.rollno);
printf("name : %s\n", p1.name);
printf("phone_number : %d\n", p1.phone_no);
printf("Second Student\n"); printf("Roll_No : %d\n",
p2.rollno);
printf("name : %s\n", p2.name);
printf("phone_number : %d\n", p2.phone_no);
printf("Third Student\n");
printf("Roll_No : %d\n", p3.rollno);
printf("name : %s\n", p3.name);
printf("phone_number : %d\n", p3.phone_no);
getch();
}
Output:
First Student
Roll No : 1
name : Ram
phone_number : 9623443
Second Student
Roll_No : 2
name : Shyam
phone_number : 934567822
Third Student
Roll_No : 3
name : Krishna
phone_number : 934567844
C program to implement using #define function.
#include <stdio.h>
#include<conio.h>
#define N 3
void main()
{
for (int i = 0; i < N; i++)
{
printf("The number is %d \n", i);
}
getch();
}
Output:
The number is 0
The number is 1
The number is 2
Introduction to C Language
Top C Program for Typedef data type |
C Program for Typedef Data Type and Using Structure |
C Program to print sum of number using typedef. |
#include <stdio.h> #include<conio.h> void main() { typedef int number ; number n1=15, n2=20; int add = n1 + n2; printf("%d", add); getch(); }
|
Output: Sum=35 |
C Program to print the value using typedef. |
#include <stdio.h> #include <conio.h>
void main() { typedef int num; num i,j; i=30; j=50; printf("Value of i is :%d",i); printf("\nValue of j is :%d",j); getch(); }
|
Output: Value of i is :30 Value of j is :50 |
C Program to print the array list using typedef |
#include <stdio.h> #include <conio.h>
typedef int array[5]; int main() { array temp = {10, 20, 30, 40,50}; printf("typedef using an
array\n"); for (int i = 0; i < 4;
i++) { printf("%d ",
temp[i]); } return 0; } |
Output: Display array list using
typedef 10 20 30 40 |
C Program to store the name, age,
height and weight using structure and typedef function. |
#include <stdio.h> #include <conio.h>
typedef struct student { char name[20]; int age; int height; int weight; } std;
void main() { std std1; printf("Enter the details of student : "); printf("\nEnter the name of the student:"); scanf("%s",& std1.name); printf("\nEnter the age of student:"); scanf("%d",& std1.age); printf("\nEnter the height of the student:"); scanf("%s",& std1.height); printf("\nEnter the weight of the student:"); scanf("%s",& std1.weight); printf("\n Name of the student is : %s", std1.name); printf("\n Age of the student is : %d", std1.age); printf("\n Name of the student is : %s", std1.
height); printf("\n Age of the student is : %d", std1.
weight);
getch(); }
|
Output:- Enter the details of student
: Enter the name of the
student: Aman Enter the age of student:12 Enter the height of the student:23 Enter the weight of the student:24 Name of the student is : Aman Age of the student is : 12 |
C Program to store the
student record using structure and typedef function. |
#include <stdio.h> #include <conio.h> #include <string.h>
typedef struct student { int rollno; char name[30]; int phone_no; }std;
void main() { std p1, p2, p3;
p1.rollno = 1; strcpy(p1.name,"Ram");
p1.phone_no = 9623443; p2.rollno = 2; strcpy(p2.name,"Shyam"); p2.phone_no = 934567822; p3.rollno = 3; strcpy(p3.name,"Krishna"); p3.phone_no = 934567844; printf("First Student\n"); printf("Roll No : %d\n", p1.rollno); printf("name : %s\n", p1.name); printf("phone_number : %d\n", p1.phone_no); printf("Second Student\n"); printf("Roll_No : %d\n",
p2.rollno); printf("name : %s\n", p2.name);
printf("phone_number : %d\n", p2.phone_no); printf("Third Student\n"); printf("Roll_No : %d\n", p3.rollno); printf("name : %s\n", p3.name);
printf("phone_number : %d\n", p3.phone_no); getch(); } |
Output: First Student Roll No : 1 name : Ram phone_number : 9623443 Second Student Roll_No : 2 name : Shyam phone_number : 934567822 Third Student Roll_No : 3 name : Krishna phone_number : 934567844
|
C program to implement using #define function. |
#include <stdio.h> #include<conio.h> #define N 3
void main() { for (int i = 0; i < N; i++) { printf("The number is %d \n", i); } getch(); }
|
Output: The number is 0 The number is 1 The number is 2 |
Comments
Post a Comment