Questions on Arithmetic operators
1. A computer programming contest requires teams of 5 members each.
Write a program that asks for the number of players and then give
the number of teams and number of players leftover?
2. Find the number of months and leftover when the number of days
are given (assume each month has only 30 days)
3. https://www.hackerrank.com/challenges/combo-meal/submissions/code/112740245
4. Number of questions on modulus operator can be explained
Questions on Assignment operator
Explanation: different types of assignments a =10, a =b, a= b+c
1. Swap two variables
Questions on Logical Operators
// Input an integer number and check whether
// it is divisible by 9 or 7.
#include <stdio.h>
int main()
{
int num;
//input number
printf("Enter an integer number: ");
scanf("%d", &num);
//check the condition
if(num%9==0 || num%7==0)
printf("%d is divisible by 9 or 7\n",num);
else
printf("%d is not divisible by 9 or 7\n",num);
return 0;
}
// Input gender in single character and print full gender
// (Ex: if input is 'M' or 'm' - it should print "Male").
#include <stdio.h>
int main()
{
char gender;
//input gender
printf("Enter gender (m/M/f/F): ");
scanf("%c", &gender);
//check the condition and print gender
if(gender=='m' || gender=='M')
printf("Gender is Male");
else if(gender=='f' || gender=='F')
printf("Gender is Female");
else
printf("Unspecified gender");
return 0;
}
No comments:
Post a Comment