Dec. 21, 2019, 8:41 a.m.
Random Code Snippets
File: Array Single Shortcut main.c
/**************************************************************
* ACTUAL COMPUTE FOR SUM AND AVG OF FIVE INPUT NUMBERS USING ARRAY SHORTCUT
* Start 2022H 100115
* License: GNU GPL v3
* TOTAL ELAPSED TIME: 14 MINS
***************************************************************/
#include <stdio.h>
//#include <conio.h>
void main ()
{
int i; //must not be float or else array error
float k,sum=0.0,five[5]; //BUG? sum should be declared as const=0.0
float avg; //for array
printf ("Input Five Numbers separated by [ENTER].\n");
for (i=0;i<5;i++)
{
scanf("%f", &five[i]);
//sum += five[i];
printf("#%d is %f\n",i+1,five[i]);
sum+=five[i];
}
/* for (k=5;i>0;k--)
{
sum = five[k] + five[k];
}
*/
//SHORT METHOD TODO: THInk of better way?
printf("SUM IS: %.1f \n", sum);
avg = sum/5;
printf("AVG IS: %.2f \n", avg);
// getch();
}
File: Convert User input to HEX main.c
/**************************************************
/* PROJECT: CONVERT USER INPUT TO HEX
/* VERSION: 0.1
/* DATE TIME: 10-20-15 1055H
/* LICENSE: GNU GPL v3
/***************************************************/
#include <stdio.h>
int main (int argc, char *argv[])
{
printf ("Input sentence\n");
int i;
i=10;
char s[i];
scanf("%s",&s);
printf("%s ", s);
return 0;
}
File: avgandsum main.c
/**************************************************************
* ACTUAL COMPUTE FOR SUM AND AVG OF FIVE INPUT NUMBERS USING ARRAY
* Start 2022H 100115
* License: GNU GPL v3
* TOTAL ELAPSED TIME: 14 MINS
***************************************************************/
#include <stdio.h>
//#include <conio.h>
void main ()
{
int i;
float k,sum,five[5];
float avg;
printf ("Input Five Numbers separated by [ENTER].\n");
for (i=0;i<5;i++)
{
scanf(" %f", &five[i]);
printf("#%d is %f\n",i+1,five[i]);
}
/* for (k=5;i>0;k--)
{
sum = five[k] + five[k];
}
*/
//LONG METHOD TODO: THInk of better way?
sum = five[0] + five[1] + five[2] + five[3] + five[4];
printf("SUM IS: %.1f \n", sum);
avg = sum/5;
printf("AVG IS: %.2f \n", avg);
// getch();
}
File: chap6
#include <stdio.h>
int main (int argc, char *argv[])
{
int a,b,c,i;
a=0;
b=1;
//printf("%d %d",a,b);
for(i=0;i<20;i++)
{
c=a+b;
a=b;
b=c;
printf(" %d ",c);
}
return 0;
}
File: CHARSARRAY.c
/***********************************************************
* COMP 212L EXAM
* ELAPSED 30 Mins
************************************************************/
#include <stdio.h>
int main (int argc, char *argv[])
{
//char a[]="computer" //8char
char a[]="The quick brown fox jumps over the lazy dog";
int i,j;
for (i=0;i<43;i++)
{
for(j=0;j<i+1;j++)
{
printf("%c",a[j]);
}
printf("\n");
}
//printf ("Hello world!\n");
for (i=43;i>0;i--)
{
for(j=i;j>0;j--)
{
printf("%c",a[j-1]);
}
printf("\n");
}
return 0;
}