Created
April 18, 2023 09:17
-
-
Save isaacssemugenyi/d72e18fe6538ddf485ac8df52e539df6 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include<stdio.h> | |
// WWrite a C program to display the following output: 20 40 60 80 100 120 | |
int main () | |
{ | |
int integer = 20; | |
while(integer <= 120){ | |
printf("\t%d", integer); | |
integer+=20; | |
} | |
return 0; | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include<stdio.h> | |
// Write a C program to display all even numbers between 39 and 65 | |
int main () | |
{ | |
int even_odd_number = 39; | |
for (int index = 39; index <= 65; index++) | |
{ | |
if(even_odd_number % 2 == 0) | |
{ | |
printf("\n%d", even_odd_number); | |
} | |
even_odd_number++; | |
} | |
return 0; | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include<stdio.h> | |
// Write a program to calculate the factorial of any given positive integer | |
int calculate_factorial(int number); | |
int main () | |
{ | |
calculate_factorial(-1); | |
return 0; | |
} | |
int calculate_factorial(int number){ | |
int fact_number = 1; | |
if(number < 0) return printf("An invalid number supplied"); | |
if(number == 0) return printf("%d", 1); | |
if(number == 1) return printf("%d", 1); | |
int iterator = number; | |
for(int index = 1; index < number; index++){ | |
fact_number *= iterator; | |
iterator--; | |
} | |
printf("%d", fact_number); | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include<stdio.h> | |
// Write a C program to display all the integers from 140 to 161 | |
int main () | |
{ | |
int number = 140; | |
for (int index = 140; index <= 161; index++) | |
{ | |
printf("\n%d", number); | |
number++; | |
} | |
return 0; | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include<stdio.h> | |
// Write a C program that displays all odd numbers between 14 and 45 | |
int main () | |
{ | |
int even_odd_number = 14; | |
for (int index = 14; index < 45; index++) | |
{ | |
if(even_odd_number % 2 != 0) | |
{ | |
printf("\n%d", even_odd_number); | |
} | |
even_odd_number++; | |
} | |
return 0; | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include<stdio.h> | |
// Write a C program to display all the integers from 59 to 99 | |
int main () | |
{ | |
int integer = 59; | |
while(integer <= 99){ | |
printf("\n%d", integer); | |
integer++; | |
} | |
return 0; | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include<stdio.h> | |
// Write a C program that computes the sum of all odd numbers between 98 and 120 | |
int main () | |
{ | |
int current = 98; | |
int sum = 0; | |
while(current < 120){ | |
if(current % 2 != 0) | |
{ | |
sum += current; | |
} | |
current++; | |
} | |
printf("%d", sum); | |
return 0; | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// Write a program to compute the sum of all integers from 52 to 69 | |
int main () | |
{ | |
int sum_of_integers = 0; | |
for (int current = 52; current <= 69; current++) | |
{ | |
sum_of_integers += current; | |
} | |
printf("%d", sum_of_integers); | |
return 0; | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include<stdio.h> | |
// Modify Program above such that it computes the sum of all the odd numbers from 45 to 80 | |
int main () | |
{ | |
int sum_of_odd_number = 0; | |
for (int index = 45; index < 80; index++) | |
{ | |
if(index % 2 != 0) | |
{ | |
sum_of_odd_number += index; | |
} | |
} | |
printf("\n%d", sum_of_odd_number); | |
return 0; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment