0% found this document useful (0 votes)
30 views4 pages

Aryan C Program

The document contains code snippets for several C programs that: 1) Check if a number is prime by testing if it is only divisible by 1 and itself. 2) Accept input of integers into an array and find the maximum and minimum values. 3) Accept a string as input and count the number of vowels. 4) Add two 2D arrays and store the result in a 3D array. 5) Display a 1D array in reverse order.

Uploaded by

Hunny Gupta
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
30 views4 pages

Aryan C Program

The document contains code snippets for several C programs that: 1) Check if a number is prime by testing if it is only divisible by 1 and itself. 2) Accept input of integers into an array and find the maximum and minimum values. 3) Accept a string as input and count the number of vowels. 4) Add two 2D arrays and store the result in a 3D array. 5) Display a 1D array in reverse order.

Uploaded by

Hunny Gupta
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 4

A Prime Number can be divided evenly only by 1, or itself.

And
it must be a whole number greater than 1. Example: 5 can only
be divided evenly by 1 or 5, so it is a prime number.
#include<stdio.h>
#include<conio.h>
int main()
{
int num,n,div,p;
printf("Enter any number: ");
scanf("%d", &num);
for(n=2; n<=num; n++)
{
for(div=2; div<n; div++)
{
if(n%div==0)
{
p=0;
break;
}
p=1;
}
if(p)
printf("\t%d",n);
}
getch();
return 0;
}
------------------------------------------------------------write a program to accept five integer value from the user and
store it in an array. also display the maximum and minimum
value
#include<stdio.h>
#include<conio.h>
#include<string.h>
void main()
{
int i, n ,max=0,min=0;
int a[100];
clrscr();
printf("Enter the limit:\n");
scanf("%d",&n);
printf("Enter the Value:\n");

for(i=0;i<n;i++)
{
scanf("%d",&a[i]);
}
max=min=a[0];
for(i=0;i<n;i++)
{
if(a[i]>max)
max=a[i];
if(a[i]<min)
min=a[i];
}
printf("\nmaximum=%d\n\nminimum=%d",max,min);
getch();
}
-------------------------------------------------------------

write a program to accept a string from the user and display


vowels
#include<stdio.h>
#include<conio.h>
void main()
{
char ch[10];
int i,count=0;
clrscr();
printf("Enter the string\n");
gets(ch);
for(i=0;ch[i]!='\0';i++)
{
if(ch[i]=='a' || ch[i]=='e' || ch[i]=='i' || ch[i]=='o'
|| ch[i]=='u')
{
count++;
}
}
printf("Vowels = %d",count);
getch();
}

write a c program TO ADD two dimensional array and store the


result in third dimensioal array

#include<stdio.h>
#include<conio.h>
void main()
{
int a[3][3],b[3][3], sum[3][3], i=0, j=0;
clrscr();
printf("Enter the elements of the first array :");
for (i=0;i<=2 ;i++ )
{
for(j=0; j<=2; j++)
{
scanf("%d\n", &a[i][j]);
printf("\n");
}
}
printf("Enter the elements of the second array :")
for(i=0; i<=2; i++)
{
for(j=0; j<=2; j++)
{
scanf("%d", &b[i][j]);
}
}
/*Now placing the sum of the two matrices in the third one */
for (i=0;i<=2 ;i++ )
{
for(j=0; j<=2; j++)
{
sum[i][j] = a[i][j] + b[i][j];
}
}
/* Now displaying the sum of the two matrices by following code
snippet */
printf("\nThe sum of the matrices obtained is as follows :");
for(i=0; i<=2; i++)
{
for(j=0; j<=2; j++)
{
printf("\n%d", sum[i][j]);
printf("\n");
}
}
getch();
}

display the single dimensional array in reverse order


#include<stdio.h>
int main() {
int arr[30], i, j, num, temp;
printf("\nEnter no of elements : ");
scanf("%d", &num);
//Read elements in an array
for (i = 0; i < num; i++) {
scanf("%d", &arr[i]);
}
j = i - 1;
i = 0;

// j will Point to last Element


// i will be pointing to first element

while (i < j) {
temp = arr[i];
arr[i] = arr[j];
arr[j] = temp;
i++;
// increment i
j--;
// decrement j
}
//Print out the Result of Insertion
printf("\nResult after reversal : ");
for (i = 0; i < num; i++) {
printf("%d \t", arr[i]);
}
return (0);
}

You might also like