C Programs

  • Uploaded by: Vignesh
  • 0
  • 0
  • April 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 as PDF for free.

More details

  • Words: 496
  • Pages: 11
To check whether the entered string is palindrome or not #include <stdio.h> #include #include <string.h> void main() {clrscr(); char str1[20],str2[20]; int m,x,i,j; printf("\n Enter any string - "); scanf("%s",&str1); m=strlen(str1); for(i=m-1,j=0;i>=0;i--,j++) { str2[j]=str1[i]; } str2[j]='\0'; x=strcmp(str1,str2); if(x!=0) printf("\n The entered string is not palindrome"); if(x==0) printf("\n The entered string is palindrome"); getch(); }

1

To concatenate two strings #include<stdio.h> #include #include<string.h> void main() {clrscr(); char a[20],b[20]; printf("Enter the first string = "); scanf("%s",&a); printf("Enter the second string = "); scanf("%s",&b); strcat(a,b); printf("The concatenated string is = "); printf("%s",a); getch(); }

2

To find the reverse of a string #include<stdio.h> #include #include<string.h> void main() {clrscr(); char a[20]; printf("Enter the first string = "); scanf("%s",&a); strrev(a); printf("The reverse string is = "); printf("%s",a); getch(); }

3

To multiply two given Matrices of orders (2*3) & (3*3) respectively #include<stdio.h> #include void main () {clrscr(); int m1[2][3],m2[3][3],r[2][3]; int i,j; puts("Values for 1st Matrix of 2*3"); for(i=0;i<2;i++) { printf("\n%d row",i+1); for(j=0;j<3;j++) { printf("\nEnter the value of column : "); scanf("%d",&m1[i][j]); } } puts("\n\n\nEnter values for 2nd Matrix of 3*3 "); for(i=0;i<3;i++) { printf("\n%d row",i+1); for(j=0;j<3;j++) { printf("\nEnter the value of column : "); scanf("%d",&m2[i][j]); } }

4

(Matrix multiplication program continued………….)

for(i=0;i<2;i++) { printf("\n"); for(j=0;j<3;j++) { r[i][j]=0; r[i][j]=m1[i][j]+m2[i][j]; } } puts("\nResultant Matrix : "); for(i=0;i<2;i++) { printf("\n"); for(j=0;j<3;j++) { printf("%d",r[i][j]); } } getch(); }

5

To find the largest & second largest numbers out of 10 entered numbers #include<stdio.h> #include #include<string.h> void main() {clrscr(); int a[10],i,j,x; for(i=0;i<10;i++) { printf("\nEnter the no., %d = ",i+1 ); scanf("%d",&a[i]); } for(i=0;i<10;i++) { for(j=i+1;j<=10;j++) { if(a[i]
6

To find the reverse of a number #include<stdio.h rel="nofollow"> #include void main() {clrscr(); int num,i; int num1=0; printf("Enter a number = "); scanf("%d",&num); while(num!=0) { i=num%10; num=num/10; num1=num1*10+i; } printf("Reversed No. is = %d",num1); getch(); }

7

To find the average height of 5 Males & 5 Females #include<stdio.h> #include void main() {clrscr(); float mavg,mtot,favg,ftot,mh[5],fh[5]; int i; puts("Enter the Male heights"); for(i=0;i<5;i++) { printf("\nHeight, %d = ",i+1); scanf("%f",&mh[i]); mtot=mh[i]+mtot; } mavg=mtot/5; printf("\nThe average Male height is = %f",mavg); puts("\n\n\n\nEnter the Female heights"); for(i=0;i<5;i++) { printf("\nHeight, %d = ",i+1); scanf("%f",&fh[i]); ftot=fh[i]+ftot; } favg=ftot/5; printf("\nThe average Female height is = %f",favg); getch();

}

8

To find greatest number out of three numbers #include<stdio.h> #include void main() {clrscr(); int a,b,c; printf("Enter any integer,a"); scanf("%d",&a); printf("Enter any integer,b"); scanf("%d",&b); printf("Enter any integer,c"); scanf("%d",&c); if(a>b) { if(a>c) {printf("a is greatest"); printf("%d",a);} else { printf("c is greatest"); printf("%d",c); } }

9

(Greatest out of three numbers continued…………)

else { if(b>c) {printf("b is greatest"); printf("%d",b);} else { printf("c is greatest"); printf("%d",c); } } getch(); }

10

To find the roots of a Quadratic Equations #include<stdio.h> #include #include<math.h> void main() {clrscr(); float a,b,c,p,q,r,x,conjug_X; printf("Enter coefficient, a = "); scanf("%f",&a); printf("Enter coefficient, b = "); scanf("%f",&b); printf("Enter coefficient, c = "); scanf("%f",&c); r=2*a; p=-b/r; q=(sqrt((b*b)-(4*a*c)))/r; x=p+q; conjug_X=p-q; printf("x = "); printf("%f",x); printf("\nConjugate x = "); printf("%f",conjug_X); getch(); }

11

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 "Neil Mahaseth"