#include<stdio.h>
int main (void)
{
int a=0,b; int num; int o=0;
long unsigned int charcount = 0;
long unsigned int wordcount = 0;
long unsigned int linecount = 0;
while (a != EOF){
a = getchar();
if (!(a>='a' && a<='z') && !(a>='A' && a<='Z') && !(a == 39)){
wordcount++;
if (!(b>='a' && b<='z') && !(b>='A' && b<='Z') && !(b == 39)){
wordcount--;
}
}
if (a == '\n'){
linecount++;
}
charcount++;
b=a;
}
//wordcount =
printf( "%lu %lu %lu\n", charcount-1, wordcount, linecount );
return 0;
}
Wednesday, May 31, 2017
t6.c (done)
#include<stdio.h>
#include <math.h>
int main (void)
{
int result = 0;
float i;
float smallest =0, largest=0, total=0;
int eachNewline = 0;
while (result != EOF)
{
result = scanf ("%f",&i);
if(smallest ==0 && largest == 0 && total == 0){
smallest = i;
largest = i;
}
if (result == EOF){ break;}
if (i<smallest){
smallest = i;
} else if (i>largest){
largest = i;
}
total = i + total;
eachNewline++;
}
printf("%.2f %.2f %.2f\n", smallest, largest, (total/eachNewline));
return 0;
}
#include <math.h>
int main (void)
{
int result = 0;
float i;
float smallest =0, largest=0, total=0;
int eachNewline = 0;
while (result != EOF)
{
result = scanf ("%f",&i);
if(smallest ==0 && largest == 0 && total == 0){
smallest = i;
largest = i;
}
if (result == EOF){ break;}
if (i<smallest){
smallest = i;
} else if (i>largest){
largest = i;
}
total = i + total;
eachNewline++;
}
printf("%.2f %.2f %.2f\n", smallest, largest, (total/eachNewline));
return 0;
}
Tuesday, May 30, 2017
scrambled.c
#include<stdio.h>
int scrambled( unsigned int a[], unsigned int b[], unsigned int len )
{
int x, y;
unsigned int score1 = 0;
unsigned int score2 =0;
int scramble = 1;
if( len !=0){
for (x=0; x<len; x++){
for (y=0; y < len; y++){
if (b[y] == a[x]){
score1++;
break;
}
}
}
for (x=0; x<len; x++){
for (y=0; y < len; y++){
if (a[y] == b[x]){
score2++;
break;
}
}
}
}
if( (score1 != len) || (score2 != len) ){
scramble = 0;
}
return scramble;
}
int main( void )
{
unsigned int a[5] = {0,5,4,1,2} ;
unsigned int b[5] = {1,2,0,4,5};
if( scrambled( a, b, 5 ) == 1 )
{
printf( "b is a scrambled version of a\n" );
} else {
printf( "b has different contents to a\n" );
}
return 0;
}
int scrambled( unsigned int a[], unsigned int b[], unsigned int len )
{
int x, y;
unsigned int score1 = 0;
unsigned int score2 =0;
int scramble = 1;
if( len !=0){
for (x=0; x<len; x++){
for (y=0; y < len; y++){
if (b[y] == a[x]){
score1++;
break;
}
}
}
for (x=0; x<len; x++){
for (y=0; y < len; y++){
if (a[y] == b[x]){
score2++;
break;
}
}
}
}
if( (score1 != len) || (score2 != len) ){
scramble = 0;
}
return scramble;
}
int main( void )
{
unsigned int a[5] = {0,5,4,1,2} ;
unsigned int b[5] = {1,2,0,4,5};
if( scrambled( a, b, 5 ) == 1 )
{
printf( "b is a scrambled version of a\n" );
} else {
printf( "b has different contents to a\n" );
}
return 0;
}
t9.c (done)
#include<stdio.h>
#include<math.h>
int main (void){
int i, diff, xd, yd, hd, slope; //yd is useless
int atZero = 0;
int start = 0;
scanf("%d %d %d", &xd, &yd, &hd);
// calculates slope
float halfxd = xd/2;
float raw_slope = (halfxd/hd);
if (raw_slope != floor(raw_slope)){
if (slope <1){
// number of #s that start at 0
atZero = hd * (1 - raw_slope);
slope = 1;
} else {
// new slope
slope = (int)floor(raw_slope);
}
} else {
slope = raw_slope;
}
//calculates number of white spaces at top
diff = hd - 1 - atZero;
//printf("diff = %d; atZero = %d", diff, atZero);
for (i = 0; i<diff; i++){
start += slope;
}
//prints top row
if (hd>1){
for ( i=0; i<start; i++){
printf(" ");
}
for (i=0; i<(xd-start*2); i++){
printf("#");
}
printf("\n");
start -= slope;
}
// prints each line
if (hd>2){
for (i=0; i<hd-2-atZero; i++){
// prints the spaces at the beginning
for (int s =0; s<(start); s++){
printf(" ");
}
printf("#");
for (int s=0; s<(xd-2-(start)*2); s++){
printf(".");
}
printf("#\n");
start-= slope;
}
if (atZero != 0){
for( int k=0; k< atZero; k++ ){
printf("#");
// to print the "."
for (int j =0; j < xd-2; j++){
printf(".");
}
printf("#\n");
i++;
}
}
}
// prints last line
for (i=0; i<xd; i++){
printf("#");
}
printf("\n");
return 0;
}
#include<math.h>
int main (void){
int i, diff, xd, yd, hd, slope; //yd is useless
int atZero = 0;
int start = 0;
scanf("%d %d %d", &xd, &yd, &hd);
// calculates slope
float halfxd = xd/2;
float raw_slope = (halfxd/hd);
if (raw_slope != floor(raw_slope)){
if (slope <1){
// number of #s that start at 0
atZero = hd * (1 - raw_slope);
slope = 1;
} else {
// new slope
slope = (int)floor(raw_slope);
}
} else {
slope = raw_slope;
}
//calculates number of white spaces at top
diff = hd - 1 - atZero;
//printf("diff = %d; atZero = %d", diff, atZero);
for (i = 0; i<diff; i++){
start += slope;
}
//prints top row
if (hd>1){
for ( i=0; i<start; i++){
printf(" ");
}
for (i=0; i<(xd-start*2); i++){
printf("#");
}
printf("\n");
start -= slope;
}
// prints each line
if (hd>2){
for (i=0; i<hd-2-atZero; i++){
// prints the spaces at the beginning
for (int s =0; s<(start); s++){
printf(" ");
}
printf("#");
for (int s=0; s<(xd-2-(start)*2); s++){
printf(".");
}
printf("#\n");
start-= slope;
}
if (atZero != 0){
for( int k=0; k< atZero; k++ ){
printf("#");
// to print the "."
for (int j =0; j < xd-2; j++){
printf(".");
}
printf("#\n");
i++;
}
}
}
// prints last line
for (i=0; i<xd; i++){
printf("#");
}
printf("\n");
return 0;
}
t6.c (done)
#include<stdio.h>
#include <math.h>
int main (void)
{
int result = 0;
float i = 0;
scanf("%f",&i);
float smallest = i;
float largest = i;
float total = i;
int eachNewline = 1;
while (result != EOF)
{
result = scanf ("%f",&i);
if (i<smallest){
smallest = i;
} else if (i>largest){
largest = i;
}
total = i + total;
eachNewline = eachNewline + 1;
}
printf("%.2f %.2f %.2f\n", smallest, largest, (total/eachNewline));
return 0;
}
#include <math.h>
int main (void)
{
int result = 0;
float i = 0;
scanf("%f",&i);
float smallest = i;
float largest = i;
float total = i;
int eachNewline = 1;
while (result != EOF)
{
result = scanf ("%f",&i);
if (i<smallest){
smallest = i;
} else if (i>largest){
largest = i;
}
total = i + total;
eachNewline = eachNewline + 1;
}
printf("%.2f %.2f %.2f\n", smallest, largest, (total/eachNewline));
return 0;
}
Saturday, May 27, 2017
Lab 1 Task 8 done
#include<stdio.h>
int main (void)
{
int a[4], xd, yd, height, i, x;
do
{
scanf("%d %d %d", &xd, &yd, &height);
// prints out first line
for(i=0; i<xd; i++){
putchar('#');
}
printf("%s", "\n");
// prints middle stuff
if (yd >2){
for(i=0; i<yd-2; i++){
putchar('#');
for (x=0; x<xd-2; x++){
putchar('.');
}
putchar('#');
printf("%s", "\n");
}
}
// prints end line
if (yd > 1){
for(i=0; i<xd; i++){
putchar('#');
}
printf("%s", "\n");
}
}while (1);
return 0;
}
int main (void)
{
int a[4], xd, yd, height, i, x;
do
{
scanf("%d %d %d", &xd, &yd, &height);
// prints out first line
for(i=0; i<xd; i++){
putchar('#');
}
printf("%s", "\n");
// prints middle stuff
if (yd >2){
for(i=0; i<yd-2; i++){
putchar('#');
for (x=0; x<xd-2; x++){
putchar('.');
}
putchar('#');
printf("%s", "\n");
}
}
// prints end line
if (yd > 1){
for(i=0; i<xd; i++){
putchar('#');
}
printf("%s", "\n");
}
}while (1);
return 0;
}
Lab 1 Task 7 done
#include <stdio.h>
int main (void)
{
int a[100];
int i; int x = 0; int y = 0;
do
{
for (i=0; a[i] != 0; i++){
scanf("%d", &a[i]);
for (y=0; y< a[i]; y++){
putchar('#');
}
printf("%s", "\n");
}
}while (1);
return 0;
}
int main (void)
{
int a[100];
int i; int x = 0; int y = 0;
do
{
for (i=0; a[i] != 0; i++){
scanf("%d", &a[i]);
for (y=0; y< a[i]; y++){
putchar('#');
}
printf("%s", "\n");
}
}while (1);
return 0;
}
Friday, May 26, 2017
contains.c (done)
#include<stdio.h>
#include<string.h>
int main (int argc, char* argv [])
{
int x, y, z;
int contained = 0;
int count =0;
int lenStr2 = 0; int i =0;
char str1[100];
strcpy(str1, argv[1]);
char str2[100];
strcpy(str2, argv[2]);
// counts the # of chars in Str2 - excludes null chracter
while (str2[i] != 0){
lenStr2++;
*(str2+i);
i++;
}
for(x=0; str1[x] != 0; x++){ //iterates through string 1
if (contained != 1){
if (str1[x] == str2[0]){ // if string1 == str2 first letter
for (y=0; str2[y] != 0; y++){ //iterates through str2
if ( str1[x] == str2[y]){
count++; //if letters match, add count
x++;
if( count == lenStr2){ //if the count equals to the len of str 2
contained = 1;
break;
}
}else{ //if the enxt chars dont match
break;
}
}
}
}else{
break;
}
}
// prints true or false statement
if (contained ==1){
printf("%s\n", "true");
} else {
printf("%s\n", "false");
}
return 0;
}
#include<string.h>
int main (int argc, char* argv [])
{
int x, y, z;
int contained = 0;
int count =0;
int lenStr2 = 0; int i =0;
char str1[100];
strcpy(str1, argv[1]);
char str2[100];
strcpy(str2, argv[2]);
// counts the # of chars in Str2 - excludes null chracter
while (str2[i] != 0){
lenStr2++;
*(str2+i);
i++;
}
for(x=0; str1[x] != 0; x++){ //iterates through string 1
if (contained != 1){
if (str1[x] == str2[0]){ // if string1 == str2 first letter
for (y=0; str2[y] != 0; y++){ //iterates through str2
if ( str1[x] == str2[y]){
count++; //if letters match, add count
x++;
if( count == lenStr2){ //if the count equals to the len of str 2
contained = 1;
break;
}
}else{ //if the enxt chars dont match
break;
}
}
}
}else{
break;
}
}
// prints true or false statement
if (contained ==1){
printf("%s\n", "true");
} else {
printf("%s\n", "false");
}
return 0;
}
contains.c (not done)
#include<stdio.h>
#include<string.h>
int main (int argc, char* argv [])
{
int y;
int contained = 0
int lenStr2 = 0; int i =0;
char*x;
char str1[100];
strcpy(str1, argv[1]);
char str2[100];
strcpy(str2, argv[2]);
char *pStr2 = str2;
char *pStr1 = str1;
// counts the # of chars in Str2 - excludes null chracter
while (str2[i] != 0){
lenStr2++;
*(str2+i);
i++;
}
while(pStr1 != NULL){
if (pStr1 == str2[0]){
}
// prints true or false statement
if (contained ==1){
printf("%s\n", "true");
} else {
printf("%s\n", "false");
return 0;
}
#include<string.h>
int main (int argc, char* argv [])
{
int y;
int contained = 0
int lenStr2 = 0; int i =0;
char*x;
char str1[100];
strcpy(str1, argv[1]);
char str2[100];
strcpy(str2, argv[2]);
char *pStr2 = str2;
char *pStr1 = str1;
// counts the # of chars in Str2 - excludes null chracter
while (str2[i] != 0){
lenStr2++;
*(str2+i);
i++;
}
while(pStr1 != NULL){
if (pStr1 == str2[0]){
}
// prints true or false statement
if (contained ==1){
printf("%s\n", "true");
} else {
printf("%s\n", "false");
return 0;
}
Wednesday, May 24, 2017
L2 T3 done
void reverse( int arr[], unsigned int len )
{
int i;
int x =1;
int k = len;
int temp = arr[len];
for (k=len;k-1 > 0; k--)
{
for (i=0; i<len-x; i++){
temp = arr[i+1];
arr[i+1]=arr[i];
arr[i]=temp;
}
x++;
}
}
{
int i;
int x =1;
int k = len;
int temp = arr[len];
for (k=len;k-1 > 0; k--)
{
for (i=0; i<len-x; i++){
temp = arr[i+1];
arr[i+1]=arr[i];
arr[i]=temp;
}
x++;
}
}
Monday, May 22, 2017
L1 T7 V3
#include<stdio.h>
#include <math.h>
int main (void)
{
int x, y, result;
//int *v;
char i[100];
/*scanf("%",&i);
for (y=0;y < (int)i; y++){
putchar('#');
}
printf("\n");*/
do
{
if (scanf(" %99[^\n]%*c", i) ==1){
for (y=0;y < (int)i[y]; y++){
printf("%d", (int)i[y]);
putchar('#');
}
printf("\n");
}
/* scanf(" %d", &i);
for (x=0; x<i; x++){
putchar('#');
}
printf("\n");*/
//result = scanf("%s", &i);
}while (1);
return 0;
}
#include <math.h>
int main (void)
{
int x, y, result;
//int *v;
char i[100];
/*scanf("%",&i);
for (y=0;y < (int)i; y++){
putchar('#');
}
printf("\n");*/
do
{
if (scanf(" %99[^\n]%*c", i) ==1){
for (y=0;y < (int)i[y]; y++){
printf("%d", (int)i[y]);
putchar('#');
}
printf("\n");
}
/* scanf(" %d", &i);
for (x=0; x<i; x++){
putchar('#');
}
printf("\n");*/
//result = scanf("%s", &i);
}while (1);
return 0;
}
Lab 1 Task 7 V2
#include<stdio.h>
#include <math.h>
int main (void)
{
int x, y, result, i;
//int *v;
scanf("%d",&i);
for (y=0;y < i; y++){
putchar('#');
}
printf("\n");
do
{
scanf("%d", &i);
for (y=0;y < i; y++){
putchar('#');
}
printf("\n");
scanf(" %d", &i);
for (x=0; x<i; x++){
putchar('#');
}
printf("\n");
result = scanf("%d", &i);
}while (result != EOF);
return 0;
}
#include <math.h>
int main (void)
{
int x, y, result, i;
//int *v;
scanf("%d",&i);
for (y=0;y < i; y++){
putchar('#');
}
printf("\n");
do
{
scanf("%d", &i);
for (y=0;y < i; y++){
putchar('#');
}
printf("\n");
scanf(" %d", &i);
for (x=0; x<i; x++){
putchar('#');
}
printf("\n");
result = scanf("%d", &i);
}while (result != EOF);
return 0;
}
Friday, May 19, 2017
Lab 1 Task 7 (not done)
#include <stdio.h>
int main (void)
{
int result = 0;
float i = 0;
scanf (%f, &i);
while (result != EOF)
{
scanf(%f, &i);
}
}
Thursday, May 18, 2017
Lab 1 Task 6
#include<stdio.h>
#include <math.h>
int main (void)
{
int result = 0;
float i = 0;
scanf("%f",&i);
float smallest = i;
float largest = i;
float total = i;
int eachNewline = 1;
while (result != EOF)
{
scanf ("%f",&i);
if (i<smallest){
smallest = i;
} else if (i>largest){
largest = i;
}
total = i + total;
eachNewline = eachNewline + 1;
result = scanf("%f", &i);
}
printf("%.2f %.2f %.2f\n", smallest, largest, (total/eachNewline));
return 0;
}
#include <math.h>
int main (void)
{
int result = 0;
float i = 0;
scanf("%f",&i);
float smallest = i;
float largest = i;
float total = i;
int eachNewline = 1;
while (result != EOF)
{
scanf ("%f",&i);
if (i<smallest){
smallest = i;
} else if (i>largest){
largest = i;
}
total = i + total;
eachNewline = eachNewline + 1;
result = scanf("%f", &i);
}
printf("%.2f %.2f %.2f\n", smallest, largest, (total/eachNewline));
return 0;
}
Wednesday, May 17, 2017
Lab 1 Task 5
#include <stdio.h>
#include <math.h>
int main (void)
{
int result = 0;
float i = 0;
scanf("%f", &i);
while (result != EOF)
{
printf("%d %d %d\n", (int)floor(i), (int)round(i), (int)ceil(i)$
result = scanf("%f",&i);
}
printf("Done.\n");
return 0;
}
#include <math.h>
int main (void)
{
int result = 0;
float i = 0;
scanf("%f", &i);
while (result != EOF)
{
printf("%d %d %d\n", (int)floor(i), (int)round(i), (int)ceil(i)$
result = scanf("%f",&i);
}
printf("Done.\n");
return 0;
}
Subscribe to:
Posts (Atom)
-
/* * imageops.c - Simple operations on images * * C laboratory exercises. * Richard Vaughan, 2014. */ #include <assert.h> ...
-
/* * imageops.c - Simple operations on images * * C laboratory exercises. * Richard Vaughan, 2014. */ #include <assert.h> #includ...