Include (Autosaved)
Include (Autosaved)
System.
Function
Page | 1
16. Write a program to sum N natural number?
21. Write a c program using the function power (a, b) to calculate the
value raised to b?
26. Create a structure student having data member to store roll number, name
of student, name of three subject, maximum mark, minimum mark, obtain
marks declare array of student provide facility to display result of all student
and specific student where roll number is given?
Page | 2
27. Create structure student having data with data member DD,
MM, YY (to store data) create another structure employee with
data member to hold the name of employee, employee id and
date of joining ( date of joining will be hold by variable of
structure date with appear date member in employee structure)
store of an employee and print the same?
28. Define union employee having data member one integer, one
float and single dimensional character array. Declare a union
variable main and text variable?
Page | 3
PROGRAM:- 1 Write a program to print combination of 123?
SOLUTION:-
FLOW CHART
start
int i,j,k;
for(i=1;i<3;i++)
for(j=1;j<=3;j++)
for(k=1;k<=3;k++)
if(i!=j&&i!
=k&&j!=k)
printf("%d%d%d",i,j,k);
printf("\n");
end
Page | 4
CODING:-
#include<stdio.h>
#include<conio.h>
void main()
{
int i,j,k;
clrscr();
for(i=1;i<3;i++)
{
for(j=1;j<=3;j++)
{
for(k=1;k<=3;k++)
{
if(i!=j&&i!=k&&j!=k)
{
printf("%d%d%d",i,j,k);
printf("\n");
}
}
}
getch();
OUTPUT:-
Page | 5
PROGRAM:-2 Write program to generate following pattern? (B)
*
**
***
**** start
*****
SOLUTION:-
FLOW CHART int i,j,k;
for(i=1;i<=5;i++)
for(k=5;k>i;k--)
printf(" ");
for(j=1;j<=i;j++)
printf("*");
printf("\n");
end
Page | 6
CODING:-
#include<stdio.h>
#include<conio.h>
void main()
{
int i,j,k;
clrscr();
for(i=1;i<=5;i++)
{
for(k=5;k>i;k--)
{
printf(" ");
}
for(j=1;j<=i;j++)
{
printf("*");
}
printf("\n");
}
getch();
}
OUTPUT:-
Page | 7
PROGRAM:- 2 Write program to generate following pattern? (D)
FLOWCHART
start
int i,j,k;
for(i=1;i<=4;i++)
for(j=1;j<=4-i;j++)
printf(" ");
for(j=i;j>=1;j--)
printf("%d",j);
for(j=2;j<=i;j++)
printf("\n");
end
Page | 8
CODING:-
#include<stdio.h>
#include<conio.h>
void main()
{
clrscr();
int i,j,k;
for(i=1;i<=4;i++)
{
for(j=1;j<=4-i;j++)
{
printf(" ");
}
for(j=i;j>=1;j--)
{
printf("%d",j);
}
for(j=2;j<=i;j++)
{
printf("%d",j);
}
printf("\n");
}
getch();
}
OUTPUT:-
Page | 9
PROGRAM:- 3 Write program to display 1 to 10 in octal, decimal and hexadecimal
System.
FLOWCHART
start
int i;
for(i=1;i<=10;i++)
printf("%0 ",i);
for(i=1;i<=10;i++)
printf("%d",i);
for(i=1;i<=10;i++)
printf("%x",i);
end
Page | 10
CODING:-
#include<stdio.h>
#include<conio.h>
void main()
{
int i;
clrscr();
printf("Value from 1 to 10 in octal format: \n");
for(i=1;i<=10;i++)
{
printf("%0 ",i);
}
printf("\n Value from 1 to 10 in decimal format: \n");
for(i=1;i<=10;i++)
{
printf("%d",i);
}
printf("\n Value from 1 to 10 in hexadecimal format: \n");
for(i=1;i<=10;i++)
{
printf("%x",i);
}
getch();
}
OUTPUT:-
Page | 11
PROGRAM:- 4 Create a single program to perform following tasks using switch if else…..loop and single
dimension character array without using library Function
FLOWCHART:- start
int temp,i;
char str[30],len;
gets(str);
len=strlen(str);
for(i=0;i<=len/2;i++)
temp=str[i];
str[i]=str[len-1-i];
str[len-1-i]=temp;
end
Page | 12
CODING:-
#include<stdio.h>
#include<conio.h>
#include<string.h>
void main()
{
clrscr();
int temp,i;
char str[30],len;
printf("Enter The String:");
gets(str);
len=strlen(str);
for(i=0;i<=len/2;i++)
{
temp=str[i];
str[i]=str[len-1-i];
str[len-1-i]=temp;
}
printf("Reverse String is:%s", str);
{
getch();
}
}
OUTPUT:-
Page | 13
PROGRAM:-5 write a program to perform arithmetic operation in C- language?
SOLUTION:-
FLOW CHART
Start
Input a, b, c, d, e, f, g
C=a+b
C=a-b
C=a*b
C=a/b
C=a%b
Print addition
Print subtraction
Page | 14
Print multiplication
Print division
End
Page | 15
CODING: -#include<stdio.h>
#include<conio.h>
Void main()
{
int a, b, c, d, e, f, g;
clrscr();
printf(“\n enter the two number=”);
scanf(“%d %d”,&a, &b);
c = a+b;
d = a-b;
e = a*b;
f = a/b;
g = a%b;
printf(“\n addition = %d”,c);
printf(“\n %d substraction = %d”,d);
printf(“\n %d multiplication = %d”,e);
printf(“\n %d division = %d”, f);
printf(“\n %d modular = %d,g);
getch();
}
OUTPUT:-
Page | 16
PROGRAM:- 6 Write a program to calculate simple interest and compound interest?
SOLUTION:-
FLOW CHART:-
Start
Input p
Input r
Input t
Si= p*r*t/100
Ci = p*(pow(1+r/100),t)
End
Page | 17
CODING:- #include<stdio.h>
#include<conio.h>
#include<math.h>
Void main()
{
Int p, t, r;
Float si, ci;
Clrscr();
Printf(“\n enter the principal =”);
Scanf(“%d ”,&p);
Printf(“\n enter the rate =”);
Scanf(“%d”,&r);
Printf(“\n enter the time =”);
Scanf(“%d”,&t);
Si = (p*r*t)/100;
Printf(“\n simple interest is %f”,si);
Ci = p*(pow((1=r/100),t));
Printf(“\n compound interest is %f”, ci);
getch();
}
OUTPUT:-
Page | 18
PROGRAM:- 7 write a program to generate following pattern?
1
22
333
4444
55555
1
11
111
1111
11111
SOLUTION:-
FLOW CHART:- start
Print pattern
For (a=1;b<=5;b++)
Print a
N=1
Page | 19
For (a=1; a<=5; a++
Print n
End
Page | 20
CODIND:- #include<stdio.h>
#include<conio.h>
Void main()
{
int a,b,n;
clrscr();
printf(“\n print the first pattern”);
for( a=1; a<=5; a++)
{
Printf(“\n”);
For( b=1; b<=5; b++)
{
Printf(“ %d”,a);
}
}
Printf(“\n print the second pattern”);
N = 1;
for ( a=1; a<=5; a++)
{
Printf(“\n”);
For ( b=1; b<=a; b++)
{
Printf(“%d”, n);
}
}
getch();
}
OUTPUT:-
Page | 21
PROGRAM:- 8 Write a program to generate following pattern?
*****
****
***
**
*
*
**
***
****
*****
SOLUTION:-
FLOW CHART Start
Print pattern
Print \n
Print *
Page | 22
End
CODING: - #include<stdio.h>
#include<conio.h>
Void main()
{
int a,b;
clrscr();
printf(“\n print the first pattern”);
for( a=1; a<=5; a++)
{
Printf(“\n”);
For( b=a; b<=5; b++)
{
Printf(“\n”);
}
}
Printf(“\n print the second pattern);
For ( a=1; a<=5; a++)
{
Printf(“\n”);
For( b=1; b<=a; b++)
{
Printf(“*”);
}
}
getch();
}
OUTPUT:-
Page | 23
PROGRAM:- 9 Write a program to calculate area of circle and circumference?
SOLUTION:-
FLOW CHART:-
Start
Input r
Area(22/7)*r*r
Cir = 2*(22/7)*r
Print circumference of
circle
End
Page | 24
CODING: - #include<stdio.h>
#include<conio.h>
Void main()
{
Float area, cir, r;
Clrscr();
Printf(“\n input radius value of circle \n”);
Scanf(“%f”,&r);
Area=(22/7)*r*r;
Printf(“ area of circle =%f \n”,area);
Cir = 2*(22/7)*r;
Printf(“\n circumference of circle=%f“,cir);
Getch();
}
OUTPUT:-
Page | 25
PROGRAM:- 10 Write a program to check even and leap year using nested if ………..else?
SOLUTION:-
FLOW CHART:-
Start
Int a,b,c
If(a==1)
If(a==2)
False
End
Page | 26
CODING: - #include<stdio.h>
#include<conio.h>
Void main()
{
Int a,b,c;
Printf(“enter the choice number=”);
Scanf(“%d”,&a);
If(a==1)
{
Printf(“\n enter the day number=”);
Scanf(“%d”,&b);
If (b%2==0)
{
Printf(“\n number is even”);
}
Else
Printf(“\n number is odd”);
}
Else
Printf(“\n enter the any year=”);
}
Scanf(“%d”,&c);
If(c%4==0)
{
Printf(“\n year is not leap year”);
}
Getch();
}
OUTPUT:-
Page | 27
PROGRAM:- 11 Write a program to print grad of student mark using ……else……if ladder?
SOLUTION:-
FLOW CHART:-
Start
Input per
If(per>
=7)
Distinction
If(per>=60
&&<70)
First division
If
(per>=45&
&per<60)
Second division
If(per>=35&
&<per45)
Third division
faild
End
Page | 28
CODING: - #include<stdio.h>
#include<conio.h>
Void main()
{
Int per;
Printf(“\n enter your mark percentage=”);
Scanf(“%d”,&per);
If(per>=75)
Printf(“\n distinction”);
Else if (per>=60&&per<75)
Printf(“\n first division mark”);
Else if (per>=45&&per<60)
Printf(“\n second division mark”);
Else if (per>=35&&per<45)
Printf(“\n third division mark”);
Else
Printf(“\n failed”);
Getch();
}
OUTPUT:-
Page | 29
PROGRAM:- 12 Write a C-Program to find factorial of inputted number?
SOLUTION:-
FLOW CHART:-
Start
Fact = 1
Input n
For ( i=n;i>=1;i--)
Fact= fact*i)
end
Page | 30
CODING: - #Include<stdio.h>
#include<conio.h>
Void main()
{
Int n,I,fact=1;
Printf(“\n enter the number”);
Scanf(“%d”,&n);
For(i=n;i>=1;i--)
{
Fact= fact*i;
}
Printf(“\n factorial is %d =”,fact);
Getch();
}
OUTPUT:-
Page | 31
PROGRAM:- 13 Write a program to perform matrix addition (3*3)?
SOLUTION:-
FLOW CHART:-
Start
For (b=0;b<3;b++)
For (a=0;a<3;a++)
For (b=0;b<3;b++)
Page | 32
For(a=0;a<3;a++)
For (b=0;b<3;b++)
Z[a][b]=x[a][b]+y[a][b]
For(a=0;a>3;a++)
For(b=0;b<=3;b++)
Print x[a][b]
For(a=0;a<=3;a++)
For(b=0;b<=3;b++)
Print y[a][b]
Page | 33
Addition of two matrix
For (a=0;a<=3;a++)
For (b=0;b<=3;b++)
Print z[a][b]
End
Page | 34
CODING: - #include<stdio.h>
#include<conio.h>
Void main()
{
Int a,b;
Int x[3][3] y[3][3] z[3][3];
Clrscr();
Printf(“\n enter the value=”);
For(a=0;a<3;a++)
{
For(b=0;b<3;b++)
{
Scanf(“%d”,&x[a][b]);
}
}
Printf(“\n enter the value=”);
For(a=0;a<3;a++);
{
For(b=0;b<3;b++)
{
Scanf(“%d”,&y[a][b]);
}
}
For(a=0;a<3;a++)
{
For(b=0;b<3;b++)
{
Z[a][b]=x[a][b]+y[a][b];
}
}
Printf(“\n value of first matrix”);
For(a=0;a<3;a++)
{
Printf(“\n”);
For(b=0;b<3;b++)
{
Printf(“\t %d”,x[a][b]);
}
Page | 35
}
Printf(“\n value of second matrix”);
For(a=0;a<3;a++)
{
Printf(“\n”);
For(b=0;b<3;b++)
{
Printf(“\t %d”,y[a][b]);
}
}
Printf(“\n addition of two matrix”);
For(a=0;a<3;a++)
{
Printf(“\n”);
For(b=0;b<3;b++)
{
Printf(“\t %d”,z[a][b]);
}
}
Getch();
}
OUTPUT:-
Page | 36
Page | 37
PROGRAM:- 14 Write a c-program to perform matrix subtraction (3*3)?
SOLUTION:-
FLOW CHART:-
Start
For(a=0;a<=3;a++)
For(b=0;b<=3;b++)
For(a=0;a<=3;a++)
For(b=0;b<=3;b++)
Page | 38
Input &y[a][b]
For(a=0;a<=3;a++)
For(b=0;b<=3;b++)
z [a][b]=x[a][b]-y[a][b]
For(a=0;a<=3;a++)
For(b=0;b<=3;b++)
Print x[a][b]
Page | 39
For(a=0;a<=3;a++)
For(b=0;b<=3;b++)
Print y[a][b]
For(a=0;a<=3;a++)
For(b=0;b<=3;b++)
Print z[a][b]
end
Page | 40
CODING: - #include<stdio.h>
#include<conio.h>
Void main()
{
Int a, b;
Int x[3][3],y[3][3],z[3][3];
Clrscr();
Printf(“\n enter the first value”);
For(a=0;a<3;a++)
{
For(b=0;b<3;b++)
{
Scanf(“%d”,&x[a][b]);
}
}
Printf(“\n enter the second value”);
For(a=0;a<3;a++)
{
For(b=0;b<3;b++)
{
Scanf(“%d”,&y[a][b]);
}
}
For(a=0;a<3;a++)
{
For(b=0;b<3;b++)
{
Z[a][b]=x[a][b]-y[a][b];
}
}
Printf(“\n value of first matrix”);
For(a=0;a<3;a++)
{
Printf(“\n”);
For(b=0;b<3;b++)
{
Printf(“\t %d”,x[a][b]);
}
}
Printf(“\n value of second matrix”);
For(a=0;a<3;a++)
Page | 41
{
Printf(“\n”);
For(b=0;b<3;b++)
{
Printf(“\t %d”, y[a][b]);
}
}
Printf(“\n subtraction of two matrix”);
For(a=0;a<3;a++)
{
Printf(“\n”);
For(b=0;b<3;b++)
{
Printf(“\n %d”,z[a][b]);
}
}
Getch();
}
OUTPUT:-
Page | 42
PROGRAM:-15 Write a c program to perform arithmetic operation using switch case?
SOLUTION:-
FLOW CHART:-
Start
Input ch
Switch (ch)
Case:1
False
Print addition
Case: 2
C=a+b
C=a-b
Break
Print value of c
Break
Page | 43
False false false
Case: 3 Case: 4 Case: 5 Default
Print first
Print first Print try
value
value again
Input
second Input Input End
value second second
value value
break break
break
Page | 44
CODING: - #include<stdio.h>
#include<conio.h>
void main()
{
int ch,a,b,c;
printf("\n enter your choice=");
scanf("%d",&ch);
switch (ch)
{
case 1: printf("\n addition");
printf("\n enter the first value=");
scanf("%d",&a);
printf("\n enter the second value=");
scanf("%d",&b);
c=a+b;
printf("\n %d",c);
break;
case 2:printf("\n subtraction");
printf("\n enter the first value=");
scanf("%d",&a);
printf("\n enter the second value=");
scanf("%d",&b);
c=a-b;
printf("\n %d",c);
break;
case 3:printf("\n multiplication");
printf("\n enter the first value=");
scanf("%d",&a);
printf("\n enter the second value=");
scanf("%d",&b);
c=a*b;
printf("\n %d",c);
break;
case 4:printf("\n division");
printf("\n enter the first value=");
scanf("%d",&a);
printf("\n enter the second value=");
scanf("%d",&b);
c=a/b;
printf("\n %d",c);
break;
case 5: printf("\n modular division");
printf("enter the first value=");
Page | 45
scanf("%d",&a);
printf("\n enter the second value=");
scanf("%d",&b);
c=a%b;
printf("\n %d",c);
break;
default: printf("\n try again");
}
getch();
}
OUTPUT:-
Page | 46
PROGRAM:- 16 Write a program to sum N natural number?
SOLUTION:-
FLOW CHART:-
Start
Sum=0
Input n
i=1
false
While (i<=n) Print sum
end
true
Sum+=I;
++I;
Page | 47
CODING: - #inclulde<stdio.h>
#include<conio.h>
Void main()
{
Int n,i,sum;
Printf(“\n enter the day number=”);
Scanf(“%d”,&n);
While(i<=n)
{
Sum+
++i;
}
Printf(“\n sum=%d”,sum);
Getch();
}
OUTPUT:-
Page | 48
PROGRAM:- 17 Create a single program to perform following task using if……..else statement
loop and single dimensional integer (a) short element (descending order)?
SOLUTION:
FLOW CHART:-
Start
For(a=0;a<=9;a++)
Input x[a]
For(b=0;b<=9;b++)
For(c=0;c<=9;c++)
If(x[c]<x[c+
After shorting the
1]) element of array
For(a=0;a<=9;a++)
D=x[c];
X[c]=x[c+1];
Print x[a]
X[c+1]=d;
end
Page | 49
CODING: - #include<stdio.h>
#include<conio.h>
void main()
{
int x[10],a,b,c,d;
clrscr();
printf("\n enter the array element");
for(a=0;a<=9;a++)
{
scanf("%d",&x[a]);
}
for(b=0;b<=9;b++)
{
for(c=0;c<=9;c++)
{
if(x[c]<x[c+1])
{
d=x[c];
x[c]=x[c+1];
x[c+1]=d;
}
}
}
printf("\n after sorting the element of array");
for(a=0;a<=9;a++)
{
printf("\n %d",x[a]);
}
getch();
}
OUTPUT:-
Page | 50
PROGRAM:-18 Create a single program to perform following task using if………else statement, loop
and single dimensional integer (a) short element (ascending order)?
SOLUTION:-
FLOW CHART
Start
For(a=0;a<=9;a++)
Input x[a]
For(b=0;b<=9;b++)
For(c=0;c<=9;c++)
For(a=0;a<=9;a++)
D=x[c];
X[c]=x[c+1];
Print x[a]
X[c+1]=d;
end
Page | 51
CODING: - #include<stdio.h>
#include<conio.h>
void main()
{
int x[10],a,b,c,d;
clrscr();
printf("\n enter the array element");
for(a=0;a<=9;a++)
{
scanf("%d",&x[a]);
}
for(b=0;b<=9;b++)
{
for(c=0;c<=9;c++)
{
if(x[c]>x[c+1])
{
d=x[c];
x[c]=x[c+1];
x[c+1]=d;
}
}
}
printf("\n after sorting the element of array");
for(a=0;a<=9;a++)
{
printf("\n %d",x[a]);
}
getch();
}
Page | 52
OUTPUT:-
Page | 53
PROGRAM:- 19 Write a c program to find whether a given string is palindrome or not?
SOLUTION:-
FLOW CHART:-
Start
Input string x
A=strlen(x)
B=a-1
C=0
While(c< false
=b/2)
true
If(x[c])=x[
C++ False b] true
b--
Go to l1
L1
end
Page | 54
CODING: - #Iinclude<stdio.h>
#include<conio.h>
#include<string.h>
{
Char x[20];
Int a,b,c;
Printf(“\n enter the string=”);
Scanf(“%d”,&x);
A=strlen (x);
B=a-1;
C=0;
While(c<=b/2)
{
If(x[c]!=x[b])
{
Printf(“\n string is not palindrome”);
Goto l1;
}
C++;
b--;
}
Printf(“\n string is palindrome”);
L1:
Getch();
}
OUTPUT:-
Page | 55
PROGRAM:- 20 Create a single program to perform following task using switch case if…….else,
loop and single dimensional character array without using library function?
a) To count the number of character in string
b) To count the number of vowel
c) To count number of constant
SOLUTION:-
FLOW CHART:- start
B=0,cvow=0
Input string x
A=strlen (x)
D=a
While(b<
a)
If(x[b]==’a’||
x[b]==’e’||
x[b]==’o’||
x[b]==’u’||
False true
B++ Cvow++
Page | 56
Print length of the string
Print no of vowel
Print no of
consonant
end
Page | 57
CODING: - #include<stdio.h>
#include<conio.h>
#include<string.h>
Void main()
{
Char x[20];
Int a,d,b=0,cvow=0;
Clrscr();
Printf(“\n enter the string=”);
Scanf(“%s”,&x);
A=strlen (x);
D=a;
While(b<a)
{
If(x[b]==’a’||x[b]==’e’||x[b]==’I’||x[b]==’o’||x[b]==’u’)
{
Cvow++;
}
B++;
}
Printf(“\n length of the string=%s”,d);
Printf(“\n total on of vowel=%d”,cvow);
Printf(“\n total on of consonant=%d”,d cvow);
Getch();
}
OUTPUT:-
Page | 58
PROGRAM:- 21 Write a c program using the function power (a,b) to calculate the value of raised
to b?
SOLUTION:-
FLOW CHART:-
start
R = power (p,q)
C=1
For(d=1;d<=b;d++)
C=c*a
Return (c)
Page | 59
CODING: - #include<stdio.h>
#include<conio.h>
int power ( int a, int b);
void main()
{
int p,q,r;
clrscr();
printf("\n enter the number and find power of value=");
scanf("%d%d",&p,&q);
r= power (p,q);
printf("\n %d to the power %d=%d",p,q,r);
getch();
}
power(int a, int b)
{
int c,d;
c=1;
for(d=1;d<=b;d++)
{
c=c*a;
}
return(c);
}
OUTPUT:-
Page | 60
PROGRAM:- 22 Write a c program to swapping two number demonstrated call by value and call
by reference?
SOLUTION:-
FLOW CHART:-
Start
A=10,b=20
Callval ( a,b)
Callref (&a,&b)
Page | 61
Temp=x;
X=y;
Y=temp;
Print value of a, b
through callval
Print value of a
End
Page | 62
CODING: - #include<stdio.h>
#include<conio.h>
void callval (int c,int y);
void callval (int *p, int*q);
void main() {
int a,b;
a=10,b=20;
clrscr();
printf("\n value of a=%d \n value of b=%d",a,b);
callval (a,b);
printf("\n value of a and b in main after function calling \n a=%d \n b=
%d",a,b);
callref (&a,&b);
printf("\n value of a and b in main after function calling \n a=%d \n b=
%d",a,b);
getch();
}
void callval (int x, int y)
{
int temp;
temp =x;
x=y;
y=temp;
printf("\n value of a and b through callval \n a=%d \n b=%d",x,y);
}
void callref( int *p, int *q)
{
int temp=*p;
*p=*q;
*q=temp;
printf("\n value of a and b through callref \n a=%d b=%d",*p,*q);
}
OUTPUT:-
Page | 63
PROGRAM:- 23 Write a c program to demonstrated pointer arithmetic?
SOLUTION:-
FLOW CHART:-
Start
A=50
B=100
P=&a
Q=&b
C=*p+*q
D=*p-*q
E=*p**q
F=*p/*q
Page | 64
Print subtraction
value
Print multiplication
value
End
Page | 65
CODING: - #include<stdio.h>
#include<conio.h>
void main()
{
int a,b,c,d,e,f,*p,*q;
a=50;
b=10;
p=&a;
q=&b;
clrscr();
c=*p+*q;
d=*p-*q;
e=*p**q;
f=*p%*q;
printf("\n addition=%d",c);
printf("\n subtraction=%d",d);
printf("\n multiplication=%d",e);
printf("\n modular division=%d",f);
getch();
}
OUTPUT:-
Page | 66
PROGRAM:- 24 Write a program to print Fibonacci series up to N term and its sum?
SOLUTION:-
FLOW CHART:-
Start
A=0 ,b=1
For (i=1;i<=n;i++)
C=a+b
Print value of c
A=b
B=c
End
Page | 67
CODING: - #include<stdio.h>
#include<conio.h>
void main()
{
int a=0, b=1,c,i,n;
printf("enter the number to print fibo series=");
scanf("%d",&n);
for(i=1;i<=n;i++)
{
c=a+b;
printf("\n %d",c);
a=b;
b=c;
}
getch();
}
OUTPUT:-
Page | 68
PROGRAM:- 25 Create a structure student having data member to store roll number, name
of student, name of three subject, maximum mark, obtain marks
declare a structure variable of student provide facility for input data in data
member and display result of student.
SOLUTION:-
FLOW CHART:- Start
Input roll no
s.total = s.mark1+s.mark2+s.mark3
s.per = s.total/3
Page | 69
Print roll no
Print marks
Print total no
End
Page | 70
CODING: - #include<stdio.h>
#include<conio.h>
struct student
{
char name[20];
int rollno;
int mark1;
int mark2;
int mark3;
int total;
float per;
}s;
void main()
{
printf("\n enter the name of student=");
scanf("%s",&s.name);
printf("\n enter the rollno of student=");
scanf("%d",&s.rollno);
printf("\n enter the three subject mark=");
scanf("%d%d%d",&s.mark1,&s.mark2,&s.mark3);
s.total=s.mark1+s.mark2+s.mark3;
s.per=s.total/3;
printf("\n name of student =%s",s.name);
printf("\n rollno=%d",s.rollno);
printf("\n mark of student mark1 \t=%d\nmark2 \t=%d\n mark3 \t=%d\
n",s.mark1,s.mark2,s.mark3);
printf("\n total %d",s.total);
printf("\n percent of student %f", s.per);
getch();
}
OUTPUT:-
Page | 71
PROGRAM:- 26 Create a structure student having data member to store roll number, name of
student, name of three subject, maximum mark, minimum mark, obtain marks
declare array of student provide facility to display result of all student and specific
student where roll number is given?
SOLUTION:-
FLOW CHART:-
start
For(i=0;i<2;i++)
Input roll no
Page | 72
Input three subject
For(i=0;i<=2;i++)
Print roll no
Print name
Print___________________
Print_______________________
Print subject,maxmark,
minmark, obtain mark
Page | 73
Print subject,maxmark,
minmark, obtain mark
Print______________________
Input roll no
For(i=0;i<=3;i++)
If(s.[i].roll
no==number
Print roll no
Print name
Print__________________
________
Page | 74
Print subject, maxmark,
minmark, obtain mark,
Print_______________
End
Page | 75
CODING:- #include<stdio.h>
#include<conio.h>
struct student
{
int rollno;
char name[10];
char sub1[20],sub2[20],sub3[2];
int maxmark;
int minmark;
int m1,m2,m3;
}s[3];
void main()
{
int i, number;
clrscr();
for(i=0;i<=2;i++)
{
printf("\n enter the detail of student=%d",i+1);
printf("\n enter the roll number=");
scanf("%d",&s[i].rollno);
printf("\n enter the student name=");
scanf("%s",&s[i].name);
printf("\n enter the three subject name=");
scanf("%s%s%s",&s[i].sub1,&s[i].sub2,&s[i].sub3);
printf("\n enter the maxmark");
scanf("%d",&s[i].maxmark);
printf("\n enter the minmark");
scanf("%d",&s[i].minmark);
printf("\n enter the three subject mark=");
scanf("%d%d%d",&s[i].m1,&s[i].m2,&s[i].m3);
clrscr();
}
for(i=0;i<=2;i++)
{
printf("\n rollno =%d",s[i].rollno);
printf("\n name=%s",s[i].name);
printf("\
n_____________________________________________________________________");
printf("\n subject \t maxmark \t minmark \t obtain mark");
printf("\
n_____________________________________________________________________");
printf("\n %s \t \t %d \t \t %d\t \t
%d",s[i].sub1,s[i].maxmark,s[i].minmark,s[i].m1);
printf("\n %s \t \t %d \t \t %d\t \t
%d",s[i].sub2,s[i].maxmark,s[i].minmark,s[i].m2);
printf("\n %s \t \t %d \t \t %d\t \t
%d",s[i].sub3,s[i].maxmark,s[i].minmark,s[i].m3);
printf("\
n_____________________________________________________________________");
}
clrscr();
printf("\n enter the rollno to display result of specific student=");
Page | 76
scanf("%d",&number);
for(i=0;i<=3;i++)
{
if(s[i].rollno==number)
{
printf("\n rollno=%d",s[i].rollno);
printf("\n name=%s",s[i].name);
printf("\
n____________________________________________________________________");
printf("\n subject \t maxmark \t minmark \t obtain mark");
printf("\
n____________________________________________________________________);
printf("\n %s\t \t %d \t \t %d \t \t
%d",s[i].sub1,s[i].maxmark,s[i].minmark,s[i].m1);
printf("\n %s\t \t %d \t \t %d \t \t
%d",s[i].sub2,s[i].maxmark,s[i].minmark,s[i].m2);
printf("\n %s\t \t %d \t \t %d \t \t
%d",s[i].sub3,s[i].maxmark,s[i].minmark,s[i].m3);
printf("\
n____________________________________________________________________");
}
}
getch();
}
OUTPUT:-
Page | 77
Page | 78
PROGRAM:- 27 Create structure student having data with data member DD, MM, YY (to store
data) create another structure employee with data member to hold the name
of employee, employee id and date of joining ( date of joining will be hold by
variable of structure date with appear date member in employee structure)
store of an employee and print the same?
SOLUTION:-
FLOW CHART:-
Start
Input employee id
Input date
Input month
Input year
Print employee id
Page | 79
Print employee id
Print date
Print month
Print year
End
Page | 80
CODING: - #include<stdio.h>
#include<conio.h>
struct employee
{
int eid;
char ename[20];
struct date
{int dd;
int mm;
int yy;
}d1;
}e1;
void main()
{
clrscr();
printf("\n enter the employee id=");
scanf("%d",&e1.eid);
printf("\n enter the employee name=");
scanf("%s",&e1.ename);
printf("\n enter the date=");
scanf("%d",&e1.d1.dd);
printf("\n enter the month=");
scanf("%d",&e1.d1.mm);
printf("\n enter the year=");
scanf("%d",&e1.d1.yy);
printf("\n employee id=%d",e1.eid);
printf("\n employee name=%s",e1.ename);
printf("\n date=%d",e1.d1.dd);
printf("\n month=%d",e1.d1.mm);
printf("\n year=%d",e1.d1.yy);
getch();
}
Page | 81
OUTPUT:-
Page | 82
PROGRAM:- 28 Define union employee having data member one integer, one float and single
dimensional character array. Declare a union variable main and text variable?
SOLUTION:-
FLOW
CHART:- Start
Input id of employee
Print employee id
End
Page | 83
CODING:- #include<stdio.h>
#include<conio.h>
#include<string.h>
union employee
{
char name[20];
int age;
int id;
float salary;
};
void main()
{
clrscr();
union employee e;
printf("\n information of employee");
printf("\n name of employee=");
scanf("%s",& e.name);
printf("\n age of employee=");
scanf("%d",&e.age);
printf("\n id of employee=");
scanf("%d",&e.id);
printf("\n salary of employee=");
scanf("%f",&e.salary);
printf("\n employee name=%s",e.name);
printf("\n employee age=%d",e.age);
printf("\n employee id=%d",e.id);
printf("\n employee salary=%f",e.salary);
getch();
}
OUTPUT:-
Page | 84
PROGRAM:- 29 Write a c-program to inputted check whether it is Armstrong number or not?
SOLUTION:-
Input n
I=n
False
While(i>0)
True
R=i/10
Sum=sum+(r*r*r);
I=i/10 If==sum
False True
End
Page | 85
CODING: - #include<stdio.h>
#include<conio.h>
void main()
{
int i,r,sum=0,n;
printf("\n enter a no.=");
scanf("%d",&n);
i=n;
while(i>0)
{
r=i%10;
sum=sum+(r*r*r);
i=i/10;
}
if(n==sum)
{
printf("\n number is armstrong=");
}
else
{
printf("\n a number is not armstrong=");
}
getch();
}
OUTPUT:-
Page | 86