C Programs For Practice

  • Uploaded by: Hirdesh
  • 0
  • 0
  • May 2020
  • PDF

This document was uploaded by user and they confirmed that they have the permission to share it. If you are author or own the copyright of this book, please report to us by using this DMCA report form. Report DMCA


Overview

Download & View C Programs For Practice as PDF for free.

More details

  • Words: 1,957
  • Pages: 16
Assignment of Programming and Problem Solving in C

SOME

C

PROGRAMS FOR PRACTICE

1

Hirdesh Singh Rajput

Assignment of Programming and Problem Solving in C 1st Assignment :  If the marks of a student in five different subjects entered by the keyboard so find out the average marks and percentage of obtained marks of student assume the max. marks of each subject is 100. /* A program of print the marksheet and show the percentage of obtained marks*/ /* Note : I'm using only 5 subjects and each subjects have max : 100 and min 40 marks*/ #include<stdio.h> void main() { int mca101,mca102,mca103,mca104,mca105,total; float per; clrscr(); printf("Please enter the marks of MCA101 : "); scanf("%d",&mca101); printf("Please enter the marks of MCA102 : "); scanf("%d",&mca102); printf("Please enter the marks of MCA103 : "); scanf("%d",&mca103); printf("Please enter the marks of MCA104 : "); scanf("%d",&mca104); printf("Please enter the marks of MCA105 : "); scanf("%d",&mca105); total=mca101+mca102+mca103+mca104+mca105; per=total/5; printf("\n ---------------------------------------------------------------"); printf("\n * MARKSHEET OF MCA -I SEM *" ); printf("\n ---------------------------------------------------------------"); printf("\n SUBJECT SUBJECT CODE MIN MAX MARKS OBTAINED"); printf("\n ---------------------------------------------------------------"); printf("\n Information Technology MCA 101 40 100 %d",mca101); printf("\n Mathematical Foundation MCA 102 40 100 %d",mca102); printf("\n Programming in C MCA 103 40 100 %d",mca103); printf("\n Computer Organization MCA 104 40 100 %d",mca104); printf("\n Communication Skills MCA 105 40 100 %d",mca105); printf("\n ---------------------------------------------------------------"); printf("\n TOTAL 200 500 %d",total); printf("\n ---------------------------------------------------------------"); printf("\n # PERCENTAGE : %f % #",per); getch(); } Screen Print of program:   Please enter the marks of MCA Please enter the marks of MCA Please enter the marks of MCA Please enter the marks of MCA Please enter the marks of MCA

101 102 103 104 105

: : : : :

80 80 80 80 80

--------------------------------------------------------------------------------------------------------------* MARKSHEET OF MCA - I SEM * --------------------------------------------------------------------------------------------------------------SUBJECT SUBJECT CODE MIN MAX MARKS OBTAINED --------------------------------------------------------------------------------------------------------------Intormation Technology MCA 101 40 100 90 Mathematical Foundation MCA 101 40 100 90 Programming in C MCA 101 40 100 90 Computer Organization MCA 101 40 100 90 Communication Skills MCA 101 40 100 90 --------------------------------------------------------------------------------------------------------------TOTAL 200 500 450 ---------------------------------------------------------------------------------------------------------------

2

Hirdesh Singh Rajput

Assignment of Programming and Problem Solving in C # PERCENTAGE : 90.0000 % #

3

Hirdesh Singh Rajput

Assignment of Programming and Problem Solving in C 2nd Assignment :  If basic salary is input through by the keyboard the DA is 40% of basic salary and HR is 20% of basic salary so write a program to calculate the gross salary. /* A program of calculate the gross salary*/ /* Note : DA is 40% of basic salary and HR is 20% of basic salary */ #include<stdio.h> void main() { float bs,da,hr,gs; clrscr(); printf("Please enter the basic salary : "); scanf("%f",&bs); da=(bs*40)/100; hr=(bs*20)/100; gs=bs+da+hr; printf("\n Basic Salary is = %f",bs); printf("\n D.A. is = %f",da); printf("\n H.R. is = %f",hr); printf("\n ------------------------------------------------"); printf("\n Total gross salary is = %f",gs); printf("\n ------------------------------------------------"); getch(); } Screen Print of program:

Please enter the basic salary : 9000 Basic Salary is = 9000.0000 D.A. is = 3600.0000 H.R. is = 1800.0000 ----------------------------------------------------------Total gross salary is = 14400.0000 -----------------------------------------------------------

4

Hirdesh Singh Rajput

Assignment of Programming and Problem Solving in C 3rd Assignment :  If any integer is input through by the keyboard WAP to find it is an odd or even number. /* A program for find the entered inteager number is even or odd */ #include<stdio.h> void main() { int a; clrscr(); printf("Please enter any inteager number : "); scanf("%d",&a); if(a%2==0) printf("# The entered number is an even number #"); else printf("# The entered number is an odd number #"); getch(); } Screen Print of program:

Please enter any inteager number : 26 # The entered number is an even number # Please enter any integaer number : 25 # The entered number is an odd number #

5

Hirdesh Singh Rajput

Assignment of Programming and Problem Solving in C 4rt Assignment :  If any year is input through by the keyboard WAP to find it is a leap year or not. /* A program for find the entered year is a leap year or not*/ #include<stdio.h> void main() { int y; clrscr(); printf ("Please enter the year : "); scanf("%d",&y); if(y%100==0) { if (y%400==0) printf("\n # The entered year is a leap year. # "); else printf("\n # The entered year is not a leap year. # "); } else { if (y%4==0) printf("\n # The entered year is a leap year. # "); else printf("\n # The entered year is not a leap year. # "); } getch(); } Screen Print of program: Please enter the year : 2000 # The entered year is a leap year. # Please enter the year : 2001 # The entered year is not a leap year. #

6

Hirdesh Singh Rajput

Assignment of Programming and Problem Solving in C 5th Assignment :  Write a program to find out the multiplication of two matrixes. /* A program to find out the multiplication of two matrix */ #include<stdio.h> #include void main() { int a[25][25]; int a1[25][25]; int a2[25][25]; int i,j,n,m,k,l,e; clrscr(); printf("Enter the size of first matrix \n"); scanf("%d%d",&n,&m); printf("\nEnter the elements of first matrix \n"); for(i=0;i
7

Hirdesh Singh Rajput

Assignment of Programming and Problem Solving in C printf("\t %d ",a2[i][j]); printf("\n"); } getch(); } Screen Print of program: Example 1: Enter the size of first matrix 3 3 Enter the elements of first matrix 1 2 3 4 5 6 7 8 9 Enter the size of second matrix 3 3 Enter the elements of second matrix 9 8 7 6 5 4 3 2 1 First matrix you entered: 1 2 3 4 5 6 7 8 9 Second matrix you entered: 9 8 7 6 5 4 3 2 1 Multiplication of matrixes is: 30 24 19 84 69 54 138 114 90 Example 2: Enter the size of first matrix 2 2 Enter the elements of first matrix 2 2 2 2 Enter the size of second matrix 2 2 Enter the elements of second matrix 2 2 2 2 First matrix you entered: 2 2

8

Hirdesh Singh Rajput

Assignment of Programming and Problem Solving in C 2 2 Second matrix you entered: 2 2 2 2 Multiplication of matrixes is: 8 8 8 8

9

Hirdesh Singh Rajput

Assignment of Programming and Problem Solving in C 6th Assignment :  Write a program to find out the transpose of a matrix. /* A program to find out the transpose of a matrix */ #include<stdio.h> void main() { int a[25][25]; int i,j,n,m; clrscr(); printf("Enter the size of matrix :\n"); scanf("%d%d",&n,&m); printf("Enter the elements of matrix :\n"); for(i=0;i
Screen Print of program: Enter the size of matrix: 3 2 Enter the elements of matrix: 1 2 3 4 5 6 You entered the matrix: 1 2 3 4 5 6 The Transpose of this matrix is: 1 3 5 2 4 6

10

Hirdesh Singh Rajput

Assignment of Programming and Problem Solving in C 7th Assignment :  Write a program of function with no argument and no return value /* A program of function has no argument and no return value */ #include<stdio.h> void printline(void) { int i; printf("* *"); for(i=0;i<8;i++) { printf(" "); } printf("* *"); for(i=0;i<8;i++) { printf(" "); } printf("* *"); for(i=0;i<9;i++) { printf(" "); } printf("* *"); for(i=0;i<8;i++) { printf(" "); } printf("* *"); for(i=0;i<8;i++) { printf(" "); } printf("* *"); } void printline2(void) { int i; printf("* "); for(i=0;i<10;i++) { printf("*"); } printf(" "); for(i=0;i<10;i++) { printf("*"); } printf(" *"); for(i=0;i<9;i++) { printf(" "); } printf("* "); for(i=0;i<10;i++) { printf("*"); } printf(" "); for(i=0;i<10;i++) { printf("*"); } printf(" *"); } void main() { int i; clrscr(); //1 line

11

Hirdesh Singh Rajput

Assignment of Programming and Problem Solving in C for(i=0;i<31;i++) { printf(" "); } printf("*\n"); //2 line for(i=0;i<30;i++) { printf(" "); } printf("* *\n"); //3 line for(i=0;i<29;i++) { printf(" "); } printf("* *\n"); //4 line for(i=0;i<28;i++) { printf(" "); } printf("* *\n"); //5 line for(i=0;i<27;i++) { printf(" "); } printf("* *\n"); //6 line for(i=0;i<63;i++) { printf("*"); } printf("\n"); //7 line for(i=0;i<27;i++) { printf("*"); } printf(" G.G.C.T "); for(i=0;i<27;i++) { printf("*"); } //8 line printf("\n*"); for(i=0;i<25;i++) { printf(" "); } for(i=0;i<11;i++) { printf("*"); } for(i=0;i<25;i++) { printf(" "); } printf("*\n"); //9 line printline2(); //10 -14 line for(i=0;i<5;i++) { printf("\n"); printline(); } printf("\n"); //15 line

12

Hirdesh Singh Rajput

Assignment of Programming and Problem Solving in C printline2(); //16 line printf("\n"); //9 line printline2(); //10 -14 line for(i=0;i<5;i++) { printf("\n"); printline(); } printf("\n"); //15 line printline2(); printf("\n"); for(i=0;i<63;i++) { printf("*"); } printf("\n"); getch(); }

Screen Print of program: * * * *

*

*

* * * *************************************************************** *************************** G.G.C.T *************************** * *********** * * ********** ********** * * ********** ********** * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * ********** ********** * * ********** ********** * * ********** ********** * * ********** ********** * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * ********** ********** * * ********** ********** * ***************************************************************

13

Hirdesh Singh Rajput

Assignment of Programming and Problem Solving in C 8th Assignment :  Write a program of function with no argument and a return value /* A function program with no argument and a return value */ #include<stdio.h> int larg() { int x,y; printf("Enter the two values :\n"); scanf("%d %d",&x,&y); (x>y)?x:y; } void main() { clrscr(); printf("The largest value is : %d",larg()); getch(); }

Screen Print of program: Enter the two values : 25 67 The largest value is : 67

14

Hirdesh Singh Rajput

Assignment of Programming and Problem Solving in C 9th Assignment:  Write a program of function with argument and no return value /* A function program with arguments and no return value (Pro.-Sum of two values)*/ #include<stdio.h> void sum(int a,int b) { printf("Enter the two values : \n"); scanf("%d %d",&a,&b); printf("The sum of these two values is : %d",(a+b)); } void main() { int x,y; clrscr(); sum(x,y); getch(); } Screen Print of program: Enter the two values : 25 36 The sum of these two values is : 61

15

Hirdesh Singh Rajput

Assignment of Programming and Problem Solving in C 10th Assignment:  Write a program of function with argument and return value /* A program of function with arguments and return value (Pro.-Find Largest value)*/ #include<stdio.h> int larg(int x, int y) { (x>y)?x:y; } void main() { int a,b; clrscr(); printf("Enter two values : \n"); scanf("%d %d",&a,&b); printf("The largest value is : %d",larg(a,b)); getch(); } Screen Print of program: Enter two values : 33 65 The largest value is : 65

16

Hirdesh Singh Rajput

Related Documents

C Programs
April 2020 23
C++ Programs
November 2019 25
C++ Programs
June 2020 21
C Programs
November 2019 40

More Documents from ""