Tuesday 9 December 2014

program to check various conditions
#include<stdio.h>
#include<stdlib.h>
main()
{
int choice;
printf("program to check various operations:1:prime\n 2:evenodd\n 3:swapping\n 4:sign_check\n");
scanf("%d",&choice);
switch(choice)
{
case 1:
printf("perform prime number series\n");
prime();
break;
case 2:
printf("to check even or odd\n");
evenodd();
break;
case 3:printf("swapping operation...\n");
swapping();
break;
case 4: printf("to check sign..\n");
sign();
break;
default:printf("enter correct choice\n");
}
printf("your task successfully completed\n");
}
prime()
{
int n,i;
printf("enter value for n:\n");
scanf("%d",&n);
for(i=0;i<n;i++)
{
if(i%2!=0)
{
printf("%d\n",i);
}
}
}
evenodd()
{
int n;
printf("enter value for n\n");
scanf("%d",&n);
if(n%2==0)
{
printf("even number\n");
}
else
{
printf("odd number\n");
}
}
swapping()
{
int a,b,c;
printf("enter values for a and b\n");
scanf("%d%d",&a,&b);
c=a;
a=b;
b=c;
printf("after swapping a and b values are %d\t%d\n",a,b);
}
sign()
{
int n;
printf("enter value for n");
scanf("%d",&n);
if(n>0)
printf("positive number\n");
else
printf("negative number\n");
}
OutPut:
madan@madan-Lenovo-G570:~/madan$ ./a.out
program to check various conditions:1:prime
 2:evenodd
 3:swapping
 4:sign_check
2
to check even or odd
enter value for n
45
odd number
your task successfully completed
madan@madan-Lenovo-G570:~/madan$ ./a.out
program to check various conditions:1:prime
 2:evenodd
 3:swapping
 4:sign_check
3
swapping operation...
enter values for a and b
54
675
after swapping a and b values are 675 54
your task successfully completed
madan@madan-Lenovo-G570:~/madan$ ./a.out
program to check various conditions:1:prime
 2:evenodd
 3:swapping
 4:sign_check
4
to check sign..
enter value for n-567
negative number
your task successfully completed