Skip to content

Instantly share code, notes, and snippets.

@isaacssemugenyi
Created April 18, 2023 05:25
Show Gist options
  • Save isaacssemugenyi/7fee510b663804d87d82a8437716a67d to your computer and use it in GitHub Desktop.
Save isaacssemugenyi/7fee510b663804d87d82a8437716a67d to your computer and use it in GitHub Desktop.
Cpp Assignment
#include<stdio.h>
int main() {
int Bal, Interest;
Bal = 300;
Interest = (30 / 100) * Bal;
if(Bal == 100)
{
Bal++;
} else if(Bal == 200) {
Bal += Interest;
} else if(Bal == 300){
Bal *= 2;
} else {
Bal--;
}
printf("Balance is: %d ", Bal);
return 0;
}
/**
* Graduate students undertaking any course must attain at least 60% in order to pass.
Write a C program that displays the message “You have passed the exam!”, if marks
are greater than 60. If not, the program should then display the message “You have
failed!”
*/
#include<stdio.h>
int main ()
{
float marks;
printf("Enter the scored mark:\t");
scanf("%f", &marks);
if(marks > 60)
{
printf("You have passed the exam!");
} else
{
printf("You have failed!");
}
return 0;
}
/**
* Write a complete C program that allows a user to enter an integer value and If the value
is equal to 10, the program outputs “Trying”, if the value is equal to 20, the program
outputs “You are about”, if a variable is equal to 30, the program outputs “Programming
is fun and logic” and if no condition is met, the program outputs “You are in trouble”
*/
#include<stdio.h>
int main() {
int number;
printf("Enter any number: \t");
scanf("%d", &number);
if(number == 10){
printf("\nTrying");
} else if(number == 20) {
printf("\You are about");
} else if(number == 30) {
printf("\Programming is fun and logic");
} else {
printf("\nYou are in trouble");
}
return 0;
}
/**
* Write a program to identify whether a number input from the keyboard is Even or Odd.
If it is even, the program should display the message “Number is Even”, else it should
display “Number is Odd”.
*/
#include<stdio.h>
int main() {
int number;
printf("Enter any number either even or odd: \t");
scanf("%d", &number);
if(number % 2 == 0)
{
printf("\nNumber is Even");
} else {
printf("\nNumber is Odd");
}
return 0;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment