C Program : Fungsi untuk X pangkat Y

#Nb : Tugas Kuliah saya🙂
#Keterangan : di sini ada yang spesial, pangkat y nya dapat berupa bilangan negatif😀 (biasa aja padahal)

#include <stdio.h>
#include <stdlib.h>
float pangkat(int x,int y);
int main()
{
    int x,y; float hasil;
    printf("n Pangkat (power)n =================n");
    printf("n Untuk fungsi x^y masukan nilai x dan y, pisahkan dengan spasi :n ");
    scanf("%d%d",&x,&y);
    hasil=pangkat(x,y);
    printf("n Hasil dari %d^%d : ",x,y);
    printf("%.4f",hasil);
    getchar();
    getchar();
    return 0;
}
float pangkat(int x,int y){
    int a;float hasil=1;
    if(y==0)
        hasil=1;
    if(y>0)
    for(a=1;a<=y;a++){
        hasil*=x;
    }
    if(y<0){
        int yy=-(y);
        for(a=1;a<=yy;a++){
        hasil*=x;
        }
        hasil = (float)1/hasil;
    }
    return hasil;
}

About Iin aryani

I don't wanna be a "Copycat" but, something they need to copy.

Posted on 1 October 2012, in Open Source ( C Program ), Pemrograman C and tagged . Bookmark the permalink. 1 Comment.

  1. WOW just what I was searching for. Came here by searching for document

Komentar untuk penulis

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

%d bloggers like this: