Search This Blog

Wednesday, July 27, 2011

pass,fail,first,distinction


#include <stdio.h>

int
main (void)
{
   /* declarations */
   int marks;
 
   printf ("Calculate my class: ");
   scanf ("%d", &marks);
   printf ("You entered: %d\n", marks );
 


if(marks>45 && marks<=60)
printf("Pass Class\n");
 else
  if(marks>60 && marks<=70)
printf("First Class \n");
else
if(marks>70 && marks<=100)
printf("Distinction\n");
else
if(marks>-1 && marks<=45)
printf("Fail\n");
   return (0);
}

vowel or constant


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


using namespace std;
int main(void)
{
   /* declarations */
 char ch;
 
   printf ("Enter one alphabet : ");
   scanf ("%c", &ch);
   printf ("Alphabet entered: %c\n", ch );
 
   if(ch=='a'||ch=='A'||ch=='e'||ch=='E'||ch=='i'||ch=='I'||ch=='o'||ch=='O'||ch=='u'||ch=='U')
printf("it is a vowel \n");
 else
 
printf("it is a constant \n");

getch();

return (0);
}

leap year or not


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


using namespace std;
int main()
{
   /* declarations */
   int year;
 
   printf ("Enter the year : ");
   scanf ("%d", &year);
   printf ("Year entered: %d\n", year );
 
 
if(year % 4 == 0)
printf("the year is a leap year \n");
 else
 
printf("the year is not a leap year \n");

getch();

return (0);
}

given number is +,- or zero


#include <stdio.h>

int
main (void)
{
   /* declarations */
   int a;
 
   printf ("Enter value of a: ");
   scanf ("%d", &a);
   printf ("You entered: %d\n", a );
 
 
if(a>0)
printf("a is the positive integer \n");
 else
  if(a<0)
printf("a is the negative integer\n");
else
if(a == 0)
printf("a is equal to zero \n");

   return (0);
}

given number is odd or even


#include <stdio.h>

int
main (void)
{
   /* declarations */
   int a;
 
   printf ("Enter value of a: ");
   scanf ("%d", &a);
   printf ("You entered: %d\n", a );
 
   if(a % 2 == 0)
printf("a is an even integer");
else
printf("a is an odd integer\n");
 



   return (0);
}

minimum of 3 numbers


#include <stdio.h>

int
main (void)
{
   /* declarations */
   int a,b,c;
 
   printf ("Enter value of a: ");
   scanf ("%d", &a);
   printf ("You entered: %d\n", a );
 
   printf ("Enter value of b: ");
   scanf ("%d", &b);
   printf ("You entered: %d\n", b );

 printf ("Enter value of c: ");
   scanf ("%d", &c);
   printf ("You entered: %d\n", c );

if(a<b && a<c)
printf("a is lesser than b and c \n");
 else
  if(b<a && b<c)
printf("b is lesser than a and c \n");
else
if(c<a && c<b)
printf("c is lesser than a and b \n");

   return (0);
}

maximum of 3 numbers


#include <stdio.h>

int
main (void)
{
   /* declarations */
   int a,b,c;
 
   printf ("Enter value of a: ");
   scanf ("%d", &a);
   printf ("You entered: %d\n", a );
 
   printf ("Enter value of b: ");
   scanf ("%d", &b);
   printf ("You entered: %d\n", b );

 printf ("Enter value of c: ");
   scanf ("%d", &c);
   printf ("You entered: %d\n", c );

if(a>b && a>c)
printf("a is greater than b and c \n");
 else
  if(b>a && b>c)
printf("b is greater than a and c \n");
else
if(c>a && c>b)
printf("c is greater than a and b \n");

   return (0);
}