Professional Documents
Culture Documents
/* q.1
following is the menu to be displayed to the user.
on selecting a choice display appropriate result.
the number should be accepted from the user.
menu
1. prime factors
2. leap year
3. sum of all digits
4. number in reverse order
*/
#include<stdio.h>
#include<conio.h>
void main()
{
int c,n;
int m;
int sum=0;
clrscr();
switch(c)
{
case 1:
if (n==0)
{
printf(" 0 \n \n");
}
else if (n==1)
{
printf(" 1 \n \n");
}
else
{
printf("\b \n \n "); /*delete the extra 'x' left
in the end*/
}
break;
case 2:
if(n%100==0)
{
if(n%400==0)
{
printf("\n this is a leap year");
}
else
printf("\n this is not a leap year");
}
else
{
if(n%4==0)
{
printf("\n this is a leap year");
}
else
printf("\n this is not a leap year");
}
break;
case 3:
while(n!=0)
{
m=n%10;
n=n/10;
sum=sum+m;
}
printf("\n sum of digits is %d ",sum);
break;
case 4:
printf("\n number in reverse order is ");
while(n!=0)
{
m=n%10;
n=n/10;
printf("%d",m);
}
break;
default:
printf("\n wrong choice");
break;
}
getch();
if (primecheck != 0 )
primestat = 't'; /*the number is
prime*/
else /*(so far)*/
{
primestat = 'f'; /*the number is
not prime*/
break;
}
remainder = num%prime;
/*
----------------------------------------------------------------------------------
output
----------------------------------------------------------------------------------
select a choice from the menu
1. prime factors
2. leap year
3. sum of all digits
4. number in reverse order
----------------------------------------------------------------------------------
----------------------------------------------------------------------------------
-
select a choice from the menu
1. prime factors
2. leap year
3. sum of all digits
4. number in reverse order
sum of digits is 10
----------------------------------------------------------------------------------
--
select a choice from the menu
1. prime factors
2. leap year
3. sum of all digits
4. number in reverse order
your choice from the menu 4
==================================================================================
==
*/
/* q.2
perform the folloeing operation on integer array of 10 elements.
accept values fom the user.
1. sort an array in ascending order
2.display sum of all odd values stored in an array
3.display number of even values stored in an array
*/
#include<conio.h>
#include<stdio.h>
void main()
{
int a[10],b[10],i,j,k,n,t,sum,count;
clrscr();
printf("enter 10 numbers\n");
for(i=0;i<10;i++)
{
scanf("%d",&a[i]);
}
printf("enter your choice\n"
"1.sort an array in ascending order\n"
"2.display sum of all odd values\n"
"3.display number of even values\n");
printf("\n your choice ");
scanf("%d",&n);
printf("\n");
switch(n)
{
case 1:
for(j=0;j<9;j++)
{
for(k=j+1;k<10;k++)
{
if(a[j]>a[k])
{
t=a[j];
a[j]=a[k];
a[k]=t;
}
}
}
printf("numbers after sorting\n");
for(i=0;i<10;i++)
{
printf("%d ",a[i]);
}
break;
case 2:
sum=0;
for(i=0;i<10;i++)
{
if((a[i]%2)!=0)
sum=sum+a[i];
}
printf("sum of odd numbers is: ");
printf("%d",sum);
break;
case 3:
count=0;
for(i=0;i<10;i++)
{
if(a[i]%2==0)
{
count++;
b[count]=a[i];
}
}
printf("there are %d even numbers\n",count);
printf("the even numbers are:");
for(i=1;i<=count;i++)
{
printf("%d ",b[i]);
}
break;
default:
printf("wrong choice");
}
getch();
}
/*
--------------------------------------------------------------------
output
--------------------------------------------------------------------
enter 10 numbers
22
55
99
345
5623
789
356
763
2
67
enter your choice
1.sort an array in ascending order
2.display sum of all odd values
3.display number of even values
your choice 1
---------------------------------------------------------------------
enter 10 numbers
10
20
34
76
097
54
356
72
679
55
enter your choice
1.sort an array in ascending order
2.display sum of all odd values
3.display number of even values
your choice 2
----------------------------------------------------------------------
enter 10 numbers
1
2
3
4
5
6
67
8
9
7
enter your choice
1.sort an array in ascending order
2.display sum of all odd values
3.display number of even values
your choice 3
=======================================================================
*/