Uploaded by natrice campbell

C PROGRAM SOLUTIONS

advertisement
C PROGRAM SOLUTIONS
1. Write a C program to print your name, date of birth. and mobile number.
include <stdio.h>
int main()
{
printf("Name : Alexandra Abramov\n");
printf("DOB : July 14, 1975\n");
printf("Mobile_number : 99-9999999999\n");
return(0);
}
2. Write a C program to read the age of a candidate and determine whether it is eligible for
casting his/her own vote.
#include <stdio.h>
void main()
{
int v_age;
printf("Enter the age of the candidate : ");
scanf("%d",&v_age);
if (v_age<18)
{
printf(" I am sorry, you are not eligible to cast your vote.\n");
printf("You would be able to cast your vote after %d year.\n",18-v_age);
}
Else
printf("Congratulation! You are eligible for casting your vote.\n");
}
3. Write a C program to input a year and check whether year is leap year or not using conditional
operator
#include <stdlib.h>
int main (){
int year;
printf ("Enter a year to check I whether or not it is leap year \n");
scanf ("%d", &year);
printf ("%s", ((year%4==0 && year%100!=0) ?
"LEAP YEAR”: (year%400 ==0 ) ?
"IS A LEAP YEAR”: "NOT A LEAP YEAR")).
return 0;}
4. Write a c program to find the Modulus of two numbers:
#include<stdio.h>
int main()
{
int num1, num2, remainder;
printf("Enter the dividend: ");
scanf("%d", &num1);
printf("Enter the divisor: ");
scanf("%d", &num2);
remainder= num1 % num2;
printf("The Remainder is = %d", remainder);
return 0;
}
5. Write a c program to find the Product of two numbers:
#include <stdio.h>
int main() {
int num1,num2, product;
printf("Enter two numbers: ");
scanf("%d %d", &num1, &num2);
product = num1*num2;
printf("The product is:", product);
return 0;
}
6. Write an algorithm of ATM Machine Working process.
WHILE TRUE
PRINT "Welcome to VMBS ATM Machine - Cash Withdrawal"
amount = ENTER “How much money you would like to withdraw today?"
IF (amount MOD 5)!= 0 THEN
PRINT "You can only withdraw a multiple of FIVE"
ELSE
IF amount<5 OR amount>100 THEN
PRINT "You can only withdraw between 5 and 100"
ELSE
notes10 = amount DIV 10
notes5 = (amount MOD 10) / 5
PRINT “Please collect your money: "
PRINT"
>> 10 Banknotes: " + notes10
PRINT"
>> 5 Banknotes: " + notes5
PRINT "Thank you for using VMBS ATM."
DISPLAY "Goodbye."
END IF
END IF
END WHILE
STEP BY STEP PROCESS
•
•
•
•
•
•
•
•
•
•
Go to the atm
Insert debit card in the atm machine
Enter the pin assigned to the card for the atm to read it
Select the option withdrawal
Select or enter the account from which to withdraw cash
Enter the amount for withdrawal
Press ok for transaction to be processed by the ATM machine
ATM disperse cash
Collect cash
Card ejected
Download