Showing posts with label For Loop. Show all posts
Showing posts with label For Loop. Show all posts

WAP to find transport of of given 3x3 matrix

/*WAP to find transport of of given 3x3 matrix*/
#include<stdio.h>
#include<conio.h>
void main()
{
	int a[3][3],i,j;
	clrscr();
	printf("Enter Elements for A Matrix:");
	for(i=0;i<3;i++)
	{
		for(j=0;j<3;j++)
		{
			printf("\n\nElements[%d][%d]:",i,j);
			scanf("%d",&a[i][j]);
		}
	}
	for(i=0;i<3;i++)
	{
		for(j=0;j<3;j++)
		{
			printf("%d\t",a[i][j]);
		}
		printf("\n");
	}
	printf("\nTranspose of Matrix:\n");
	for(i=0;i<3;i++)
	{
		for(j=0;j<3;j++)
		{
			printf("%d\t",a[j][i]);
		}
		printf("\n");
	}
	getch();
}

Wap to print line or draw line after text without using graphics


/*Wap to print line or draw line after text without using graphics*/
#include<stdio.h>
#include<conio.h>

void drawline();

void main()
{
 clrscr();

 drawline();

 printf("SMIT");

 drawline();

 getch();
}

void drawline()
{
 int i;
 printf("\n");
 for(i=0;i<10;i++)
  printf("-");
 printf("\n");

}

WAP to illustrate the use of CONTINUE and BREAK statement using IF Else

/*WAP to illustrate the use of CONTINUE and BREAK statement using IF Else*/
#include<stdio.h>
#include<conio.h>

void main()

{
 int x=5,y=7,z=8;
 clrscr();
 for(;50<100;x++,y++)
 {
 while(y>=x)
 {
 printf("\n%d%d%d",x,y,z);
 y--;
 break;
 }
 if(x==5)
  break;
 else
  continue;
 }
 getch();
}

WAP to count how many number of vovels in the given string and print on output screen

/*WAP to count how many number of vovels in the given string and print on output screen*/
#include<stdio.h>
#include<conio.h>
#include<string.h>
void main()
{
 int count=0,i;
 char a[25],b[25];
 clrscr();
 printf("Enter a strting:");
 gets(a);
 for(i=0;a[i]!='\0';i++)
 {
  if(a[i]=='a' || a[i]=='i' || a[i]=='o' || a[i]=='u' || a[i]=='e')
  {
   strcpy(&b[i],&a[i]);
   count+=1;
  }
  else
  {
   printf("%c",a[i]);
  }

 }
  printf("\n Total vovels: %d",count);

 getch();
}

write a c program to add first 10 successive integer

/*write a c program to add first 10 successive integer*/

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

void main()

{
 int x,n,i,ans=1;
 clrscr();
 printf("enter value of x:");
 scanf("%d",&x);
 printf("enter value of n:");
 scanf("%d",&n);
 for(i=1;i<=n;i++)
 {
  ans=ans+x;
 }
 printf("ans:%d",ans);
 getch();
}

WAP that take N number of elements and print them on output screen


#include <stdio.h>
 
main() 
{
    int array[100], n, c;
 
    printf("Enter the number of elements in array\n");
    scanf("%d", &n);
 
    printf("Enter %d elements\n", n);
 
    for ( c = 0 ; c < n ; c++ ) 
        scanf("%d", &array[c]);
 
    printf("Array elements entered by you are:\n");
 
    for ( c = 0 ; c < n ; c++ ) 
        printf("array[%d] = %d\n", c, array[c]);
 
    return 0;
}

WAP to find whether number entered by user is prime or not


 #include<stdio.h>

main()
{
   int n, c;
 
   printf("Enter a number\n");
   scanf("%d", &n);
 
   if ( n == 2 )
      printf("Prime number.\n");
   else
   {
       for ( c = 2 ; c <= n - 1 ; c++ )
       {
           if ( n % c == 0 )
              break;
       }
       if ( c != n )
          printf("Not prime.\n");
       else
          printf("Prime number.\n");
   }
   return 0;
}

WAP to illustrate continue & break statement


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

void main()

{
	int x=5,y=7,z=8;
	clrscr();
	for(;50<100;x++,y++)
	{
		while(y>=x)
		{
			printf("/n%d%d%d",x,y,++z);
			y--;
			break;
		}
		if(x==5)
			break;
		else
			continue;
	}
	getch();
}

WAP to calculate the how many characters enter by user


#include<stdio.h>
#include<conio.h>
void main()
{
	char str[20];
	int i,c=0;
	clrscr();

	printf("\n enter any string:");
	gets(str);
	for(i=0;i<str[i];i++)
	{
		c++;
	}
	printf("\n no. of character entered in a string is::%d",c);
	getch();


}

WAP to find power if any number which is given by user without MATH.H header file


#include<conio.h>
#include<stdio.h>
int power(int x,int y);
void main( )
{
 int x, y;
 int pow;

 clrscr();
 printf("\nEnter two numbers: -");
 scanf("%d %d",&x,&y);

 pow=power(x,y);
 printf("\n%d to the power %d=%d",x,y,pow);

 getch();
 }

 int power(int x,int y)
 {
  int i;

  int p=1;
  for(i=1;i<=y;i++)

   p=p*x;
   return (p);

}

WAP to find multioplication of given two matrix from user


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

main()
{
	int i,j,k,a[3][3],b[3][3],c[3][3];
	clrscr();

	printf("\n\nA:\n");
	for(i=0;i<3;i++)
	{
		for(j=0;j<3;j++)
		{
			scanf("%d",&a[i][j]);
			c[i][j]=0;
		}
	}

	printf("\n\nB:\n");
	for(i=0;i<3;i++)
	{
		for(j=0;j<3;j++)
			scanf("%d",&b[i][j]);
	}

	for (i = 0; i < 3; i++)
	{
		for (j = 0; j < 3; j++)
		{
			for (k = 0; k < 3; k++)
			{
				c[i][j] += a[i][k] * b[k][j];
	        	}
	    	}	
	}

	printf("\n\nAns:\n");
	for(i=0;i<3;i++)
	{
		for(j=0;j<3;j++)
			printf("%d\t",c[i][j]);
		printf("\n");
	}

	getch();
}

WAP to find maximum number an integer array.

//(WAP to find maximum number an integer array.)

#include<stdio.h>
#include<conio.h>
void main()
{
	int a[10],i,n,k;
	clrscr();
	printf("\nEnter the number:");
	scanf("%d",&n);
	for(i=0;i<n;i++)
	{
		printf("\nEnter elements:",i+1);
		scanf("%d",&a[i]);
	}
	k=a[0];
	for(i=0;i<n;i++)
	{
		if(k<a[i+1])
		{
			k=a[i+1];
		}
	}
	printf("\nMaximum:%d",k);
	getch();
}


WAP to get input 2D MATRIX from user and print them on output screen

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

void main()
{
    int i,j;
    int a[3][3];
    int b[3][3];

    clrscr();
    printf("Enter values for a:--\n");
    for(i=0;i<3;i++)
	{
		for(j=0;j<3;j++)
		   {
		   scanf("%d",&a[i][j]);
		   }
	}

    printf("Enter values for b:--\n");
    for(i=0;i<3;i++)
	{
		for(j=0;j<3;j++)
		   {
		   scanf("%d",&b[i][j]);
		   }
	}

clrscr();
printf("\nvalue of matrix a\n");
    for(i=0;i<3;i++)
	{
		for(j=0;j<3;j++)
		   {
		   printf("\t%d",a[i][j]);
		   }
		   printf("\n");
	}

printf("\nValue of matrix b \n");
 printf("Enter values for a:--\n");
    for(i=0;i<3;i++)
	{
		for(j=0;j<3;j++)
		   {
		   printf("\t%d",b[i][j]);
		   }
		   printf("\n");
	}



    getch();

}

WAP to find factorial of any number

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

void main()
{
	int i,n,f=1;
	clrscr();
	printf("Enter No.");
	scanf("%d",&n);
	for(i=n;i>0;i--)
		f=f*i;
	printf("%d's Factorial value is : %d",n,f);
	getch();
}

wap to sort an int of 5 elements in asending & desending both order

/*wap to sort an int of 5 elements in asending & desending order*/

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

void main()

{
 int n[5],i=0,j=0,temp=0;
 clrscr();

 printf("Enter any 5 int to sort them in Ascending & Descending order:\n");
 for(i=0;i<5;i++)
 {
  scanf("%d",&n[i]);
 }

 printf("\nDescending:\tAscending:\n\n");

 for(i=0;i<5;i++)
 {
  for(j=i+1;j<5;j++)
  {
   if(n[i]<n[j])
   {
    temp=n[j];
    n[j]=n[i];
    n[i]=temp;
   }
  }
 }

 for(i=0,j=4;i<=4,j>=0;i++,j--)
 {
  printf("%d\t\t%d\n",n[i],n[j]);
 }

 getch();
}

Wap to add prime numbers between given two numbers by user

/*Wap to add prime numbers between given two numbers by user*/

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

void main()

{
 int a,b,i,j,k;
 clrscr();

 printf("Enter two int to find Prime Numbers between them:\n");
 scanf("%d %d",&a,&b);
 printf("\nPrime Numbers are:\n");

 for(i=a;i<b;i++)
 {
  k=0;
   for(j=2;j<i;j++)
   {
    if(i%j==0)
    k=k++;
   }
    if(k==0)
    printf("%d\n",i);
 }
 getch();
}

Wap to find sum of first ODD or EVEn numbers using SWITCH CASE

/*write a c program to add first 10 odd or even numbers*/

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

void main()

{
 int n,c,sum=0;
 clrscr();
 printf("1.sum of first 10 odd numbers");
 printf("\n2.sum of first 10 even numbers");
 printf("\nenter your choice:");
 scanf("%d",&c);
 switch(c)
 {
 case 1:
  for(n=1;n<=20;n=n+2)
  {
   sum=sum+n;
  }
  printf("sum:%d",sum);
 break;
 case 2:
  for(n=2;n<=20;n=n+2)
  {
   sum=sum+n;
  }
  printf("sum:%d",sum);
 break;
 }
 getch();
}

Wap to find sum of first 10 even numbers

/*write a c program to add first 10 even numbers*/

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

void main()

{
 int n,sum=0;
 clrscr();
 printf("sum of first 10 even numbers");
  for(n=2;n<=20;n=n+2)
  {
   sum=sum+n;
  }
  printf("sum:%d",sum);

 getch();
}

Wap to find sum of first 10 odd numbers

/*write a c program to add first 10 odd numbers*/

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

void main()

{
 int n,sum=0;
 clrscr();
 printf("sum of first 10 odd numbers");
  for(n=1;n<=20;n=n+2)
  {
   sum=sum+n;
  }
  printf("sum:%d",sum);
 getch();
}

Wap to calculate first 10 iteger using Less Than operator

/*write a c program to add first 10 successive int numbers*/

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

void main()

{
 int n,sum=0;
 clrscr();
 for(n=1;n<11;n++)
 {
 sum=sum+n;
 }
 printf("sum of first 10 succesive int=%d",sum);
 getch();
}