Showing posts with label Result. Show all posts
Showing posts with label Result. Show all posts

C Program to find result where value and power are user given

How to Write a C Program to find result where value and power are user given in C Programming Language ?


Solution:

  1. #include <stdio.h>
  2. #include <conio.h>
  3. void main()
  4. {
  5.  int a,p,n,r;
  6.  clrscr();
  7.  printf("Enter Number: ");
  8.  scanf("%d",&n);
  9.  printf("\nEnter Power: ");
  10.  scanf("%d",&p);
  11.  for(a=p;a!=0;a--)
  12.  {
  13.   r=n*n;
  14.  }
  15.  printf("%d",r);
  16.  getch();
  17. }

C Program to calculate sum of two m*n matrices & store the result in 3 matrix

How to Write a C program to calculate sum of two m*n matrices & store the result in 3 matrix in C Programming Language ?

Solution:
/*C Program to calculate sum of two m*n matrices & store the result in 3 matrix*/
#include<stdio.h>
#include<conio.h>
  void main()
{
  int m[10][10],n[10][10],p[10][10],i,j;
  clrscr();
  printf("\nEnter the elements of m: ");
  for(i=0;i<3;i++)
{
  for(j=0;j<3;j++)
{
  scanf("%d",&m[i][j]);
}
  printf("\n");
}
  printf("\nEnter the elements of n: ");
  for(i=0;i<3;i++)
{
  for(j=0;j<3;j++)
{
  scanf("%d",&n[i][j]);
}
  printf("\n");
}
  printf("\nEntered elements of m is:\n");
  for(i=0;i<3;i++)
{
  for(j=0;j<3;j++)
{
  printf("\t%d",m[i][j]);
}
  printf("\n");
}
  printf("\nEntered elements of n is:\n");
  for(i=0;i<3;i++)
{
  for(j=0;j<3;j++)
{
  printf("\t%d",n[i][j]);
}
  printf("\n");
}
  printf("\nAddition of matrix is: ");
  for(i=0;i<3;i++)
{
  for(j=0;j<3;j++)
{
  p[i][j]=m[i][j]+n[i][j];
}
  printf("\n");
}
  for(i=0;i<3;i++)
{
  for(j=0;j<3;j++)
{
  printf("\t%d",p[i][j]);
}
  printf("\n");
}
  getch();
}

//OUTPUT:

//Enter the elements of m:
1
2
3
4
5
6
7
8
9

//Enter the elements of n:
1
2
3
4
5
6
7
8
9

//Entered elements of m is:
      1       2       3
      4       5       6
      7       8       9

//Entered elements of n is:
      1       2       3
      4       5       6
      7       8       9

//Addition of matrix is:
      2       4       6
      8       10      12
      14      16      18

C Program to accept n numbers & store all prime numbers in an array & display this result

How to write a C Program to accept n numbers & store all prime numbers in an array & display this result in C Programming Language ?


Solution:
/*C Program to accept n numbers & store all prime numbers in an array & display this result*/
#include<stdio.h>
#include<conio.h>
  void main()
{
  int a[10],i,n;
  clrscr();
  printf("\nEnter the n number: ");
  scanf("%d",&n);
  printf("\nEnter the numbers: ");
  for(i=0;i<=n;i++)
{
  scanf("%d",&a[i]);
}
  printf("\nThe Prime Number is: ");
  for(i=1;i<=n;i++)
{
  if(a[i]%2==1)
{
  printf("\t%d",a[i]);
}
}
  getch();
}

//OUTPUT:
//Enter the n number: 4

//Enter the numbers: 1
//2
//3
//4
//5

//The Prime Number is: 3 5