রবিবার, ১২ ডিসেম্বর, ২০১০

Conditional C Program


1.Three  numbers are input through keyboard, write a program to find  out  the maximum  and minimum  of these  3  numbers.
#include<stdio.h>
#include<conio.h>
#include<math.h>
void main()
{
            int a,b,c;
            float aver;
            double s;
            clrscr();
            printf("Please enter three different inteser :\n");
            scanf("%d%d%d", &a,&b,&c);
            if(a>b && b>c && b>c)
                        printf("\n%d is maximum & %d is minimum .",a,c);
            else if(a>b && c>b && a>c)
                        printf("\n%d is maximum & %d is minimum .",a,b);
            else if(c>a && a>b && c>b)
                        printf("\n%d is maximum & %d is minimum .",c,b);
            else if(b>a && b>c && a>c)
                        printf("\n%d is maximum & %d is minimum .",b,c);
            else if(b>c && b>a && c>a)
                        printf("\n%d is maximum & %d is minimum .",b,a);
            else
                        printf("\n%d is maximum & %d is minimum .",c,a);
            getch();
}
2.Take a year as input and determine whether it is a leap year.
#include<stdio.h>
#include<conio.h>
void main()
{
      int year;
      clrscr();
      printf("Please enter a year to teste for leap year : ");
      scanf("%d", &year);
      if((year%4==0 && year%100 !=0)|| year%400==0)
          printf("\n%d is a leap year.",year);
      else
          printf("\n%d is not a leap year.",year);
      getch();
}

6.A 5 digit number is input through the keyboard, write a program to reverse the number and cheak it if it is equal to the original number.
#include<stdio.h>
#include<conio.h>
#include<math.h>
void main()
{
            Long int n,a[50];
            long sum=0;
            clrscr();
          while(n!=0)
                {
                a[i]=n%10;
                n=n/10;
                i++;
}
                for(j=0;j<i;j++)
                {
                sum+=a[i-j-1]*pow(10,j);
                }
                printf(“Reverse number is %d : “,sum);
                if(b==sum)
                printf(“Equal to the main number.”);
                else
printf(“Not equal to the main number.”);
getch();
}


 (ii)7 + 20 + 33 + .. .   ( up to nth term )
#include<stdio.h>
#include<conio.h>
void main()
{
            long int a,n,i,j;
            long sum = 0,term;
            clrscr();
          printf("Sum of serises : ");
printf("\n\7 + 20 + 33 + .. .   ( up to nth term ));
printf("\n\nEnter a value for n : ");
            scanf("%d",&n);
            for(i=0;i<=n;i=i++)
                 {
                        term=5+(i*6);
sum = sum+i;
                 }
            printf("sum = %ld",sum);
            getch();
}










3.If cost price and selling price of an item is input through the keyboard, write a program to determine whether the seller has made profit or incurred loss. Also determine how much he made or loss he incurred.
#include<stdio.h>
#include<conio.h>
void main()
{             float a,b;
            long float p,l;
            clrscr();
            printf("Enter cost price(In TK) : ");
            scanf("%f",&a);
            printf("Enter selling price(In TK) : ");
            scanf("%f",&b);
            p = ((b-a)/a)*100.00;
            l = ((a-b)/a)*100.00;
            if(a<b)
            printf("\nHe made a profit.");
            else if(b<a)
            printf("\nHe made a loss .");
            else
            printf("\nHe neither made a profit nor a loss .");
           
if(a<b)
            printf("\nHe made %.2lf percent profit .",p);
            else if(a>b)
            printf("\nHe made %.2lf percent loss .",l);
            else
            getch();
}
4.Any integer is input through keyboard. Write a program to find out whether it is an odd number or even number.
#include<stdio.h>
#include<conio.h>
void main()
{
            long int n;
            clrscr();
            printf("Enter a intger number to be tested for even or odd nunber : ");
            scanf("%ld",&n);
            if(n%2==0)
                 printf("\n%ld is enen number .",n);
            else
                 printf("\n%ld is odd number .",n);
            getch();
}
5.According to Gregorian calendar, it was Monday on the date 01/01/1900. If any year is input through the keyboard write a program to find out what is the day on 1st January of this year.
#include<stdio.h>
#include<conio.h>
void main()
{
            unsigned int days;
            int year,n=0, yr,i;
            clrscr();
            printf("Enter the year:");
            scanf ("%d", &year);
            for(i=1900;i<year;i++)
            {
                if((i%4==0 && i%100 !=0)|| i%400==0)
                        n=n+1;
                else
                        n=n+0;
            }
            yr=(n+(year-1900));
            days = (yr*365);
            if (days%7 == 0)
            printf("The day on Jan 1st of this year is Monday");
            else if (days%7 == 1)
            printf("The day on Jan 1st of this year is Tuesday");
            else if (days%7 == 2)
            printf("The day on Jan 1st of this year is Wednesday");
            else if (days%7 == 3)
            printf("The day on Jan 1st of this year is Thursday");
            else if (days%7 ==4)
            printf("The day on Jan 1st of this year is Friday");
            else if (days%7 ==5)
            printf("The day on Jan 1st of this year is Saturday");
            else if (days%7 ==6)
            printf("The day on Jan 1st of this year is Sunday");

getch();
}


7.AUST grading policy is :
(i)           80% marks or above is A+
(ii)         75% to 79% marks is A
(iii)       70% to 74% marks is A-
(iv)        65% to 69% marks is B+
(v)         60% to 64% marks is B
(vi)        55% to 59% marks is B-
(vii)      50% to 54% marks is C+
(viii)    45% to 44% marks is C
(ix)       40% to 44% marks is D
(x)         Below 40% is F
Write a program which will take an input from user and calculate the grade of a student according to AUST  grading policy based on that input.
#include<stdio.h>
#include<conio.h>
void main()
{
            float marks;
            clrscr();
            printf("Input marks that obtained : ");
            scanf("%f", &marks);
            if((marks>100) || (marks<0))
            printf("\nInvalid number");
            else if(marks<40)
            printf("\nGrade = F ");
            else if(marks<45)
            printf("\nGrade = D");
            else if(marks<50)
            printf("\nGrade = C");
            else if(marks<55)
            printf("\nGrade = C+");
            else if(marks<60)
            printf("\nGrade = B-");
            else if(marks<65)
            printf("\nGrade = B");
            else if(marks<70)
            printf("\nGrade = B+");
            else if(marks<75)
            printf("\nGrade = A-");
            else if(marks<80)
            printf("\nGrade = A");
            else
            printf("\nGrade = A+");
            printf("\n\nPress any key for exit...");
            getch();
}
8.A certain grade of steel is graded according to the following conditions:                        
(i)           Hardness must be greater than 60
(ii)         Carbon content must be less than 0.7
(iii)       Tensile strength must be greater than 50000
The grades are as follows :
Grade is 10 if all three conditions are met
Grade is   9 if  condition (i) and (ii) are met
Grade is   8 if  condition (ii) and (iii) are met
Grade is   7 if  condition (i) and (iii) are met
Grade is   6 if only one condition is met
Grade is   5 if none of the conditions are met
Write a program which will require the user to give values of hardness, carbon content and tensile strength of the steel  under consideration and output the grade of the steel.
#include<stdio.h>
#include<conio.h>
void main()
{
            float h,c,t;
            clrscr();
            printf("Enter the value of Hardness of the steel : ");
            scanf("%f",&h);
            printf("\nEnter the value of Carbon content of the steel : ");
            scanf("%f",&c);
            printf("\nEnter the value of Tensile strength of the steel : ");
            scanf("%f",&t);
            if(h>60.00 && c<0.7 && t>5000.00)
            printf("\n\t\tGrade is 10");
            else if(h>60.00 && c<0.7)
            printf("\n\t\tGrade is 9");
            else if(c<0.7 && t>5000.00)
            printf("\n\t\tGrade is 8");
            else if(h>60.00 && t>5000.00)
            printf("\n\t\tGrade is 7");
            else if(h>60.00 || c<0.7 || t>5000.00)
            printf("\n\t\tGrade is 6");
            else
            printf("\n\t\tGrade is 5");
            printf("\n\nPress any key for exit...");
            getch();  }

৩টি মন্তব্য:

  1. 1xbet korean sports betting & casinos - LegalBet
    1xbet korean sports betting & casinos - 1xbet Get the 샌즈카지노 best 제왕카지노 free bets, bonuses and promotions from TOP Online Gaming providers from TOP Online

    উত্তরমুছুন
  2. Best Casino Sites in India (2021) - Lucky Club
    Find the best Casino Sites in 카지노사이트luckclub India (2021) and more in the top list at Luckyclub.live. The best Online Casino Sites in India for Indian players in 2021.

    উত্তরমুছুন