C Programmers Help Me!!!!

senewimala1988

Well-known member
  • Dec 5, 2007
    7,788
    2,638
    113
    Kadawatha, Sri Lanka
    Here are two simple exercise on C programming language. Please give me the coding for these program(at least for the second exercise)(The second one is the most important exercise)

    Exercise 1:
    Write a program to input a temperature reading in either Celsius(c) or Fahrenheit(f) scale and convert it to the other scale. The temperature reading consist of a decimal integer followed by letter “F” or “f” if the temperature is in Fahrenheit scale or letter “C” or “c” if it is in Celsius scale. You may use a similar format for the output of the program.


    Note: c=5*(f-32)/9


    $ ./a.out
    Temperature reading: 100C
    212F


    $ ./a.out
    Temperature reading: 100F
    37C


    Exercise 2:
    Give a date as a triplet of numbers(y,m,d), with y indicating the year, m the month(m=1 for January, m=2 for February, etc.), and d the day of the month, the corresponding day of the week f(f=0 for Sunday, f=1 for Monday, etc.), can be found as follows:


    (a)if m<3 let m=m+12 and let y=y-1
    (b)let a=2m+6(m+1)/10
    (c)let b=y+y/4-y/100+y/400
    (d)let f1=d+a+b+1
    (e)let f=f1 mod 7
    (f)stop.


    Write a program that will read a date and print the corresponding day of the week. All divisions indicated above are integer divisions.


    :(:(:(
     

    xcorect

    Well-known member
  • Apr 17, 2007
    7,881
    84
    48
    prashne pahadili madi machan
    input ekai
    umbata wenna ona out put ekak pahadiliwa kiyanna
     

    chamidilk

    Active member
  • Nov 18, 2006
    1,053
    4
    38
    Moratuwa
    menna temperature conversion prog eka

    #include<stdio.h>
    main(){
    int c;
    int f;
    char type;
    printf("Temperature reading: ");
    scanf("%d%c",&c,&type);
    if((type=='c'||type=='C')){
    printf("%dF",F(c));
    }
    else if((type=='f'||type=='F')){
    printf("%dC",C(c));
    }
    else printf("Invalid Entry\nTry Again");
    }

    int C(int i){
    return (5*(i-32)/9);
    }
    int F(int i){
    return (32+9*i/5);
    }


    menna anith prog eka day eka kiyana eka


    #include<stdio.h>
    main(){
    int y,m,d,a,b,f1,f;
    printf("Enter (YYYY-MM-DD) : ");
    scanf("%d-%d-%d",&y,&m,&d);
    if(m<3){
    m+=12;--y;
    }
    a = 2*m+6*(m+1)/10;
    b = y+y/4-y/100+y/400;
    f1= d+a+b+1;
    f = f1%7;
    switch(f){
    case 0:printf("Sunday\n");break;
    case 1:printf("Monday\n");break;
    case 2:printf("Tuesday\n");break;
    case 3:printf("Wednesday\n");break;
    case 4:printf("Thursday\n");break;
    case 5:printf("Friday\n");break;
    case 6:printf("Saturday\n");break;
    }
    }
     

    chamidilk

    Active member
  • Nov 18, 2006
    1,053
    4
    38
    Moratuwa
    macho ara day eka kiyana prog eke input eka mama dunne me widiyata honde
    look at dz instance
    ex-: input-----> 2009-2-13
    output-----> Friday
     

    ¤--bACarDi--¤

    Well-known member
  • Jan 9, 2009
    12,130
    288
    83
    124.43.xxx.xxx
    chamidilk said:
    menna temperature conversion prog eka

    #include<stdio.h>
    main(){
    int c;
    int f;
    char type;
    printf("Temperature reading: ");
    scanf("%d%c",&c,&type);
    if((type=='c'||type=='C')){
    printf("%dF",F(c));
    }
    else if((type=='f'||type=='F')){
    printf("%dC",C(c));
    }
    else printf("Invalid Entry\nTry Again");
    }

    int C(int i){
    return (5*(i-32)/9);
    }
    int F(int i){
    return (32+9*i/5);
    }


    menna anith prog eka day eka kiyana eka


    #include<stdio.h>
    main(){
    int y,m,d,a,b,f1,f;
    printf("Enter (YYYY-MM-DD) : ");
    scanf("%d-%d-%d",&y,&m,&d);
    if(m<3){
    m+=12;--y;
    }
    a = 2*m+6*(m+1)/10;
    b = y+y/4-y/100+y/400;
    f1= d+a+b+1;
    f = f1%7;
    switch(f){
    case 0:printf("Sunday\n");break;
    case 1:printf("Monday\n");break;
    case 2:printf("Tuesday\n");break;
    case 3:printf("Wednesday\n");break;
    case 4:printf("Thursday\n");break;
    case 5:printf("Friday\n");break;
    case 6:printf("Saturday\n");break;
    }
    }


    Hey nice machan...Are u studing @ SLIIT or sumwhere...?
     

    madurax86

    Member
    Jun 29, 2006
    4,385
    88
    0
    Code:
    #include <cstdlib>
    #include <iostream>
    
    using namespace std;
    
    int main(int argc, char *argv[])
    {
        int y,m,d,f1,f,a,b;
    
        cin>>y;
        cin>>m;
        cin>>d;
        if (m<3) {
                m=m+12;
                y=y-1;
               }
        a=2*m+6*(m+1)/10;
        b=y+y/4-y/100+y/400;
        f1=d+a+b+1;
        f=f1 % 7;
        switch (f){
               case 0:cout<<"Sunday";
               case 1:cout<<"Monday";
               case 2:cout<<"Tuesday";
               case 3:cout<<"Wednesday";
               case 4:cout<<"Thursday";
               case 5:cout<<"Friday";
               case 6:cout<<"Saturday";
               }
        system("PAUSE");
        return EXIT_SUCCESS;
    }

    Meka C++ eth convert karagana puluwan ne 2ma eka wage ne tikak printf ui scanf ui witarai man hithanne wenasa manda man C danne na C++ pamanai
     
    Last edited:

    chamidilk

    Active member
  • Nov 18, 2006
    1,053
    4
    38
    Moratuwa
    no macho I study in University of Moratuwa ....
    Why did you ask me whether I studied in SLIIT ..... ????
    macho CPP wala oya switch case eka ain karala kelinma String array ekak ganna puluwan neda ?????