CS Codes

111 0 1
                                        

#include <stdio.h>

// prints the factorial of a number keyed in by the user

int main ()

{

int x,y;

scanf ("%d", &x);

y=1;

while (x>1)

{

y = (y*x);

x = x-1;

}

printf("%d",y);

system ("pause");

return 0;

}

=====

#include<stdio.h>

// asks for a number from 1 - 12 and then prints the corr. month

int main()

{

int x;

printf ("Enter number:");

scanf ("%d", &x);

{

if (x==1) {printf ("January");}

else if (x==2) {printf ("February");}

else if (x==3) {printf ("March");}

else if (x==4) {printf ("April");}

else if (x==5) {printf ("May");}

else if (x==6) {printf ("June");}

else if (x==7) {printf ("July");}

else if (x==8) {printf ("August");}

else if (x==9) {printf ("September");}

else if (x==10) {printf ("October");}

else if (x==11) {printf ("November");}

else {printf ("December");}

}

system ("pause");

return 0;

}

====

#include <stdio.h>

// displays the Pascal's triangle

int main()

{

int x=8,y;

int a,k;

int coeff=0

for(a=0;a<=x;a++)

{

for(k=0;k<=a;k++)

{

coeff=factorial(a)/factorial(k)*factorial(a-k)

printf("%d", coeff);

}

printf ("

");

}

return 0;

}

int factorial (int a)

{

int k,c=1;

for(k=1;k<=a;k++){

c=c*k;

}

return c;

CS CodesWhere stories live. Discover now