Setembro 11, 2008
E com este exercício está concluído o capitulo. Espero que tenham aproveitado. Qualquer comentário ou dica é só mandar.
Abraço,
Fernando
/* 12279.c 20080911 fmc
* Write a program to read two integers with the following significance.
* The first integer value represents a time of day on a 24 hour clock,
* so that 1245 represents quarter to one mid-day, for example.
* The second integer represents a time duration in a similar way, so
* that 345 represents three hours and 45 minutes.
* This duration is to be added to the first time, and the result
* printed out in the same notation, in this case 1630 which is the
* time 3 hours and 45 minutes after 12.45.
* Typical output might be
* Start time is 1415. Duration is 50. End time is 1505.
* There are a few extra marks for spotting.
* Start time is 2300. Duration is 200. End time is 100.
*
* compile: gcc 12278.c -o 12278
*/
#include<stdio.h>
main() {
int inicio,duracao,termino,h_dur,h_start,m_dur,m_start,ter_h,ter_min;
printf("\n\nEntre com o horario de inicio [hhmm]: ");
scanf("%d",&inicio);
printf("\nEntre com a duração [hhmm]: ");
scanf("%d",&duracao);
h_start=inicio/100;
m_start=inicio-(h_start*100);
h_dur=duracao/100;
m_dur=duracao-(h_dur*100);
ter_h=h_start+h_dur;
ter_min=m_start+m_dur;
if (ter_min>59) {
ter_h++;
ter_min=ter_min-60;
}
if (ter_h>23) {
ter_h=ter_h-24;
}
termino=(ter_h*100)+ter_min;
printf("\nInicio %d. Duração %d. Termino %d\n\n",inicio,duracao,termino);
return 0 ;
}
Deixar um comentário » |
Uncategorized |
Link Permanente
Escrito por fcasado
Setembro 11, 2008
/* 12278.c 20080911 fmc
* Given as input an integer number of seconds, print as output the
* equivalent time in hours, minutes and seconds. Recommended output
* format is something like
*
* 7322 seconds is equivalent to 2 hours 2 minutes 2 seconds.
* compile: gcc 12278.c -o 12278
*/
#include<stdio.h>
main()
{
int total,h,m,s;
printf("\n Quantos segundos? ");
scanf("%d",&total);
h=total/3600;
m=(total/60)-(h*60);
s=total-(h*3600)-(m*60);
printf("\n%d segundos é equivalente a %d horas %d minutos %d segundos\n\n",total,h,m,s);
return 0;
}
Deixar um comentário » |
Uncategorized |
Link Permanente
Escrito por fcasado
Agosto 23, 2008
/* 12277.c 20080820 fmc
* Exercise 12277
* Given as input a floating (real) number of centimeters, print out the
* equivalent number of feet (integer) and inches (floating, 1 decimal), with
* the inches given to an accuracy of one decimal place.
* Assume 2.54 centimeters per inch, and 12 inches per foot.
* If the input value is 333.3, the output format should be:
* 333.3 centimeters is 10 feet 11.2 inches.
* compile:
* cc 12277.c -o 12277
*/
#include<stdio.h>
main() {
float cm,pol,pes,pes_fracional,in;
printf("\n\nEntre com o valor em centimetros: ");
scanf("%f",&cm);
// Convertendo centimetros em polegadas pol = cm * 0,3937008
pol=cm*0.3937008;
// Convertendo as polegadas em pés pes=pol/12
pes=pol/12;
// Extraindo a parte inteira do numero
int a = (int)pes;
pes_fracional=pes-a;
// Convertendo a parte fracional de pes em polegadas
in=pes_fracional*12;
printf("\n\n%.1f centimeters is %d feet %.1f inches.s\n\n",cm,a,in);
}
Deixar um comentário » |
Programação |
Link Permanente
Escrito por fcasado
Agosto 23, 2008
Nossa esse eu fiz muito toscamente…
N!=3*2*1=6 possibilidades para os três números
Apenas mostrei as variáveis a,b e c nas diferentes ordens
sei q mais a frente no curso vou aprender a forma correta
de trocar as variáveis usando um array e usar um loop para mostrar
e trocar as variaveis
/* 12275.c 20080815 fmc
* Exercise 12275
* Write a program to read a positive integer at
* least equal to 3, and print
* out all possible permutations of three positive integers less or equal to
* than this value.
* compile:
* cc 12275.c -o 12275
*/
#include<stdio.h>
main()
{
int a,b,c,i;
i=6;
inicio:
printf("\nEntre um número inteiro positivo maior ou igual a três:");
scanf("\%d",&c);
if (c<3)
{
printf("\nValor invalido digite novamente!\n");
goto inicio;
}
else
{
c=c-1;
b=c-1;
a=b-1;
}
printf("\n\n\t{ [%d], [%d], [%d] }\n",a,b,c);
printf("\t{ [%d], [%d], [%d] }\n",a,c,b);
printf("\t{ [%d], [%d], [%d] }\n",b,c,a);
printf("\t{ [%d], [%d], [%d] }\n",b,a,c);
printf("\t{ [%d], [%d], [%d] }\n",c,a,b);
printf("\t{ [%d], [%d], [%d] }\n\n",c,b,a);
}
Deixar um comentário » |
Programação |
Link Permanente
Escrito por fcasado
Agosto 20, 2008
Estes primeiros exercicios me pareceram simples. Só para constar estou usando como ambiente o Debian “Etch” e como IDE o Anjuta + gcc. Se alguem tiver sugestões de ambiente/IDE é só mandar. Instalei também o Solaris 10 que tem o ambiente CDE usado no curso, mas o Debian me pareceu mais fácil… rs Apesar de o Solaris ter uma interface muito bonita e robusta.
/* 12270.c 20080814 fmc
* Exercise 12270
* Input two numbers and work out their sum,
* average and sum of the squares
* of the numbers.
* compile:
* cc 12270.c -o 12270
*/
#include <math.h>
#include <stdio.h>
main()
{
int a,b,sum,sum2;
float average;
printf("\nEntre com o primeiro número: ");
scanf("%d",&a);
printf("\nEntre com o segundo número: ");
scanf("%d",&b);
sum=a+b;
average=(a+b)/2;
sum2=pow(a,2)+pow(b,2);
printf("\nA soma de %d e %d é: %d",a,b,sum);
printf("\nA média de %d e %d é: %f",a,b,average);
printf("\nA soma dos quadrados de %d e %d é: %d\n\n",a,b,sum2);
}
/* 12271.c 20080814 fmc
* Exercise 12271
* Input and output your name, address and
* age to an appropriate structure.
* compile:
* cc 12271.c -o 12271
*
*/
#include <stdio.h>
main()
{
char name[35], address[35];
int age;
/* não usar o gets pq ele pode capturar mais
* valores do que comporta a variavel, melhor
* usar o fgets(variavel,tamanho, stdin)
*/
printf("Nome: ");
fgets(name,35,stdin);
printf("\nEndereço: ");
fgets(address,35,stdin);
printf("\nIdade: ");
scanf("%d",&age);
printf("\n\tNome:\t\t %s\n",name);
printf("\n\tEndereço:\t %s\n",address);
printf("\n\tIdade:\t\t %d\n\n",age);
}
Deixar um comentário » |
Programação |
Link Permanente
Escrito por fcasado
Agosto 19, 2008
Olá a todos! Trabalho com TI e gosto muito da área de programação, apesar de não trabalhar diretamente com esta parte. Para me divertir um pouco comecei a estudar um pouquinho programação. A algum tempo atrás perguntei a um grande mestre nesta arte por onde começar e ele me indicou um curso que estou achando muito bom… Estou seguindo este curso e resolvendo os exercicios propostos. A medida que for avançando irei colocando as minhas respostas e quem estiver a fim de estudar junto pode ir comentando e colocando suas dúvidas, críticas e sugestões.
Abaixo segue o site do treinamento.
http://www.cs.cf.ac.uk/Dave/C/CE.html
Gostaria de agradecer ao mestre AlexF pela indicação de onde começar e ao professor Dave Marshall pelo excelente material.
Um grande abraço a todos!
Fernando
Deixar um comentário » |
Programação |
Link Permanente
Escrito por fcasado