You are on page 1of 9

1)C Program:

/*************************************************************
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);
}
}

5)C Program for arrays


#include<stdio.h>
#include<conio.h>
void main()
{
int a[10],index;
clrscr();
printf(“\n Store The Elements In An Array a”);
for(index=0;index<=9;index++)
scanf(“%d”,&a[index]);
printf(“\n You Have Stored These numbers in the array a”);
for(index=0;index<=9;index++)
printf(“\n %d”,a[index]);
}
6)C program for strings
#include<stdio.h>
#include<conio.h>
main()
{
char str1[10],str2[10];
clrscr();
printf(“\n Accessing Strings By Two Methods”);
str1 = “Radha”; /*Method1*/
printf(“\n Enter The String”);
scanf(“%s”,str2); /*Method2*/
getch();
}

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>

typedef struct student {


int roll_no;
char name[20];
int marks;
}stud;
stud s[10];
void main(void)
{
int n,i;
clrscr();
printf(“\n Enter the total number of students”);
scanf(“%d”,&n);
printf(“\n Enter Each student’s record”);
for(i=0;i<n;i++)
{
scanf(“%d”,&s[i].roll_no);
scanf(“%s”,&s[i].name);
scanf(“%d”,&s[i].marks);
}
printf(“\n Each student’s record is”);
printf(“\n——————-”);
printf(“\n roll_no name marks”);
printf(“\n—————————————-”);
for(i=0;i<n;i++)
printf(“\n%d %s %d”,s[i].roll_no,s[i].name,s[i].marks);
printf(“\n————————-”);
getch();
}
15)C program
/*************************************************************
Program for nested structures.The two structures are declared
within a single structure.
*************************************************************/
#include<stdio.h>
#include<conio.h>
#include<stdlib.h>
struct bdate {
int day;
int month;
int year;
} dt;
struct address {
char street[10];
char city[10];
}add;
struct student {
int roll_no;
char name[10];
struct bdate dt;
struct address add;
}std;
void main(void)
{
clrscr();
printf(“\n Enter the students’ data”);
printf(“\n Enter student’s rollnumber”);
scanf(“%d”,&std.roll_no);
printf(“\n Enter student’s name”);
scanf(“%s”,std.name);
printf(“\n Enter student’s Birth date(mm-dd-yy)”;
scanf(“%d %d %d”,&std.dt.month,&std.dt.day,&std.dt.year);
printf(“\n Enter student’s Address”);
scanf(“%s %s”,&std.add.street,std.add.city);
printf(“\n\n You have entered ”);
printf(“\n roll_no name B’date address”);
printf(“\n————————————-”);
printf(“\n %d %s ”,std.roll_no,std.name);
printf(“ %d-%d-%d ”,std.dt.month,std.dt.day,std.dt.year);
printf(“ %s,%s”,std.add.street,std.add.city);
getch();
}
16)C Program
/*************************************************************
This Program is for assigning the values to the structure
variable. It also shows how the structure can be accessed by
a pointer variable.
*************************************************************/
#include<stdio.h>
#include<conio.h>
#include<stdlib.h>
struct student {
int roll_no;
char name[10];
float marks;
}stud1;
void main(void)
{
clrscr();
struct student *pt;
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);
pt = &stud1;
printf(“\n\t Display of structure using structure variable”);
printf(“\n\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);
printf(“\n\n\t Accessing the same structure using pointer
variable ”);
printf(“\n\n The record of the student is”);
printf(“\n\n Roll_no Name Marks”);
printf(“\n——————————-”);
printf(“\n%d %s %.2f ”,pt->roll_no,pt->name,pt->marks);
getch();
}
17)C program
/***********************************************************
Program for performing Bit-wise AND and OR Operation
************************************************************/

#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();
}

You might also like