Skip to content
  • P
    Projects
  • G
    Groups
  • S
    Snippets
  • Help

viakul / iax0583

  • This project
    • Loading...
  • Sign in
Go to a project
  • Project
  • Repository
  • Issues 0
  • Merge Requests 0
  • Pipelines
  • Wiki
  • Snippets
  • Members
  • Activity
  • Graph
  • Charts
  • Create a new issue
  • Jobs
  • Commits
  • Issue Boards
  • Files
  • Commits
  • Branches
  • Tags
  • Contributors
  • Graph
  • Compare
  • Charts
Commit 06b55f49 authored 6 years ago by viakul's avatar viakul
1 Browse files
Options
  • Browse Files
  • Download
  • Email Patches
  • Plain Diff

lab 2 greg cal

parent fb2af6b7
Show whitespace changes
Inline Side-by-side
Showing with 187 additions and 0 deletions
  • greg
  • greg.o
  • lab2/bin.c
  • lab2/bin.o
  • lab2/greg.c
  • lab2/number
  • lab2/number.c
  • lab2/number.o
  • lab2/untitled
  • lab2/untitled.c
  • lab2/untitled.o
greg 0 → 100644
View file @ 06b55f49
File added
This diff is collapsed. Click to expand it.
greg.o 0 → 100644
View file @ 06b55f49
File added
This diff is collapsed. Click to expand it.
lab2/bin.c 0 → 100644
View file @ 06b55f49
#include <stdio.h>
#include <m.h>
int main(){
int value;
int i;
i=1;
int pow;
int pow1;
pow=1;
pow1=0;
printf("please input positive integer\n");
scanf("%d", &value);
if ((value==0) ||(value==0))
{
printf("binary %d", value);
}else {
printf("binary ");
while(i==1){
if (value<pow) {
i=1;
} else{
pow=pow*2;
pow1=pow1+1;
}
}
while(pow1=>0){
if (power(2,pow1)>val)
{
printf("0");
pow1=pow1-1;
}
else{
printf("1");
pow1=pow1-1;
val=
}
}
}
}
}
return 0;
}
This diff is collapsed. Click to expand it.
lab2/bin.o 0 → 100644
View file @ 06b55f49
File added
This diff is collapsed. Click to expand it.
lab2/greg.c 0 → 100644
View file @ 06b55f49
#include <stdio.h>
int main(){
int date;
int year;
int month;
int day;
printf("please input your date\n");
scanf("%d", &date);
day=date/1000000;
year=date%1000;
month=(date-day*1000000)/10000;
if (((month==1)||(month==3)||(month==7)||(month==5)||(month==8)||(month==10)||(month==12)) && ((day<32)&&(day>0)))
{
printf("This is a Gregorian calendar");
}else
{
if (((month==4)||(month==6)||(month==9)||(month==11)) && ((day<31)&&(day>0)))
{
printf("This is a Gregorian calendar");
}else
{
if ((month==2 )&&(day<29)&&(day>0))
{
printf("This is a Gregorian calendar");
}else
{
if ((month==2 )&&(day<30)&&(day>0)&& (((year%4==0) && (year%100!=0)) || (year%400==0 )))
{
printf("This is a Gregorian calendar");
}else
{
printf("This is not a Gregorian calendar");
}
}
}
}
return 0;
}
This diff is collapsed. Click to expand it.
lab2/number 0 → 100644
View file @ 06b55f49
File added
This diff is collapsed. Click to expand it.
lab2/number.c 0 → 100644
View file @ 06b55f49
#include <stdio.h>
int main(){
int ThisArray[10];
int maxVal;
int minVal;
int i;
int sum;
float avg;
i=0;
printf("please input your numbers\n");
while(i<10){
scanf("%d", &ThisArray[i]);
i=i+1;
if (i<10)
{
printf("print another number\n");
}else{
printf("thank you for numbers\n");
}
}
maxVal=ThisArray[0];
minVal=ThisArray[0];
i=1;
while(i<10){
if (maxVal<ThisArray[i])
{
maxVal=ThisArray[i];
}
i=i+1;
}
while(i<10){
if (minVal>ThisArray[i])
{
minVal=ThisArray[i];
}
i=i+1;
}
sum=0;
i=0;
while(i<10){
sum=sum+ThisArray[i];
i=i+1;
}
avg=sum/10;
printf("max Value %d\n", maxVal);
printf("max Value %d\n", minVal);
printf("average %f", avg);
return 0;
}
This diff is collapsed. Click to expand it.
lab2/number.o 0 → 100644
View file @ 06b55f49
File added
This diff is collapsed. Click to expand it.
lab2/untitled 0 → 100644
View file @ 06b55f49
File added
This diff is collapsed. Click to expand it.
lab2/untitled.c 0 → 100644
View file @ 06b55f49
#include <stdio.h>
int main(){
char name[100];
int code;
printf("please input your name");
scanf("%s", name);
printf("please input your student code\n");
scanf("%d", &code);
if ( ( code > 99999) && (code<1000000)){
printf("hello! and welcome to coding %s, %d", name, code);
}else{
printf("nice try buster, but I don't think you've got a code");
}
return 0;
}
This diff is collapsed. Click to expand it.
lab2/untitled.o 0 → 100644
View file @ 06b55f49
File added
This diff is collapsed. Click to expand it.
  • viakul @viakul commented 6 years ago
    Master

    #include int main(){

    int DefNum; int pow1; int pow2; pow1=0; pow2=1;

    printf("Type your number such as 0, 1, 2, 3, 4....\n"); scanf("%d", &DefNum); if ((DefNum==1)||(DefNum==0)){ printf("The Binary representation is %d", DefNum); }else{ while(pow2=0){ if (pow2>DefNum){ printf("0"); pow1=pow1-1; pow2=pow2/2; }else{ printf("1"); DefNum=DefNum-pow2; pow1=pow1-1; pow2=pow2/2;

        }
    }

    } return 0; }

    #include <stdio.h> int main(){ int DefNum; int pow1; int pow2; pow1=0; pow2=1; printf("Type your number such as 0, 1, 2, 3, 4....\n"); scanf("%d", &DefNum); if ((DefNum==1)||(DefNum==0)){ printf("The Binary representation is %d", DefNum); }else{ while(pow2<DefNum) { pow2=pow2*2; pow1=pow1+1; } if (pow2!=DefNum) { pow2=pow2/2; pow1=pow1-1; } printf("The Binary representation is "); while (pow1>=0){ if (pow2>DefNum){ printf("0"); pow1=pow1-1; pow2=pow2/2; }else{ printf("1"); DefNum=DefNum-pow2; pow1=pow1-1; pow2=pow2/2; } } } return 0; }
  • Write
  • Preview
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or sign in to comment