0% found this document useful (0 votes)
43 views5 pages

Homework3 PDF

The document contains 5 coding problems and solutions involving C programming concepts like input/output, conditional statements, loops, functions, macros. Problem 1 prints each character entered 3 times if it is a letter, and once otherwise. Problem 2 converts vowels to uppercase and consonants to lowercase. Problem 3 prints trigonometric function values in a table for pi radians.

Uploaded by

Alan Raye
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
43 views5 pages

Homework3 PDF

The document contains 5 coding problems and solutions involving C programming concepts like input/output, conditional statements, loops, functions, macros. Problem 1 prints each character entered 3 times if it is a letter, and once otherwise. Problem 2 converts vowels to uppercase and consonants to lowercase. Problem 3 prints trigonometric function values in a table for pi radians.

Uploaded by

Alan Raye
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 5

Isaac Ray, CSCE 206-504, Fall 2018

Problem 1:
#include <stdio.h>

int main(void)
{
char c;
while((c=getchar()) != EOF)
{
if(c >= 65 && c <= 122)
{
putchar(c);
putchar(c);
putchar(c);
putchar(10);
} else {
putchar(c);
}
}
return 0;
}
Problem 2:
#include <stdio.h>
#include <ctype.h>

int isvowel(int);

int main(void)
{
char c;
while((c=getchar()) != EOF)
{
if(isvowel(c))
putchar(toupper(c));
else
putchar(tolower(c));
}
return 0;
}

int isvowel(int c)
{
c = toupper(c);
if(c == 'A' || c == 'E' || c == 'I' || c == 'O' || c ==
'U')
return 1;
else
return 0;
}
Problem 3:
#include <stdio.h>
#include <math.h>
#define PI 3.1415926

int main(void)
{
long double i;
printf("------------------------------\n");
printf("| sin(x) | cos(x) | tan(x) |\n");
printf("------------------------------\n");
for(i = 0; i<=PI; i += PI / 19)
{
printf("| %.4f | %.4f | %.4f |\n", sin(i), cos(i),
tan(i));
}
printf("------------------------------\n");
return 0;
}
Problem 3 Output:
------------------------------
| sin(x) | cos(x) | tan(x) |
------------------------------
| 0.0000 | 1.0000 | 0.0000 |
| 0.1646 | 0.9864 | 0.1669 |
| 0.3247 | 0.9458 | 0.3433 |
| 0.4759 | 0.8795 | 0.5412 |
| 0.6142 | 0.7891 | 0.7783 |
| 0.7357 | 0.6773 | 1.0863 |
| 0.8372 | 0.5469 | 1.5306 |
| 0.9158 | 0.4017 | 2.2798 |
| 0.9694 | 0.2455 | 3.9489 |
| 0.9966 | 0.0826 | 12.0682 |
| 0.9966 | -0.0826 | -12.0682 |
| 0.9694 | -0.2455 | -3.9489 |
| 0.9158 | -0.4017 | -2.2798 |
| 0.8372 | -0.5469 | -1.5306 |
| 0.7357 | -0.6773 | -1.0863 |
| 0.6142 | -0.7891 | -0.7783 |
| 0.4759 | -0.8795 | -0.5412 |
| 0.3247 | -0.9458 | -0.3433 |
| 0.1646 | -0.9864 | -0.1669 |
| 0.0000 | -1.0000 | -0.0000 |
------------------------------
Problem 4:
#include <stdio.h>
#define SUM(x,y) ((x) + (y))

int main(void)
{
int x , y;
printf("Input 2 integers\n");
scanf("%d %d", &x, &y);
printf("The sum of x and y is %d", SUM(x,y));
return 0;
}
Problem 5:
#include <stdio.h>
#define MIN2(x,y) ((x)<(y))?(x):(y)

int main(void)
{
int a, b;
printf("Input 2 integers\n");
scanf("%d %d", &a, &b);
printf("The smaller value is %d", MIN2(a,b));
return 0;
}

You might also like