23.12.19

Multiplication of Matrices program in c

#include <stdio.h>


void main()


{


 int m,n,p,q,c,d,k,sum=0;


 int f[10][10],s[10][10],mul[10][10];


 printf("Enter the number of rows and columns of First Matrix\n");


 scanf("%d%d",&m,&n);


 printf("Enter the elements of First Matrix\n");


 for(c=0;c<m;c++)


    for(d=0;d<n;d++)


       scanf("%d",&f[c][d]);


 printf("Enter the number of rows and columns of Second Matrix\n");


 scanf("%d%d",&p,&q);


 if(n!=p)


    printf("The matrices multiplication is not possible.\n");


 else


 {


  printf("Enter the elements of Second Matrix\n");


  for(c=0;c<p;c++)


    for(d=0;d<q;d++)


        scanf("%d",&s[c][d]);    


  for(c=0;c<m;c++)


     {


      for(d=0;d<q;d++)


         {


          for(k=0;k<p;k++)


             {


               sum=sum+f[c][k]*s[k][d];


             }


          mul[c][d]=sum;


          sum = 0;


         }


     }


 printf("Product of Matrices is:\n");


 for(c=0;c<m;c++)


    {  


     for(d=0;d<q;d++)


         printf("%d\t", mul[c][d]);


         printf("\n");
    }


 }


}


Output 1:
Enter the number of rows and columns of First Matrix


2
2


Enter the elements of First Matrix


1
2
3
4


Enter the number of rows and columns of Second Matrix
2
2


Enter the elements of Second Matrix
1
2
3
4


Product of Matrices is:
7    10   
15    22

Sum of two Matrices program in c

#include <stdio.h>


void main()


{


 int r1,c1,r2,c2,c,d,f[10][10],s[10][10],sum[10][10];


 printf("Enter the number of rows and columns of First Matrix\n");


 scanf("%d%d",&r1,&c1);


 printf("Enter the number of rows and columns of Second Matrix\n");


 scanf("%d%d",&r2,&c2);


 if(r1==r2 && c1==c2)


 {


 printf("Enter the elements of First Matrix\n");

 for(c=0;c<r1;c++)


    for(d=0;d<c1;d++)


       scanf("%d",&f[c][d]);


 printf("Enter the elements of Second Matrix\n");


 for(c=0;c<r2;c++)


    for(d=0;d<c2;d++)


        scanf("%d",&s[c][d]);


 printf("Sum of Two Matrices:\n");


 for(c=0;c<r1;c++)  //we may use r1,c1 combinatio or r2,c2.


 {


  for(d=0;d<c1;d++)


     {


       sum[c][d]=f[c][d]+s[c][d];


       printf("%d\t", sum[c][d]);


     }


  printf("\n");


  }


 }


 else
 {


  printf("Matrix addition is not possible...\n");


 }


}




Output1 :
Enter the number of rows and columns of First Matrix


2
2


Enter the number of rows and columns of Second Matrix


2
2


Enter the elements of First Matrix


1
2
3
4


Enter the elements of Second Matrix


1
2
3
4


Sum of Two Matrices:
2    4   
6    8   

Generating all prime numbers b/w 1 and n program in c

#include<stdio.h>

void main()
{
int n,i,f,j;

printf("enter the number to print prime numbers upto");

scanf("%d".&n);

printf("Prime number are \n ");

for(i=0;i<=n;i++)

{

f=0;

for(j=1;j<=n;j++)

{

if(i%j==0)

f++;

}

if(f==2)

printf("%d",i);

}
}


OUTPUT:

 enter the number to print prime numbers upto 10

Prime number are
2
3
5
7

Generating the first n terms of fibonacci series program in c

#include<stdio.h>
void main()
{
int a=0,b=1,c=0,n,i;

printf("Enter the positive number ");
scanf("%d",&n);

printf("\nFibonacci series ");

for(i=0;i<=n;++i)
{

printf("%d",a);

c=a+b;
a=b;
b=c;
}
}

OUTPUT:

Enter the positive number 10
Fibonacci series
0
1
1
2
3
5
8
13
21
34

Fibonacci sequence program in c

#include<stdio.h>
 void main()
{

int a,b,c=0,n;

a=0;
b=1;

printf("Give the range to print fibonacci series");
 scanf("%d",&n);

printf("%d%d\n",a,b);
while(c<=n)
{

c=a+b;

if(c<=n)
{

printf(" \nThe fibonacci series are %d",c);

a=b;
b=c;
}
}
}



OUTPUT:
Give the range to print fibonacci series 10

The fibonacci series are

0
1
1
2
3
5
8

Sum of individual digit of a positive integer program in c


#include<stdio.h>
void main()
{
 int n,s=0,d;
 printf("Enter Any Positive Number(Integer): ");       
 scanf("%d",&n);             
 while(n!=0)
 {
  d=n%10;     
  s=s+d;     
  n=n/10;     
 }
 printf("The sum of the digits of given Number is %d\n",s);
}

Output1:
Enter Any Positive Number(Integer):145
The sum of the digits of given Number is 10
Output2:
Enter Any Positive Number(Integer):34567
The sum of the digits of given Number is 25

Armstrong number program in c

Armstrong Number(Or Narcissistic Number):
An Armstrong number is a number such that the sum of its digits raised to the no.of digits power is equal to the number itself.
Explnation:To declare a number is an Armstrong number, first determine how many digits are in the number. Call that n. Then take every digit in the number and raise it to the n power. Add all those together, and if your answer is the original number then it is an "Armstrong Number"



#include<stdio.h>

void main()
{

int number,orignum,rem,result=0;

printf("enter a three digit number to check whether it is armstrong or not");

scanf("%d",&number);

orignum=number;

while(orignum!=0)
{
rem=orignum%10;
result+rem*rem*rem;
orignum=orignum/10;
}

if(result==number)

printf("%d is armstrong number ",number);

else

printf("%d is not armstrong number",number);

}


OUTPUT:
1:  enter a three digit number to check whether it is armstrong or not   371
     
     371 is armstrong number

2:  enter a three digit number to check whether it is armstrong or not   456     
     456 is not  armstrong number

perfect number program in c

Perfect Number :A perfect number is a positive integer that is equal to the sum of its proper positive divisors, that is, the sum of its positive divisors excluding the number itself. 



#include<stdio.h>
int main()
{
int n,rem,sum=0,i;
printf("Enter a number\n");
scanf("%d",&n);

for(i=1;i<=(n-1);i++)
{
rem=n%i;
if(rem==0)
{
sum=sum+i;
}

}

if(sum==n)
printf(" number is perfect ");
else
printf("number is not perfect ");

return 0;
}





OUTPUT:

1:   Enter a number 496
       number is perfect 


2:   Enter a number 67
     number is not perfect

Handling Characters program in c

#include<stdio.h>

void main()
{
 char ch1,ch2;

printf("Enter an alphabet in lowercase:");
scanf("%c",&ch1);

ch2=ch1-32;

printf("Equivalent uppercase alphabet is %c",ch2);

}


OUTPUT:

Enter an alphabet  in lowercase: b
Equivalent uppercase alphabet is B

Intialization program in c

#include<stdio.h>

void main()
{
int a=10, b=17,c=83,d=24;

a++;
++b;
c--;
--d;

printf("%d,%d,%d,%d",a,b,c,d);

}

OUTPUT:

11,18,82,23

Escape sequence characters program in c

#include<stdio.h>
#include<conio.h>
void main()
{
int a,b;
char name[20];

printf("Enter two numbers");
scanf("%d%d",&a,&b);
printf("Enter a name");
scanf("%s",name);

printf("%d\t%d\n%s",a,b,name);

}


OUTPUT:

Enter two numbers 23
96
Enter a name Arnold
23          96
Arnold

Type cating example program in c

#include<stdio.h>
#include<conio.h>
void main()
{
int a,b;
float c;
clrscr();

printf("Enter two numbers");
scanf("%d%d",&a,&b);

c=(float)a/b;

printf("Quotient=%f",c);

}

 OUTPUT:

Enter two numbers 5
2
Quotient is 2.5

alphabet to ascii program in c

#include<stdio.h>
#include<conio.h>
main()
{
char ch;
clrscr();
printf("\n enter any numer");
scanf("%c",&ch);
printf("\n char is %c",ch);
printf("\n Ascii code %d",ch);
getch();
}

swap of numbers program in c

#include<stdio.h>
#include<conio.h>
main()
{
int a,b,c;
clrscr();
printf("\n enter A and B values");
scanf("%d%d",&a,&b);
printf("\n Before Swapping A is %d and B is %d",a,b);
c=a;
a=b;
b=c;
printf("\n After swapping  A is %d and B is %d ",a,b);
getch();
}



OUTPUT:
enter A and B values 34 78
Before Swapping A is 34 and B is 78
After Swapping A is 78 and B is 34

Area of circle program in c

#include<stdio.h>
#include<conio.h>
main()
{
float r,a;
clrscr();
printf("\n enter radius");
scanf("%f",&r);
a=3.14*r*r;
printf("Area of circle %f",a)
printf("Area of circle %.2f",a)
getch();
}

OUTPUT:

enter radius 8
Area of circle 200.9600
Area of circle 200.96

square and cube program in c

#include<stdio.h>
#include<conio.h>
main()
{
int a,b,n;
clrscr();
printf("\n enter any number for cube and square value");
scanf("%d",&n);
a=n*n;
b=n*n*n;
printf("square is %d  and cube is %d",a,b)
getch();
}


OUTPUT

enter any number for cube and square value 3
square is 9 cube is 27

Avarage program in c

#include<stdio.h>
#include<conio.h>
main()
{
int m,p,c,total,avarage;
clrscr();
printf("\n enter the three subject marks");
scanf("%d%d%d",&m,&p,&c)
total=m+p+c;
avarage=total/3;
printf("\n total is %d",total);
printf("\n avarage is %d",avarage);
getch();
}


OUTPUT:

enter the three subject marks 20 20 20
total is 60
avarage is 20

Reverse program in c

#include<stdio.h>
#include<conio.h>
main()
{
int n,r,sum=0;
clrscr();
printf("enter the number to reverse the number");
scanf("%d",&n);
while(n!=0)
{
r=n%10;
sum=(sum*10)+r;
n=n/10;
}
printf("the reverse number is"+sum);
}


OUTPUT:

enter the number to reverse the number 345
the reverse number is 543

arthmetic operations(accepting value from user) program in c

#include<stdio.h>
#include<conio.h>
main()
{
int a,b;
clrscr();
scanf("%d%d",&a,&b);
printf("enter a value");
printf("enter b value");
printf("\n Add is %d",a+b);
printf("\n Sub is %d",a-b);
printf("\n Mul is %d",a*b);
printf("\n Div is %d",a/b);
printf("\n Remainder is %d",a%b);
getch();
}



OUTPUT:
enter a value 10
enter b value 10
Add is 20
Sub is 0
Mul is 100
Div is 1
Remainder is 0


sum of numbers program in c

#include<stdio.h>
#include<conio.h>

main()

{
int a,b,c;
clrscr();
a=56;
b=10;
c=a+b;
printf("\n a value is  %d"a);
printf("\n b value is  %d"b);
printf("\n sum is %d"c);
getch();
}



OUTPUT:
a value is 56
b  value is 10
sum is 66













C Hello World Program

#include<stdio.h>

int main()
{
     printf("I am Sirisha!");

     return 0;

}

Ouput:

I am Sirisha!

JAVA program pattern 2

import java.util.Scanner; public class pattern3 { public static void main(String args[]) { int i,j; Scanner sc=new Scanner(System.in); Syste...