Showing posts with label Array. Show all posts
Showing posts with label Array. Show all posts

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 number of odd, even & zero numbers from given 10 int numbers


/*wap to find number of odd, even & zero numbers from given 10 int numbers*/
#include<stdio.h>
#include<conio.h>

void main()

{
	int n[10],i,count1=0,count2=0,count3=0;
	clrscr();
	printf("enter any 10 int numbers:\n");

	for(i=0;i<10;i++)
	{
		scanf("%d",&n[i]);
	}

	for(i=0;i<10;i++)
	{
		if(n[i]==0)
			count1++;
		else if(n[i]%2==0)
			count2++;
		else if(n[i]%2!=0)
			count3++;
	}

	printf("odd numbers:%d",count3);
	printf("\neven numbers:%d",count2);
	printf("\nzero numbers:%d",count1);

	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 insert an element into array.

//WAP to isert an element into array.

#include<stdio.h>
#include<conio.h>
void main()
{
	char ch='y';
	int n,k,a[100],r,i;
	clrscr();
	printf("\nHow many number:");
	scanf("%d",&n);
	for(i=0;i<n;i++)
	{
		printf("\nElement %d:",i+1);
		scanf("%d",&a[i]);
	}
	for(i=0;i<n;i++)
	{
		printf("\n%d",a[i]);
	}
	while(ch=='y')
	{
		printf("\nEnter position where you want to enter:");
		scanf("%d",&k);
		printf("\nEnter new number:");
		scanf("%d",&r);
		for(i=n-1;i>=k-1;i--)
		{
			a[i+1]=a[i];
		}
		a[k-1]=r;
		n=n+1;
		for(i=0;i<n;i++)
		{
			printf("\n%d",a[i]);
		}
		printf("\nDo you want to continue y or n:");
		fflush(stdin);
		scanf("%c",&ch);
	}
	getch();
}

WAP to take N strings from user and print them on output screen

#include<stdio.h>
#include<conio.h>
void main()
{
	int n;
	char a[50][50],i;
	clrscr();
	printf("\nEnter number :");
	scanf("%d",&n);
	for(i=0;i<n;i++)
	{
		printf("\nEnter Name:");
		scanf("%s",a[i]);

	}
	for(i=0;i<n;i++)
	{
		printf("\nName is : %s",a[i]);
	}
		getch();

}

WAP to delete element from array.

//(WAP to delete element from array.)

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

void main()
{
 char ch='y';
 int n,k,a[100],r,i;
 clrscr();
 printf("\nHow many number:");
 scanf("%d",&n);
 for(i=0;i<n;i++)
 {
  printf("\nElement %d:",i+1);
  scanf("%d",&a[i]);
 }
 for(i=0;i<n;i++)
 {
  printf("\n%d",a[i]);
 }

 while(ch=='y')
 {
  printf("\nEnter number which you want to delete:");
  scanf("%d",&r);
        for(i=0;i<n;i++)
  {
   if(a[i]==r)
   {
    k=r;
   }
  }
  for(i=k-1;i<=n-1;i++)
  {

   a[i]=a[i+1];
  }
  n=n-1;
  for(i=0;i<n;i++)
  {
   printf("\n%d",a[i]);
  }
  printf("\nDo you want to continue y or n:");
  fflush(stdin);
  scanf("%c",&ch);
 }
 getch();
}

WAP that will take 10 number from user and print it on output

//WAP that will take 10 number from user and print it on output

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