## Ç language program

1 . Write a program to accept number of seconds and display its corresponding hours, minutes and seconds. #include #include void main() { int sec,h,m,s; clrscr(); printf(“Enter seconds : “); scanf(“%d”,&sec); h = (sec/3600); m = (sec – (3600*h))/60; s = (sec – (3600*h)-(m*60)); printf(“%d:%d:%d”,h,m,s); getch(); }

2. Write a C program to find the maximum from given three numbers (Using Nested IF). #include #include void main() { int num1,num2,num3; clrscr(); printf(“Enter three numbers “); scanf(“%d%d%d”,&num1,&num2,&num3); if(num1>num2) { if(num1>num3) { printf(“\n Num1 is max : %d”,num1); } else { printf(“\n Num3 is max : %d”,num3); } } else { if(num2>num3) { printf(“\n Num2 is max : %d”,num2); } else { printf(“\n Num3 is max : %d” , num3); } } getch(); }

3. Write a C program to find that the accepted no is Negative, Positive or Zero. #include #include void main() { int num; clrscr(); printf(“Enter Number : “); scanf(“%d”,&num); if(num>=0) { if(num>0) { printf(“Number is Positive : %d”,num); } else { printf(“Number is Zero : %d”,num); } } else { printf(“Number is Negative : %d”,num); } getch(); }

4. Write a program to check given year is a Leap year or not. #include #include void main() { int year; clrscr(); printf(“\n Enter year : “); scanf(“%d”,&year); if(year%4==0) { printf(“\n Year is leap year %d”,year); } else { printf(“It Year is not leap year %d”,year); } getch(); }

5. Write a C program to find minimum from given 3 numbers (Using Conditional Operator). #include #include void main() { int ans,num1,num2,num3; clrscr(); printf(“Enter number 1,2,3 : “); scanf(“%d%d%d”,&num1,&num2,&num3); ans=((num1<num2)?((num1<num3)?num1:num3):((num2<num3)?num2:num3)); printf(“Minimum number is : %d”,ans); getch(); }

6. Write a C program to find the maximum from given three numbers (Without using Nested if, or Logical Operator, Or Conditional operators). #include #include void main() { int max,num1,num2,num3; clrscr(); printf(“Enter number 1 , 2 ,3 :”); scanf(“%d%d%d”,&num1,&num2,&num3); max=num1; (max<num2)&&(max=num2); (max<num3)&&(max=num3); printf(“The maximum number is : %d”,max); getch(); }

7. Take marks from the user and print grade accordingly( >=75 marks – Distinction, <75 and >=60 marks – First, <60 and >=50 – Second, <50 and >=35 – Pass, <35 – Fail) using if … else if….else statement and also by using logical operators) #include #include void main() { int mark; clrscr(); printf(“Enter Marks : “); scanf(“%d”,&mark); if(mark>=75) printf(“This is disinction”); else if(mark>=60) printf(“This is first class”); else if(mark>=50) printf(“This is second class”); else if(mark>=35) printf(“Your is Pass Maks”); else printf(“Your Fail”); getch(); }

8. Take 2 numbers from the user and print the greater number (Number can be equal). #include #include void main() { int num1,num2; clrscr(); printf(“Enter Number 1 :”); scanf(“%d”,&num1); printf(“Enter Number 2 : “); scanf(“%d”,&num2); if(num1=num2) { if(num1>num2) { printf(“\n number 1 is Maximum : %d”,num1); } else { printf(“\n number1 and number 2 is Equal %d – %d”,num1,num2); } } else { printf(“\n number 2 is Maximum : %d”,num2); } getch();

} 9. Write a program to check whether the blood donor is eligible or not for donating blood. The conditions laid down are as under. Use if statement. a) Age should be above 18 yrs but not more than 55 yrs. #include #include void main() { int age; clrscr(); printf(“\nEnter age of blood donor\n”); scanf(“%d”,&age); if(age>18 && age<=55) printf(“\n The age of blood donor is %d and is eligible”,age); else printf(“The age of blood donor is %d and not eligible”,age); getch(); }

10. Write a program to calculate bill of a job work done as follows. Use if else statement. a) Rate of typing 3 Rs/page b) Printing of 1st copy 5Rs/pages & later every copy 3Rs/page. The user should enter the number of pages and print out copies he/she wants #include #include void main() { int pages,copies; long int bill; clrscr(); printf(“Enter number of pages and copies of print outs”); scanf(“%d%d”,&pages,&copies); bill=(pages*3)+((copies-1)*3*pages)+(pages*5); printf(“The bill amount is %ld”,bill); getch(); }