CH 1
CH 1
CH 1
/*************************************************************
The use of User defined Data Type i.e. enum
*************************************************************/
#include<stdio.h>
#include<conio.h>
main()
{
int roll1,roll2;
enum standard {FIRST,SECOND,THIRD,FOURTH};
enum standard s1,s2;
clrscr();
printf(“\n Enter the roll numbers for two students”);
scanf(“%d%d”,&roll1,&roll2);
s1=FIRST;
s2=FOURTH; /*assigning the standards*/
printf(“\nThe Roll Number %d is admitted to
%d st Standard”,roll1,s1+1);
printf(“\nThe Roll Number %d is admitted to
%d th Standard”,roll2,s2+1);
getch();
}
2)C program
/*************************************************************
Program for fixing The Bonus of employee using nested if else if
statement.
*************************************************************/
#include<stdio.h>
#include<conio.h>
void main()
{
long int basic;
float bonus,gross;
clrscr();
printf(“\n Enter The basic Salary”);
scanf(“%ld”,&basic);/*for long int format specifier is %ld*/
if(basic<10000)
{
bonus=0.75;
gross= basic+bonus;
printf(“\n Your Salary is = %f”,gross);
}
else if(basic>10000 &&basic<=20000)
{
bonus =0.50;
gross =basic+bonus;
printf(“\n Your Salary is = %f”,gross);
}
else if(basic>20000 &&basic <=50000)
{
bonus=0.25;
gross=basic+bonus;
printf(“\n Your Salary is = %f”,gross);
}
else
{
bonus=0.0;
gross=basic+bonus;
printf(“\n no Bonus and Your Salary is = %f”,gross);
}
getch();
}
3)C Program
/*************************************************************
Program for using switch-case statement.
*************************************************************/
#include<stdio.h>
#include<conio.h>
main()
{
int choice;
clrscr();
printf(“\n Enter Your choice”);
scanf(“%d”,&choice);
switch(choice)
{
case 1:printf(“\n Your choice is number 1");
break;
case 2:printf(“\n Your choice is number 2");
break;
case 3:printf(“\n Your choice is number 3");
break;
default:printf(“\n Choice is other than number 1,2 and 3");
}
getch();
}
4)C Program
/*************************************************************
Program using for loop.
*************************************************************/
#include<stdio.h>
#include<conio.h>
main()
{
int count;
clrscr();
for(count=1;count<=5;count=count+1)
{
printf(“\n Testing the for loop,Tested OK!”);
printf(“\n printing the statement for %d time”,count);
}
}
7)C program
These functions are there in “string.h” file so the sting.h file is included in the program.
#include<stdio.h>
#include<conio.h>
#include<string.h>
#define size 10
void main()
{
char s1[size],s2[size];
clrscr();
printf(“\n Enter String1”);
gets(s1);
printf(“\n Enter String2”);
gets(s2);
printf(“\n\n The length of the String1 is %d”,strlen(s1));
if(strcmp(s1,s2) ==0)
printf(“\n\n Both String1 and String2 Are Same”);
else
printf(“\n\n Both String1 and String2 Are Not Same”);
printf(“\n\n The Reversed String1 is %s”,strrev(s1));
getch();
}
8)C Program
/*************************************************************
Program to perform addition two matrices.
The matices are nothing but the two dimensional arrays.
*************************************************************/
#include<stdio.h>
#include<conio.h>
#define size 3
int A[size][size],B[size][size],C[size][size],n;
void main()
{
int i,j;
clrscr();
printf(“\n Enter The order of the matrix”);
scanf(“%d”,&n);
printf(“\n Enter The Elements For The First Matrix”);
for(i=0;i<n;i++)
for(j=0;j<n;j++)
scanf(“%d”,&A[i][j]);
printf(“\n Enter The Elements For The Second Matrix”);
for(i=0;i<n;i++)
for(j=0;j<n;j++)
scanf(“%d”,&B[i][j]);
for(i=0;i<n;i++)
for(j=0;j<n;j++)
C[i][j]=A[i][j]+B[i][j];
printf(“\n The Addition Is\n”);
for(i=0;i<n;i++)
{
for(j=0;j<n;j++)
{
printf(“%d”,C[i][j]);
}
printf(“\n”);
}
getch();
}
9)C Program
#include<stdio.h>
#include<conio.h>
#include<stdlib.h>
void main(void)
{
int x;
clrscr();
x=5;
printf(“\n The value of x is = %d”,x);
printf(“\n The address of x is =%u”,&x);
getch();
}
10)‘C’ Program
/************************************************************
This is a Program which illustrates how the a variable can be
accessed by pointer.The parameter passing method for function cir
is call by reference.
*************************************************************/
#include<stdio.h>
#include<conio.h>
#include<stdlib.h>
float cir(int *r)
{
float a;
a = 3.14 *(*r)**r);
return(a);
}
void main(void)
{
int r;
float a,*b;
clrscr();
printf(“\n Enter the radius of the circle”);
scanf(“%d”,&r);
a=cir(&r);
b=&a;
printf(“\nvalue of a = %f”,a);
printf(“\naddress of a = %u”,&a);
printf(“\naddress of b = %u”,b);
printf(“\nvalue stored at b =%f”,*b);
getch();
}
11)C Program
/*************************************************************
Program uses the pointers and arrays with the help of pointer the
contents of the array can be displayed.
*************************************************************/
#include<stdio.h>
#include<conio.h>
#include<stdlib.h>
main()
{
int x[10],i;
clrscr();
printf(“\n Enter the numbers in array”);
for(i=0;i<5;i++)
scanf(“%d”,&x[i]);
printf(“\n You have entered”);
for(i=0;i<5;i++)
printf(“\nAt address %u the value is %d”,(x+i),*(x+i));
getch();
}
12)C Program
/*************************************************************
Program for accessing the string using a pointer variable.
*************************************************************/
#include<stdio.h>
#include<conio.h>
#include<stdlib.h>
#define size 10
void main(void)
{
char name[size];
char *i;
clrscr();
printf(“\n What is Your name?”);
gets(name);
i=name;
printf(“\nNow printing your name as ”);
while(*i!=’\0’)
{
printf(“%c”,*i);
i++;
}
getch();
}
13)C Program
/*************************************************************
This Program for is for assigning the values to the structure
variable. Also for retrieving the values.
*************************************************************/
#include<stdio.h>
#include<conio.h>
#include<stdlib.h>
struct student {
int roll_no;
char name[10];
float marks;
} stud1;
void main(void)
{
clrscr();
printf(“\n Enter the roll number”);
scanf(“%d”,&stud1.roll_no);
printf(“\n Enter the name ”);
scanf(“%s”,stud1.name);
printf(“\n Enter the marks”);
scanf(“%f”,&stud1.marks);
printf(“\n The record of the student is”);
printf(“\n\n Roll_no Name Marks”);
printf(“\n——————-”);
printf(“\n%d %s %.2f ”,stud1.roll_no,stud1.name,stud1.marks);
getch();
}
14)‘C’ Program
/*************************************************************
Program for maintaining the students’ database using
structure.The program shows the use of typedef for a structure
variable
*************************************************************/
#include<stdio.h>
#include<conio.h>
#include<stdlib.h>
#include<stdio.h>
#include<conio.h>
void main ()
{
int a,b,ans;
clrscr();
printf("\n Enter a Number");
scanf("%d",&a);
b=1;
ans=a&b;
printf("\n Result of AND operation with 1");
if (ans==0)
printf("\n The Rightmost bit is OFF");
else
printf("\n The Rightmost Bit is ON");
and=a/b;
printf("\n Result Of OR operation with 1");
printf("\n The Rightmost bit is Turned ON and the result
is%d", and);
getch();
}