Last active
May 24, 2019 17:46
-
-
Save brunokiafuka/3015fae2e0cdac8075773cc360cccd62 to your computer and use it in GitHub Desktop.
C Basic programs
This file contains 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> | |
int main() | |
{ | |
//declarar var | |
int opt; | |
float avg = 0; | |
float total = 0; | |
float num = 0; | |
int count = 0; | |
//1. initialize sentinel | |
printf("Click 1 continue or 0 to stop >> "); | |
scanf("%d", &opt); | |
while (opt != 0){//2. test sentinel against condition | |
//some code | |
printf("Insert mark >> "); | |
scanf("%f", &num); | |
total = num + total; | |
count++; | |
//3. update sentinel | |
printf("Click 1 continue or 0 to stop >> "); | |
scanf("%d", &opt); | |
} | |
avg = total / count; | |
printf("Your avg is %f", avg); | |
return 0; | |
} |
This file contains 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
//Basic sum | |
#include <stdio.h> | |
int | |
main () | |
{ | |
/* variable definition: */ | |
int num1, num2; | |
int sum; | |
/* actual initialization */ | |
printf ("Insira o primeiro >> "); | |
scanf ("%d", &num1); | |
printf ("Insira o segundo >> "); | |
scanf ("%d", &num2); | |
//processing | |
sum = num1 + num2; | |
//output | |
printf ("value of c : %d \n", sum); | |
return 0; | |
} |
This file contains 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
//Números pares | |
#include <stdio.h> | |
int | |
main () | |
{ | |
/* variable definition: */ | |
int num1, num2; | |
int sum; | |
/* actual initialization */ | |
printf ("Insira o primeiro >> "); | |
scanf ("%d", &num1); | |
printf ("Insira o segundo >> "); | |
scanf ("%d", &num2); | |
//processing | |
sum = num1 + num2; | |
if (sum % 2 == 0){ | |
printf ("%d é um número par", sum); | |
} else{ | |
printf ("%d é um número impar", sum); | |
} | |
return 0; | |
} |
This file contains 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
//Positive or Negative | |
#include <stdio.h> | |
void main() | |
{ | |
int num; | |
printf("Input um número >> "); | |
scanf("%d", &num); | |
if (num >= 0){ | |
printf("%d número é positivo \n", num); | |
} | |
else{ | |
printf("%d número é negativo \n", num); | |
} | |
return 0; | |
} |
This file contains 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
/*Temp < 0 clima gelado | |
Temp 0-10 then clima muito frio | |
Temp 10-20 then clima frio | |
Temp 20-30 then clima normal | |
Temp 30-40 then clima quente | |
Temp >=40 then Its clima muito quente */ | |
//Tem check | |
#include <stdio.h> | |
void | |
main () | |
{ | |
int tmp; | |
printf ("Input temp >> "); | |
scanf ("%d", &tmp); | |
if (tmp < 0) | |
{ | |
printf ("Clima gelado.\n"); | |
} | |
else if (tmp < 10) | |
{ | |
printf ("Clima muito frio.\n"); | |
} | |
else if (tmp < 20) | |
{ | |
printf ("Clima frio.\n"); | |
} | |
else if (tmp < 30) | |
{ | |
printf ("Clima normal.\n"); | |
} | |
else if (tmp < 40) | |
{ | |
printf ("Clima quente.\n"); | |
} | |
else | |
{ | |
printf ("Clima muito quente.\n"); | |
} | |
return 0; | |
} |
This file contains 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> | |
int main() | |
{ | |
int num = 0;//1. initialize sentinel | |
while (num != 10){//2. test sentinel against condition | |
//some code | |
printf("%d \n", num); | |
num = num + 1;//3. update sentinel | |
} | |
printf("done!"); | |
return 0; | |
} |
This file contains 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> | |
int main() | |
{ | |
//declarar var | |
int opt; | |
//1. initialize sentinel | |
printf("Click 1 continue or 0 to stop >> "); | |
scanf("%d", &opt); | |
while (opt != 0){//2. test sentinel against condition | |
//some code | |
printf("Let's continue..."); | |
//3. update sentinel | |
printf("Click 1 continue or 0 to stop >> "); | |
scanf("%d", &opt); | |
} | |
printf("You decided to stop!"); | |
return 0; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment