목차
▤ 프로그램 6.1 /* 표현식이 생략된 for문 */
#include <stdio.h>
main()
{
int a=0, b=0;
for(;;){ /* 무한루프를 형성하는 형태 */
printf(\"정수 입력 : \");
<생략>
#include <stdio.h>
main()
{
int a=0, b=0;
for(;;){ /* 무한루프를 형성하는 형태 */
printf(\"정수 입력 : \");
<생략>
본문내용
(B!=1)))
{
puts("Invalid input");
okay=FALSE;
}
else okay=TRUE;
} while ( !okay );
do
{
printf("Enter C input (0 or 1) >>");
rtn=scanf("%d",&C);
if ((rtn!=1) ||( (C!=0) && (C!=1)))
{
puts("Invalid input");
okay=FALSE;
}
else okay=TRUE;
} while ( !okay );
Z=!((A && B) || C);
printf("Output will be %d\n",Z);
printf("Do you wish to continue (y/n) >>");
fflush(stdin);
/* this will flush the keyboard buffer */
/* as there may be characters still in it */
ch=getchar();
} while (tolower(ch)=='y');
return(0);
}
▤ 프로그램 6.52
/*Program to determine the gain of an CR */
/*active filter for an entered values of C and R*/
/*and a frequency span from 1Hz up to 1 GHz in*/
/*decadesteps*/
#include
#include
#defineTRUE1
#defineFALSE0
#defineMILLI1e-3
#defineKILO1e3
#defineMEGA1e6
#defineGIGA1e9
#definePI3.14159
int main(void)
{
floatresistance,capacitance,freq,gain,gain_dB;
intrtn,okay;
puts("Program to determine gain of a CR active filter");
do
{
printf("Enter capacitance >>");
rtn=scanf("%f",&capacitance);
if ((rtn!=1) || (capacitance>MILLI))
{
puts("INVALID: re-enter");
okay=FALSE;
}
elseokay=TRUE;
} while (!okay );
do
{
printf("Enter resistance >>");
rtn=scanf("%f",&resistance);
if ((rtn!=1) || ((resistance>=MEGA) || (resistance
{
puts("INVALID: re-enter");
okay=FALSE;
}
else okay=TRUE;
} while (!okay);
puts("FREQUENCY(Hz) GAIN(dB)");
for (freq=1;freq<=GIGA;freq*=10)
{/* decade steps of frequency*/
gain=2*PI*freq*resistance*capacitance;
gain_dB=20*log10(gain);
printf("%10.1e %10.3f\n",freq,gain_dB);
}
return(0);
}
▤ 프로그램 6.53
/*Prints the square of the numbers 1 to 10*/
/*ie 1,4,9..100*/
#include
intmain(void)
{
int i;
for (i=1,i<10,i++)
printf("The square of i is %d,i*i);
return(0);
}
▤ 프로그램 6.54
/*Prints values from 1 to 100 in power of 3 */
/*The step used is 0.3*/
#include
intmain(void)
{
int i;
while (i != 100)
{
printf("%d to the power of three is %d /n",i*i*i);
i += 0.3;
return(0);
}
▤ 프로그램 6.55
/* Prints the square of the numbers 1 to 10 */
/*ie 1,4,9..100*/
#include
intmain(void)
{
int i;
for (i=1;i<=10;i++);
printf("The square of i is %d,i*i);
return(0);
}
▤ 프로그램 6.56
/* Program to determine input resistance given the*/
/*input voltage and current*/
#include
int main(void)
{
char input;
puts("Program to determine the resistance given");
puts("input voltage and current");
while (input == 'y')
{
printf("Enter voltage and current >> ");
scanf("%f %f",voltage,current);
printf("The resistance is %f",voltage/current);
puts("Do you wish to continue (y/n)")
input = getchar();
}
return(0);
}
▤ 프로그램 6.57
#defineTRUE1
#include
int main(void)
{
puts("Program to determine the resistance given");
puts("input voltage and current");
while (TRUE)
{
printf("Enter voltage and current >> ");
scanf("%f %f",voltage,current);
printf("The resistance is %f",voltage/current);
puts("Do you wish to continue(y/n)");
ch=getchar();
if ((ch=='n') && (ch=='N')) break;
}
puts("Program exited");
return(0);
}
{
puts("Invalid input");
okay=FALSE;
}
else okay=TRUE;
} while ( !okay );
do
{
printf("Enter C input (0 or 1) >>");
rtn=scanf("%d",&C);
if ((rtn!=1) ||( (C!=0) && (C!=1)))
{
puts("Invalid input");
okay=FALSE;
}
else okay=TRUE;
} while ( !okay );
Z=!((A && B) || C);
printf("Output will be %d\n",Z);
printf("Do you wish to continue (y/n) >>");
fflush(stdin);
/* this will flush the keyboard buffer */
/* as there may be characters still in it */
ch=getchar();
} while (tolower(ch)=='y');
return(0);
}
▤ 프로그램 6.52
/*Program to determine the gain of an CR */
/*active filter for an entered values of C and R*/
/*and a frequency span from 1Hz up to 1 GHz in*/
/*decadesteps*/
#include
#include
#defineTRUE1
#defineFALSE0
#defineMILLI1e-3
#defineKILO1e3
#defineMEGA1e6
#defineGIGA1e9
#definePI3.14159
int main(void)
{
floatresistance,capacitance,freq,gain,gain_dB;
intrtn,okay;
puts("Program to determine gain of a CR active filter");
do
{
printf("Enter capacitance >>");
rtn=scanf("%f",&capacitance);
if ((rtn!=1) || (capacitance>MILLI))
{
puts("INVALID: re-enter");
okay=FALSE;
}
elseokay=TRUE;
} while (!okay );
do
{
printf("Enter resistance >>");
rtn=scanf("%f",&resistance);
if ((rtn!=1) || ((resistance>=MEGA) || (resistance
puts("INVALID: re-enter");
okay=FALSE;
}
else okay=TRUE;
} while (!okay);
puts("FREQUENCY(Hz) GAIN(dB)");
for (freq=1;freq<=GIGA;freq*=10)
{/* decade steps of frequency*/
gain=2*PI*freq*resistance*capacitance;
gain_dB=20*log10(gain);
printf("%10.1e %10.3f\n",freq,gain_dB);
}
return(0);
}
▤ 프로그램 6.53
/*Prints the square of the numbers 1 to 10*/
/*ie 1,4,9..100*/
#include
intmain(void)
{
int i;
for (i=1,i<10,i++)
printf("The square of i is %d,i*i);
return(0);
}
▤ 프로그램 6.54
/*Prints values from 1 to 100 in power of 3 */
/*The step used is 0.3*/
#include
intmain(void)
{
int i;
while (i != 100)
{
printf("%d to the power of three is %d /n",i*i*i);
i += 0.3;
return(0);
}
▤ 프로그램 6.55
/* Prints the square of the numbers 1 to 10 */
/*ie 1,4,9..100*/
#include
intmain(void)
{
int i;
for (i=1;i<=10;i++);
printf("The square of i is %d,i*i);
return(0);
}
▤ 프로그램 6.56
/* Program to determine input resistance given the*/
/*input voltage and current*/
#include
int main(void)
{
char input;
puts("Program to determine the resistance given");
puts("input voltage and current");
while (input == 'y')
{
printf("Enter voltage and current >> ");
scanf("%f %f",voltage,current);
printf("The resistance is %f",voltage/current);
puts("Do you wish to continue (y/n)")
input = getchar();
}
return(0);
}
▤ 프로그램 6.57
#defineTRUE1
#include
int main(void)
{
puts("Program to determine the resistance given");
puts("input voltage and current");
while (TRUE)
{
printf("Enter voltage and current >> ");
scanf("%f %f",voltage,current);
printf("The resistance is %f",voltage/current);
puts("Do you wish to continue(y/n)");
ch=getchar();
if ((ch=='n') && (ch=='N')) break;
}
puts("Program exited");
return(0);
}
소개글