Commit 06b55f49 by viakul

lab 2 greg cal

parent fb2af6b7
File added
File added
#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;
}
File added
#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;
}
File added
#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;
}
File added
File added
#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;
}
File added
  • #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; }

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