Posts

Showing posts from September, 2011

To Find Out Largest No. Out Of 3 Nos. Without Using If In C Language

# include <stdio.h> void main() { int a,b,c,m; clrscr(); printf(" \n\n\n  Program To Find Out Largest No. Out Of 3 Nos. Without Using If In C Language "); printf(" \n\n\n\t Please Enter The 1st No. : "); scanf(" %d ",&a); printf(" \n\t Please Enter The 2nd No. : "); scanf(" %d ",&b); printf(" \n\t Please Enter The 3rd No. : "); scanf(" %d ",&c); m = a>b?(a>c?a:c):(b>c?b:c); printf(" \n\n\n\t\t The Largest No. Is %d ",m); getch(); }

Read a string and check whether it is palindrome or not.

 //Read a string and print the string is palindrome or NOT palindrome. # include <stdio.h> void main() { char a[500],b[500]; clrscr(); printf(" \n Enter A String :-  "); scanf(" %s ",&a); strcpy(b,a); //copies string a to b strrev(b);  //reverses string b if(strcmp(a,b)==0)  //compares if the original and reverse strings are same printf(" \n %s is a palindrome ",a); else printf(" \n %s is not a palindrome ",a); getch(); } //Read a string and print the string is palindrome or NOT palindrome without using inbuilt functions. # include <stdio.h> void main() { char a[500]; int i,b; clrscr(); printf(" \n Enter A String :-  "); scanf(" %s ",&a); b = strlen(a); for (i=0;i<=((b-1)/2);i++) {     if(a[i] != a[b-1-i])     printf(" \n %s is not palindrome ",a); } printf(" \n %s is palindrome ",a); getch(); }

To Find First,Second &Third Largest No. From A Given Array

# include <iostream.h> # include <conio.h> void main() { clrscr(); int f,s,t,a[50],n,i; cout<<" \n Enter Size Of Array: "; cin>>n; cout<<" \n Enter The Array:- "; for (i=0;i<n;i++) {     cin>>a[i]; } f = a[0]; s = a[0]; t = a[0]; for (i=0;i<n-1;i++) {     if (a[i] > f)      f = a[i+1];     } for(i=0;i<n-1;i++) {      if ((a[i] > s) && (f > a[i]) )         s = a[i+1]; }       for (i=0;i<n-1;i++) {      if ((a[i] > t) && (f > a[i]) && (s > a[i]))         t = a[i+1]; } cout<<" \n The First Largest No. Is " <<f; cout<<" \n The Second Largest No. Is "<<s; cout<<" \n The Third Largest No Is. "<<t; getch(); }

To Find Modulus Of Two No. Without Using Modulus Operator

# include <stdio.h> void main() { int n1,n2,res,result; clrscr(); printf(" \n Enter First No . "); scanf(" %d ",&n1); printf(" \n Enter Second No. "); scanf(" %d ",&n2); res = n1/n2; result = n1-(n2*res); printf(" \n The Modulus Of %d and %d is %d . ",n1,n2,result); getch(); }

Matrix Addition In C Language

#include <stdio.h> int main(){   int a[3][3],b[3][3],c[3][3],i,j;   printf( "Enter the First matrix->" );   for (i=0;i<3;i++)       for (j=0;j<3;j++)            scanf( "%d" ,&a[i][j]);   printf( "\nEnter the Second matrix->" );   for (i=0;i<3;i++)       for (j=0;j<3;j++)            scanf( "%d" ,&b[i][j]);   printf( "\nThe First matrix is\n" );   for (i=0;i<3;i++){       printf( "\n" );       for (j=0;j<3;j++)            printf( "%d\t" ,a[i][j]);   }   printf( "\nThe Second matrix is\n" );   for (i=0;i<3;i++){       printf( "\n" );       for (j=0;j<3;j++)       printf( "%d\t" ,b[i][j]);    }    for (i=0;i<3;i++)        for (j=0;j<3;j++)             c[i][j]=a[i][j]+b[i][j];    printf( "\nThe Addition of two matrix is\n" );    for (i=0;i<3;i++){        printf( "\n" );        for (j=0;j&