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

1.total and Average

The document contains 14 code examples demonstrating various programming concepts in C language like data types, operators, control structures, functions, classes and inheritance. The examples include calculating total and average, checking leap year, income tax calculation, voting eligibility, finding maximum value, for loop, string manipulation, switch case, student marks system, function calling, function overloading, object-oriented concepts like class, single inheritance and multiple inheritance.

Uploaded by

Praveen Kumar
Copyright
© Attribution Non-Commercial (BY-NC)
Available Formats
Download as DOC, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
43 views

1.total and Average

The document contains 14 code examples demonstrating various programming concepts in C language like data types, operators, control structures, functions, classes and inheritance. The examples include calculating total and average, checking leap year, income tax calculation, voting eligibility, finding maximum value, for loop, string manipulation, switch case, student marks system, function calling, function overloading, object-oriented concepts like class, single inheritance and multiple inheritance.

Uploaded by

Praveen Kumar
Copyright
© Attribution Non-Commercial (BY-NC)
Available Formats
Download as DOC, PDF, TXT or read online on Scribd
You are on page 1/ 23

1.

TOTAL AND AVERAGE

#include<stdio.h> #include<conio.h> main() { int num1,num2; float total,avg; clrscr(); printf("\nEnter the number1 value:"); scanf("%d",&num1); printf("\nEnter the number2 value:"); scanf("%d",&num2); total=num1+num2; avg=total/2; printf("\nThe Total is:%f",total); printf("\nThe Average is:%f",avg); getch(); }

OUTPUT Enter the number1 value:20 Enter the number2 value:40 The Total is:60.000000 The Average is:30.000000

2.FIND OUT LEAF YEAR OR NOT LEAF YEAR

#include<stdio.h> #include<conio.h> main() { int year; clrscr(); printf("\nEnter the year:"); scanf("%d",&year); if(year%4==0) printf("\nGiven year is leaf year:%d",year); else printf("\nGiven year is not leaf yeat:%d",year); getch(); }

OUTPUT Enter the year:2013 Given year is not leaf yeat:2013

3.FIND OUT THE INCOME TAX

#include<stdio.h> #include<conio.h> main() { int sal=150000,sa; clrscr(); printf("\nEnter the salaray:"); scanf("%d",&sa); if(sal<=sa) printf("\nYour must Paid to tax"); else printf("\nYour do not Pay the tax"); getch(); }

OUTPUT Enter the salaray:50000 Your do not Pay the tax

4.FIND OUT ELIGIBLE FOR VOTE

#include<stdio.h> #include<conio.h> main() { int age; clrscr(); printf("\nEnter the Age:"); scanf("%d",&age); if(age>=18) printf("\nThe Age is eligible for voting:%d",age); else printf("\nThe age is not eligible for voting:%d",age); getch(); }

OUTPUT Enter the Age:20 The Age is eligible for voting 20

5.FIND OUT BIGEST VALUE #include<stdio.h>

#include<conio.h> main() { int a,b,c; clrscr(); printf("\n Enter the A,B,C Value:"); scanf("%d%d%d",&a,&b,&c); if(a>b && a>c) printf("\n A value is Big:%d",a); else if(b>a && b>c) printf("\n B Value is Big:%d",b); else printf("\n C Value is Big:%d",c); getch(); }

OUTPUT Enter the A,B,C Value: 10 50 70 C Value is Big:70

6.SIMPLE FOR LOOPING #include<stdio.h> #include<conio.h>

main() { int a,i; clrscr(); printf("\nEnter the limt:"); scanf("%d",&a); for(i=0;i<a;i++) printf("\n%d",i); getch(); }

OUTPUT Enter the limt:20 0 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19

7.STRING MANIPULATION #include<stdio.h> #include<conio.h> main() {

char name[10]; int len; clrscr(); printf("\nEnter the Name:"); gets(name); len=strlen(name); strrev(name); printf("\nThe Name length is:%d",len); printf("\nThe Name Reversed is:%s",name); getch(); }

OUTPUT Enter the Name:krish The Name length is:5 The Name Reversed is:hsirk

8.FIND OUT DAYS USING SWITCH CASE

#include<stdio.h> #include<conio.h> main()

{ int c; clrscr(); printf("\nEnter Your Choice"); scanf("%d",&c); switch(c) { case 1: printf("\n 1 Day is Sunday"); break; case 2: printf("\n 2 Day is Monday"); break; case 3: printf("\n 3 Day is Thus day"); break; case 4: printf("\n 4 Day is Wednesday"); break; case 5: printf("\n 5 Day is Thurs day"); break; case 6: printf("\n 6 Day is Friday"); break; case 7: printf("\n 7 Day is Saturday"); break; deafult: printf("\n Enter the correct day"); break; } getch(); }

OUTPUT Enter Your Choice 1 1 Day is Sunday 9.STUDENT MARK INFO #include<stdio.h> #include<conio.h> main() { char name[10];

int rollno; int mark1,mark2,mark3; float total,avg; clrscr(); printf("\nEnter Name:"); scanf("%s",&name); printf("\nEnter rollno:"); scanf("%d",&rollno); printf("\nEnter Mark1:"); scanf("%d",&mark1); printf("\nEnter the Mark2:"); scanf("%d",&mark2); printf("\nEnter the Mark3:"); scanf("%d",&mark3); total=mark1+mark2+mark3; avg=total/3; printf("\nTotal Mark is:%f",total); printf("\nAverage is:%f",avg); getch(); }

OUTPUT Enter Name: parthi Enter rollno:120 Enter Mark1:70 Enter the Mark2:60 Enter the Mark3:50 Total Mark is:180.000000 Average is:60.000000

10.FUNCTION CALLING #include<conio.h> #include<stdio.h> main() { int add(); int sum,a,b; clrscr(); printf("\nEnter The A,B value:");

scanf("%d%d",&a,&b); sum=add(a,b); printf("\nThe Function"); printf("Result is%d:",sum); getch(); } add(int x, int y) { int tot; tot=x+y; return(tot); }

OUTPUT Enter The A,B value:50 60 The FunctionResult is110:

11.FUNCTION OVERLOADING WITH DIFFERENT NUMBER OF ARQUMENTS #include<iostream.h> #include<conio.h> int sum(int,int); int sum(int,int,int);

10

void main() { int a; int b; int c; clrscr(); cout<<\n enter the a value:; cin>>a; cout<<\n enter the b value:; cin>>b; cout<<\n enter the c value:; cin>>c; cout<<\n the result is:<<sum(a,b); cout<<\n the result is:<<sum(a,b,c) getch(); } int sum(int x,int y); { return (x+y); } int sum(int x,int y,int z); { return (x*y*z); }

OUTPUT:

Enter the A value :5

11

Enter the B value :5 Enter the c value :5 The result is :10 The result is :125

12. BOOK-INFORMATION OUTSIDE OF MEMBER FUNCTION DEFINITION

#include<iostream.h> #include<conio.h> class book { Private: char bname[30];

12

int bno; char aname[10]; float price;

Public:

Void getdata() Void display(); }; Void book:: getdata() { cout<<\n enter the Book Name:; cin>>bmane; cout<<\n enter the Book No:; cin>>bno; cout<<\n enter the Book Author Name:; cin>>aname; cout<<\n enter the Book Price:; cin>>price; } Void book:: display() { cout<<==BOOK INFORMATION==\n; cout<<\n Book name:<<bname; cout<<\n Book No:<<bno; cout<<\n Author Name:<<aname; cout<<\n Book Prices:<<price; } Void main()

13

{ book b; clrscr(); b.getdata(); b.display(); getch(); }

OUTPUT: Enter the Book Name: cpgm Enter the Book No: 123 Enter the Book Author Name: balan Enter the Book Price: 120

==BOOK INFORMATION==

14

Book Name: cpgm Book no: 123 Book Author Name: balan Book Prices: 120

13. SINGLE INHERITANCE

#include<iostream.h> #include<conio.h> Class stud { Private: int no; char name[20]; int tmark; Public:

15

void gets() { cout<<\n Name:; cin>>name; cout<<\n No:; cin>>no; cout<<\n Mark:; cin>>tmark; } void puts() { cout<<Name:<<name; cout<<\n No:<<no; cout<<\n Mark:<<tmark; } };

class mark : public stud { Private: int m1,m2,m3: int tot; float avg; Public; void get() { cout<< Mark1:;

16

cin>>m1; cout<< Mark2:; cin>>m2; cout<< Mark3:; cin>>m3; } void cal() { tot=m1+m2+m3; avg=tot/3; } voidput() { cout<<\n Mark1:<<m1; cout<<\n Mark2:<<m2; cout<<\n Mark3:<<m3; cout<<\n Total:<<tot; cout<<\n Average:<<avg; } }; void main() { clrscr(); Mark m1; m1.gets(); m1. get(); m1.cal(); m1.puts(); m1.put();

17

getch(); }

OUTPUT:

NAME :M.NKrishnan

No:121 Mark1:60 Mark2:50 Mark3:80

NAME :M.NKrishnan No:121 Mark1:60 Mark2:50 Mark3:80

18

14. MULTIPLE INHERITANCE

#include<iosream.h> #include<conio.h> class train { Private: char name[10]; int tno; char jun[10];

Public: void gets() { cout<<\n enter the Train Name:;

19

cin>>tname; cout<<\n enter the Train No:; cin>>tno; cout>>\n enter the Junction Name:; cin>>jun; } void puts() { cout<<\n Train Nmae is:<<tname; cout<<\n Train No is:<<tno; cout<<\n Junction Name is:<<jun; } };

class coche { Private: int cno; int seat; Public: void getting() { cout<<\n enter the Coche No:; cin>>cno; cout<<\n enter the Total No Of Seats:; cin>>seat; } void putting()

20

{ cout<<\n Coche No is:<<cno; cout<<\n Total No Of Seats:<<seat; } }; class passenger : public coache, public train { Private: char name[20]; int idno; float fare;

Public: void getdata() { cout<<\n enter the Passanger Name:; cin>>pname; cout<<\n enter the Id No:; cin>>idno; cout<<\n enter the Train Fare:; cin>>fare; } void putdata() { cout<<\n The Passanger Name:<<pname;

21

cout<<\n The Id No:<<idno; cout<<\n The Train Fare:<<fare; } }; void main() { clrscr(); Passenger p; p.gets(); p.geting(); p.getdata(); p.puts(); p.puting(); p.putdata(); getch(); }

OUTPUT:

Enter the Train Name:PANDIAN Enter the Train No:1421 Enter the Junction Name: MADURAI Enter the cocheno:5 Enter the Total No Of Seats:450 Enter the Passanger Name:RAM Enter the Id No:120 Enter the Train Fare:175

22

Train Name is:PANDIAN Train No is:1421 Junction Name is:MADURAI Coche No is:5 Total No of seats is:450 The Passenger Name is:RAM The Id No:120 The Train Fare:175

23

You might also like