Download as doc, pdf, or txt
Download as doc, pdf, or txt
You are on page 1of 25

PROGRAM NO- 1

#include<stdio.h> #include<conio.h> /*A program to input two numbers and work out their sum,average and sums of squares of numbers*/ void main() { int a,b,s,n,m; clrscr(); printf(Enter value of number=); scanf(%d,&n); printf(Enter value of number=); scanf(%d,&m); s=n+m; printf(sum =%d\n,s); a=(n+m)/2; printf(Average=%d\n,a); b= (n*n)+(m*m); printf(Sum of squares of numbers = %d,b); getch(); } /*OUTPUT Enter the value of number= 8 Enter the value of number= 6 Average = 7 100*/ sum = 14 Sum of squares of numbers =

PROGRAM NO- 2
#include<stdio.h> #include<conio.h> /*A program to find area,circumference of circle and area,perimeter of rectangle*/ void main() { float circ,aoc; printf(\n Enter radius of circle =); printf(Enter length of rectangle =); printf(Enter breadth of rectangle =); circ = 2*3.14*r; aor = l*b; printf(\n Area of circle = %f,aoc); Circumference of circle = %f,circ); Area of rectangle = %d,aor); rectangle = %d,peri); getch(); } /*OUTPUT Enter radius of circle = 5 rectangle = 4 Area of circle = 78.500000 circle = 31.400000 Perimeter of rectangle = 20 */ Enter length of Enter breadth of rectangle = 6 Circumference of Area of rectangle = 24 int r,l,b,aor,peri; clrscr(); scanf(%d,&r); scanf(%d,&l); scanf(%d,&b); aoc = 3.14*r*r; peri = (l+b)*2; printf(\n printf(\n printf(\n Perimeter of

PROGRAM NO- 3

#include<stdio.h> #include<conio.h> /*A program to check whether entered year is leap year or not. */ void main() { int yr; clrscr(); printf(Enter the year to be checked); scanf(%d,&yr); if(yr%4==0) { printf(\n %d Is a leap year,yr); } else { printf(\n %d Is not a leap year,yr); } getch(); } /*OUTPUT Enter the year to be checked 2004 2004 Is a leap year */

PROGRAM NO- 4

#include<stdio.h> #include<conio.h> /*A program to input marks of a student if marks are between 80 and 90,print first division,if marks are between 70 and 80 print second division,if marks are between 60 and 70 print third division else print fourth division*/ void main() { int m; printf(Enter marks=\n); if((m>=80)&&(m<=90)) printf(Division is first); else if((m>=70)&&(m<80)) printf(Division is second); else if((m>=60)&&(m<70)) printf(Division is third); else printf(Division is fourth); getch(); /*OUTPUT Enter marks = 85 Division is first */ clrscr(); scanf(%d,&m); { } { } { } { } }

PROGRAM NO- 5
#include<stdio.h> #include<conio.h> /*A program to input a number and display its table using while loop*/

void main()

int i,j,k; clrscr(); printf(Enter the number for printing table =); scanf(%d,&i); j= 1; while(j<=10) { k= i*j; printf(\n%d*%d=%d,i,j,k); j++; } getch(); } /*OUTPUT Enter the number for printing table = 6 6*1 6*3 6*5 6*7 6*9 */ = = = = = 6 18 30 42 54 6*2 = 12 6*4 = 24 6*6 = 36 6*8 = 48 6*10= 60

PROGRAM NO- 6
#include<stdio.h> #include<conio.h>

/*A program to find whether a given number is even or odd using dowhile loop.*/ void main() { int i,n; printf(Enter a number=); clrscr(); scanf(%d,&i);

n= 1; { { printf(Number is even); } else { printf(Number is odd); } n++; }while(n<i); getch(); } /*OUTPUT Enter a number = 18 Number is even */

do if(i%2==0)

PROGRAM NO- 7
#include<stdio.h> #include<conio.h> /* A program to calculate factorial of a number*/ void main() { int num,i,fact=1;

clrscr(); printf(Enter the number=); scanf(%d,&num); for(i=num;i>=1;i--) { fact=fact*i; } printf(\n Factorial is %d,fact); getch(); }

/* OUTPUT Enter the number 5 Factorial is 120 */

PROGRAM NO- 8
#include<stdio.h> #include<conio.h> /* A program to find Fibonacci series upto 51 using for loop*/ void main() int a=0,b=1,c,i; {

clrscr(); printf(%d,a); printf( ); printf(%d,b); for(i=1;i<=8;i++) { c= a+b; printf( ); printf(%d,c); a=b; b=c; } getch(); }

/*OUTPUT 0 1 1 2 3 5 8 13 21 34 */

PROGRAM NO- 9
#include<stdio.h> #include<conio.h> /* A program to check whether the character entered is vowel or not*/ void main()

{ char ch; clrscr(); printf(Enter a character :\n); scanf(%c,&ch); switch(ch) case a: case i: case u: case E: case O: printf(It is a vowel); default: printf(It is not a vowel); getch(); } /*OUTPUT Enter a character: e */ It is a vowel. { case e: case o: case A: case I: case U: break; }

PROGRAM NO- 10
#include<stdio.h> #include<conio.h> /* A program to copy the contents of an array in another array in reverse manner*/ void main() { int a[10],b[10],i; printf(Enter values of a[i]=); clrscr(); for(i=0;i<=9;i++)

{ scanf(%d,&a[i]); } printf(\n Elements in reverse,b[i] are=\n); for(i=0;i<=9;i++) { b[i] = a[9-i]; printf(%d,b[i]); printf(\n); } getch(); } /* OUTPUT Enter the values of a[i]= 1 3 5 7 9 2 4 6 8 10

Elements in reverse,b[i] are = 10 8 6 4 2 */ 9 7 5 3 1

PROGRAM NO- 11
#include<stdio.h> #include<conio.h> /* A program to multiply two matrices of order3*3 using array*/ void main() { int a[3][3],b[3][3],c[3][3],i,j,k; clrscr(); printf(Enter the elements of matrix a=\n); for(i=0;i<3;i++) { for(j=0;j<3;j++) { scanf(%d,&a[i][j]); } } printf(Enter the elements of matrix b = \n); for(i=0;i<3;i++) { for(j=0;j<3;j++) { scanf(%d,&b[i][j]); } } printf(Product of two matrices = \n); for(i=0;i<3;i++)

{ { for(k=0;k<3;k++) c[i][j]+=a[i][k]*b[k][j]; } for(i=0;i<3;i++) for(j=0;j<3;j++) printf(\t%d,c[i][j]); printf(\n); getch(); /*OUTPUT Enter the elements of matrix a= 1 1 1 1 1 Enter the elements of matrix b= 3 3 3 3 3 Product of two matrices = 999 999 999

for(j=0;j<3;j++) c[i][j]=0; { } } { { } } }

1 1 1 1

3 3 3 3

*/

PROGRAM NO- 12
#include<stdio.h> #include<conio.h>

/* A program to take a string and check whether a string entered is palindrome sequence or not*/ void main() { char str[20]; char str1[20]; int x; clrscr(); printf(Enter the elements of string =\n); gets(str); strcpy(str1,str); strrev(str1); x= stricmp(str1,str); { if(x==0) { } else { } } getch(); } printf(String is not palindrome); printf(String is palindrome,x);

/* OUTPUT Enter the elements of string= huj String is not palindrome */

PROGRAM NO- 13
#include<stdio.h> #include<conio.h>

/* A program to swap two values using function*/ void main() { int a,b; printf(Enter the first value=); printf(Enter the second value=); swap(a,b); } void swap(int c,int d) { int temp; temp =c; c=d; d= temp; printf(swaped values =%d,%d,c,d); getch(); } clrscr(); scanf(%d,&a); scanf(%d,&b);

/* OUTPUT Enter the first value = 12 Enter the second value = 67 Swaped values = 67 12 */

PROGRAM NO- 14
#include<stdio.h> #include<conio.h>

/* A program to implement a calculator using function*/ void sum(float a,float b) float t; printf(\n sum = %f\n,t); void sub(float a,float b) float t; printf(\n Difference = %f\n,t); void mul(float a,float b) float t; printf(\n Product = %f\n,t); void div(float a,float b) float t; printf(\n Quotient = %f\n,t); { t= a+b; } { t= a-b; } { t= a*b; } { t= a/b; }

void main() { int n; float a,b; clrscr(); do { printf(\n What do you want to do?\n1.Adddition\n2.Substraction\n3.Multiplication\n4. Division\n5.Exit\n); scanf(%d,&n); switch(n) case 1: printf(\n Enter a&b = \n); sum(a,b); break; case 2 printf(\n Enter a&b = \n); sub(a,b); break; case 3: printf(\n Enter a&b = \n); { { scanf(%f%f,&a,&b); } { scanf(%f%f,&a,&b); } { scanf(%f%f,&a,&b);

mul(a,b); break; case 4: printf(\n Enter a&b = \n); div(a,b); break; case 5: printf(\n Good Bye); } getch(); /* OUTPUT What do you want to do? 2.Substraction 4.Division 1 sum = 11 What do you want to do? 2.Substraction 4.Division 2 Difference = -1 What do you want to do? 2.Substraction 4.Division 3 Product = 21 What do you want to do? 2.Substraction 4.Division 4 Quotient = 13 What do you want to do? 2.Substraction 4.Division 5 */

} { scanf(%f%f,&a,&b); } { } }while(n!=5); }

1.Addition 3.Multiplication 5.Exit Enter a&b = 5 6 1.Addition 3.Multiplication 5.Exit Enter a&b = 4 5 1.Addition 3.Multiplication 5.Exit Enter a&b = 7 3 1.Addition 3.Multiplication 5.Exit Enter a&b = 26 2 1.Addition 3.Multiplication 5.Exit Good Bye

PROGRAM NO- 15
#include<stdio.h> #include<string.h> /* A program to create a structure to specify data on students given below: Roll no., Name, Dept, Course, Year of joining.Assume that there are not more than 10 students in the college 1.Write a function to print the names of all the students who joined in a particular year. 2.Write a function to print the data of a student whose roll no. is given*/ struct students int roll; int year; char name[5]; char dep[5]; char course[5]; char info[5]; } void display(int yearo); void displayd(int rolln); void main() { #include<conio.h>

{ int a,b,c,i; for(i=0;i<5;i++) { printf(Enter the students information as follow\n,i+1); printf(Name of the student); scanf(%s,info[i].name); printf(Depatment:); scanf(%s,info[i].dep); printf(Roll no. of the student); scanf(%d,&info[i].roll); printf(Course); scanf(%s,info[i].course); printf(Year of Joining); scanf(%d,&info[i].name); } do { printf(Your choice\n1.Names of the students in particular year of joining\n2.Data of the students with respective roll no.\n); scanf(%d,&c); if(c==1) { printf(Year of joining); scanf(%d,&b); display(b); }

else if(c==2) { printf(Roll no.); scanf(%d,&a); displayd(a); } }while(c!=2) getch(); } void display(int yearo) { int i; for(i=0;i<5;i++) { if(info[i].year== yearo) { printf(%s,info[i].name); printf(\n); } } } void displayd(int rolln) { int i; for(i=0;i<5;i++) {

if(info[i].roll== rolln) { printf(Roll no.%d,info[i].roll); printf(\n Name of the student); printf(%s,info[i].name); printf(\n Depatment); printf(%s,info[i].dep); printf(\n Course); printf(%s,info[i].course); printf(\n Year of joining:%d,info[i].year); break; } } }

/* OUTPUT Enter the student information as follows: Name of the student:Goldie Depatment:MSIP Roll no. of the student: 017 Course: B.pharma Year of joining: 2011 */

You might also like