C Programs Example 4

27.     Write a program to check that he or she can vote.

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

void main()
{
          int age;
          clrscr();
          printf("Enter your age");
          scanf("%d",&age);

          if(age>=18)
          {
                   printf("He or she can vote");
          }
          getch();
}       

28.     Write a program to check that he or she can vote or not.

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

void main()
{
          int age;
          clrscr();
          printf("Enter your age");
          scanf("%d",&age);

          if(age>=18)
          {
                   printf("He or she can vote");
          }
          else
          {
                   printf("He or she cannot vote");
          }
          getch();
}       


29.     Describe steps for algorithm, draw a flow chart and write a program to check that year is leap year or not.

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

void main()
{
          int year;
          clrscr();
          printf("Enter year");
          scanf("%d",&year);
         
          if(year%4==0)
          {
                   printf("Leap Year");
          }
          else
          {
                   printf("Not Leap Year");        
          }
          getch();
}       

30.     Describe steps for algorithm, draw a flow chart and write a program to check that the number is positive number or negative number.

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

void main()
{
          int no;
          clrscr();
          printf("Enter number");
          scanf("%d",&no);
         
          if(no>0)
          {
                   printf("Positive number");
          }
          else
          {                
                   printf("Negative number");
          }
          getch();
}       


31.     Describe steps for algorithm, draw a flow chart and write a program to find out that the entered number is odd or even.

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

void main()
{
          int no;
          clrscr();
          printf("Enter number");
          scanf("%d",&no);
         
          if(no%2==0)
          {
                   printf("Even number %d",no);
          }
          else
          {       
                   printf("Odd number %d",no);
          }
          getch();
}       

32.     Write a program to find out that the entered number is positive no or negative no or zero.

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

void main()
{
          int no;
          clrscr();
          printf("Enter number");
          scanf("%d",&no);
         
          if(no>0)
          {
                   printf("Positive number");
          }
          if(no<0)
          {
                   printf("Negative number");
          }
          if(no==0)
          {
                   printf("zero");
          }
          getch();
}       

33.     Write a program to find out large number from any two numbers.

#include<stdio.h>
#include<conio.h>
void main()
{
          int a,b;
          clrscr();
          printf("Enter first value");
          scanf("%d",&a);
          printf("Enter second value");
          scanf("%d",&b);
          if(a>b)
          {
                   printf(" a is big %d",a);
          }
          else
          {
                   printf("b is big %d",b);
          }
          getch();


34.     Describe steps for algorithm, draw a flow chart and write a program to find out largest number from any three numbers.

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

void main()
{
          int a,b,c;
          clrscr();
          printf("Enter first value");
          scanf("%d",&a);
          printf("Enter second value");
          scanf("%d",&b);
          printf("Enter third value");
          scanf("%d",&c);

          if(a>b)
          {
                   if(a>c)
                   {
                             printf("a is big");
                   }
                   else
                   {
                             printf("c is big");
                   }
          }
          else
          {
                   if(b>c)
                   {
                             printf("b is big");
                   }
                   else
                   {
                             printf("c is big");
                   }
          }
          getch();

}        

Comments

Popular posts from this blog

પટેલ સમાજનો ઈતિહાસ જાણો : કોણ અને ક્યાંથી આવ્યા હતા પાટીદારો

Python HTML Generator using Yattag Part 1

Java Event Delegation Model, Listener and Adapter Classes