0% found this document useful (0 votes)
23 views

Programs

Uploaded by

tunoob10
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)
23 views

Programs

Uploaded by

tunoob10
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/ 50

Fundamental of Programming

By

Dr. Kiran Patel


Assistant Professor, LDRP-ITR

B.E , M.S (Uni. of Bridgeport –USA)


PhD

Prepared by: Dr. Kiran Patel


1. Write a program to print your address.

#include <stdio.h>
#include <conio.h>
main()
{
printf("\n\n MY JOB ADDRESS IS");
printf("\n------------------------------------------------");
printf("\n\n L.D.R.P.-ITR,\n Gandhinagar.");
printf("\n------------------------------------------------");
}

Prepared by: Dr. Kiran Patel


2. Write a program to perform average of five variables.

#include<stdio.h>
#include<conio.h>
main()
{
int a,b,c,d,e;
float avg;
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);
}

Prepared by: Dr. Kiran Patel


3. Write a program to print area of circle and rectangle.

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

Prepared by: Dr. Kiran Patel


4. Write a program to convert years into minutes.

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

Prepared by: Dr. Kiran Patel


5. Write a program to perform all the arithmetic operations
together in a single program.
#include<stdio.h>
#include<conio.h>
main()
{
float no1,no2,sum,mul,sub,div;
printf("\n ENTER THE NO1:====>");
scanf("%f",&no1);
printf("\n ENTER THE NO2:====>");
scanf("%f",&no2);
sum=no1+no2;
mul=no1*no2;
sub=no1-no2;
div=no1/no2;
printf("\n\n ADDITION OF TWO NUMBERS:===>%f",sum);
printf("\n\n SUBTRACTION OF TWO NUMBERS:===>%f",sub);
printf("\n\n MULTIPLICATION OF TWO NUMBERS:===>%f",mul);
printf("\n\n DIVISION OF TWO NUMBERS:===>%f",div);
} Prepared by: Dr. Kiran Patel
6. Write a program to print a character entered by user.

#include<stdio.h>
#include<conio.h>
main()
{
char ch;
printf(""\n\nEnter the Character:==>"");
scanf(""%c"",&ch);
printf("Entered Character Is:==>%c",ch);
}

Prepared by: Dr. Kiran Patel


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

#include<stdio.h>
#include<conio.h>
main()
{
char lowerChar, upperChar;
int ascii;
printf("Enter a lowercase Character: ");
scanf("%c", &lowerChar);
ascii = lowerChar;
upperChar = ascii-32;
printf("\nIts Uppercase = %c", upperChar);
}
Prepared by: Dr. Kiran Patel
8. Write a program to swap the values of two variables using
third variable.
#include<stdio.h>
#include<conio.h>
main()
{ int a,b,temp;
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);
}
Prepared by: Dr. Kiran Patel
9. Write a program to swap the values of two variables
without using third variable.

#include<stdio.h>
#include<conio.h>
main() {
int a,b;
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);
} Prepared by: Dr. Kiran Patel
10.Write a program to find maximum and minimum numbers from two
numbers by using conditional operator.
#include<stdio.h>
#include<conio.h>
main()
{
int a,b;
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);
} Prepared by: Dr. Kiran Patel
11. Write a program to demonstrate bitwise operator.
#include<stdio.h>
#include<conio.h>
main() {
int a = 5, b = 9; // a = 5(00000101), b = 9(00001001)
// 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); } Prepared by: Dr. Kiran Patel
12. Write a program to check whether the entered number
is odd or even by using if else statement.

#include <stdio.h>
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);
} Prepared by: Dr. Kiran Patel
13. Write a program to check whether entered character is
alphabet, digit or special symbol.
#include <stdio.h>
main()
{
char ch;
printf("Enter any character: ");
scanf("%c", &ch);
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);
}
} Prepared by: Dr. Kiran Patel
14. Write a program to find whether entered year is
leap year or not.
#include <stdio.h>
main()
{
int year;
printf("Enter a year: ");
scanf("%d", &year);
if (year % 4 == 0)
{
if (year % 100 == 0)
{
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);
}
Prepared by: Dr. Kiran Patel
15. Write a program to check how many days are there in
entered month by using switch case.
#include <stdio.h>
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 7: printf("31 days"); break;
case 8: printf("31 days"); break;
case 9: printf("30 days"); break;
case 10: printf("31 days"); break;
case 11: printf("30 days"); break;
case 12: printf("31 days"); break;
default:
printf("Invalid input! Please enter month number between 1-12");
} } Prepared by: Dr. Kiran Patel
16. Write a program to check whether entered character is
vowel or consonant by using switch case.
#include <stdio.h>
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)
{ printf("%c is a VOWEL",ch);
case 'A': break;
case 'E': default:
case 'I': printf("%c is a CONSONANT",ch);
case 'O': }
case 'U': }
case 'a': else
case 'e': {
case 'i': printf("%c is not an alphabet",ch);
case 'o': }
case 'u‘: } Prepared by: Dr. Kiran Patel
17. Write a program to get maximum number among three.
#include <stdio.h>
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");
Prepared by: Dr. Kiran Patel
} Prepared by: Dr. Kiran Patel
18. Write a program to print first 10 integers by using go to
statement.

#include <stdio.h>
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;
} Prepared by: Dr. Kiran Patel
19. Write a program to print addition of first n numbers by
using go to statement.
#include <stdio.h>
#include<conio.h>
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);
} Prepared by: Dr. Kiran Patel
20. Write a program to find reverse of given numbers.
(For example 132-231)

#include <stdio.h>
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);
} Prepared by: Dr. Kiran Patel
21. Write a program to check whether entered number is
Armstrong or not.
#include <stdio.h>
// 3**3 + 7**3 + 1**3 = 371
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);
} Prepared by: Dr. Kiran Patel
22. Write a program to check whether entered number is
palindrome or not.
#include <stdio.h>
// Same when u read Forward and Backward
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);
} Prepared by: Dr. Kiran Patel
23. Write a program to print factorial of a given number.

#include <stdio.h>
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);
}
}
Prepared by: Dr. Kiran Patel
24. Write a program to check whether entered number is
#include <stdio.h>
prime or not.
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);
}
} Prepared by: Dr. Kiran Patel
25. 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");
}
Prepared by: Dr. Kiran Patel
}
1
22
333
#include<stdio.h> 4444
main() 55555
{
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");
}
} Prepared by: Dr. Kiran Patel
*****
****
#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");
} Prepared by: Dr. Kiran Patel
}
1
#include<stdio.h>
main()
12
{ 123
int i,j,k,n; 1234
printf("Enter the value of N:");
scanf("%d",&n); 12345
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");
}
}
Prepared by: Dr. Kiran Patel
*
#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");
}
Prepared by: Dr. Kiran Patel
}
27. 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]);
}

}
Prepared by: Dr. Kiran Patel
27. 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]);
}

}
Prepared by: Dr. Kiran Patel
28. 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);
}
Prepared by: Dr. Kiran Patel
29. 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);
Prepared by: Dr. Kiran Patel
}
30. Write a program to find number of positive, negative and zero from given array.

#include<stdio.h>
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);
Prepared by: Dr. Kiran Patel
}
31. 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);
Prepared by: Dr. Kiran Patel
}
32. 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");
for(i=0;i<n;i++)
{ printf("%d\n",a[i]);
} } Prepared by: Dr. Kiran Patel
33. Write a program to read matrix, display original and transpose of matrix.

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

Prepared by: Dr. Kiran Patel


34. 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);
//concatenate String
strcat(name1,name2);
// Copy string
printf("\n\nAfter concatenate name1 and
strcpy(name2,name1);
name2");
printf("\n\nAfter coping name1 into name2");
printf("\nName 1 is ==>%s",name1);
printf("\nName 1 is ==>%s",name1);
printf("\nName 2 is ==>%s",name2);
printf("\nName 2 is ==>%s",name2);
//length of string
// reverse String
len=strlen(name1);
strrev(name2);
printf("\n\nLength of '%s' is
printf("\n\nAfter reverse name2");
==>%d",name1,len);
printf("\nName 2 is ==>%s",name2);
return 0;
Prepared by: Dr. Kiran Patel
}
35. 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;
}

Prepared by: Dr. Kiran Patel


36. 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;
}

Prepared by: Dr. Kiran Patel


37. 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;
}
Prepared by: Dr. Kiran Patel
38. 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;
} Prepared by: Dr. Kiran Patel
39. 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;
}
Prepared by: Dr. Kiran Patel
40. Write a user defined function (UDF) to print whether
#include<stdio.h> entered number is odd or even.
#include<conio.h>
void oddeven(int);
void main()
{
int n;
printf("\n Enter number::");
scanf("%d",&n);
oddeven(n);
}
void oddeven(int n)
{
if(n%2==0)
{
printf("\n Even number...");
}
else
{
printf("\n Odd number...");
}
}
Prepared by: Dr. Kiran Patel
41. 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;
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);
}
int sum(int num)
{
int add=0;
while(num!=0)
{
add=add+num;
num--;
}
return add;
Prepared by: Dr. Kiran Patel
}
42. 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;
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);
}
float average(num) {
int add=0,oldn=num;
float avg;
while(num!=0)
{
add=add+num;
num--; }
avg=(float)add/oldn;
return avg; Prepared by: Dr. Kiran Patel
}
43. Write a program using structure to get name, roll number, and
marks of a student’s of a class and find out who got highest marks.
#include<stdio.h>
#include<conio.h> if(s[i].marks>max)
struct student {
{ max=s[i].marks;
int roll,marks; r=i;
char name[10]; }
}; }
void main() printf("\n Details of student having
{ maximum marks is:\nName: %s \nRoll no:
struct student s[3]; %d\n Marks:
int max=0,i,r; %d",s[r].name,s[r].roll,s[r].marks);
clrscr(); getch();
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);
Prepared by: Dr. Kiran Patel
44. Write a program to enter the details (Name, Employee_id, Salary)
of employees using the concept of structure within structure.
#include<stdio.h>
#include<conio.h>
struct employee
{
int id; scanf("%s",emp.name);
char name[10]; printf("\n Employee id:");
struct salary scanf("%d",&emp.id);
{ printf("\n Basic and DA::");
int basic,DA; scanf("%d \n %d",&emp.sal.basic,&emp.sal.DA);
}sal; total=emp.sal.basic+emp.sal.DA;
}emp; printf("\n Total salary is %d",total);
void main() getch();
{ }
int total;
printf("\n *** Details of Employee ***");
printf("\n Name of employee:");

Prepared by: Dr. Kiran Patel


45. 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 of struct and function.
#include<stdio.h>
#include<conio.h>
#include<string.h>
struct Member
{
int salary; struct Member get_data(struct Member mem)
char name[10]; {
}; printf("\n Enter Member name:");
struct Member get_data(struct Member mem); scanf("%s",mem.name);
void print_data(struct Member mem); printf("\n Enter salary:");
void main() scanf("%d",&mem.salary);
{ return mem;
struct Member mem,mem_new; }
clrscr(); void print_data(struct Member mem)
printf("\n *** Details of member ***"); {
mem_new=get_data(mem); printf("\n Member having name %s
print_data(mem_new); got %d salary...",mem.name,mem.salary);
getch(); }
}
Prepared by: Dr. Kiran Patel

You might also like