C Programlama Ödevleri
Türkçeyi katletme durumundayım çünkü ödev böyleydi. Neyse zaten soruyu anlamıyorsanız ödeviniz değildir. Soruyu anlamasanızda kodları çalıştırarak ne işlev yaptığını görüp, faydalanabilirsiniz.
Soru;
4.8 What does this program print?
|
#include <stdio.h> /* function main begins program execution */ int main() { int x; int y; int i; int j; /* prompt user for input */ printf( “Enter two integers in the range 1-20: ” ); scanf( “%d%d”, &x, &y ); /* read values for x and y */ for ( i = 1; i <= y; i++ ) { /* count from 1 to y */ for ( j = 1; j <= x; j++ ) { /* count from 1 to x */ printf( “@” ); /* output @ */ } /* end inner for */ printf( “\n” ); /* begin new line */ } /* end outer for */ return 0; /* indicate program ended successfully */ } /* end function main */ |
Cevap;
When you run the program, it will want to enter two integer in range 1-20. After will add “@”. Your first enter value is line number and second column number.
Soru;
4.9 Write a program that sums a sequence of integers. Assume that the first integer read with scanf specifies the number of values remaining to be entered. Your program should read only one value each time scanf is executed. A typical input sequence might be
5 100 200 300 400 500
Where the 5 indicates that the subsequent five values are to be summed.
Cevap;
#include <stdio.h>
int main()
{
int num=0;
int num_of_ints=0;
int c=0;
int sum=0;
printf(”Please enter number of integers you will submit:”);
scanf(”%d”,&num_of_ints);
for(c=1;c<=num_of_ints;c++)
{
printf(”Enter Number %i:\n”, num);
scanf(”%d”,&num);
sum = sum + num;
}
printf(”Total of numbers enter: %d\n”,sum);
return 0;
}
4.14 The factorial function is used frequently in probability problems. The factorial of a positive integer n (written n! and pronounced “n factorial”) is equal to the product of the positive integers from 1 to n. Write a program that evaluates the factorials of the integers from 1 to 5. Print the results in tabular format. What difficulty might prevent you from calculating the factorial of 20?
Cevap;
#include <iostream.h>
main()
{
#include<stdio.h>
int c(int a);
main()
{
int a;
printf(”Enter a number:”);
scanf(”%d”,&a);
printf(”The factorial number is: “);
printf(”%d”,c(a));
return 0;
}
int c(int a)
{
int b,z;
b=1;
for(z=1;z<=a;z++){
b=b*z;
}
return b;
}
Soru;
5. Consider the function given in Fig. 5.3 (Locate the file fig05_03.c in Book Resources) on page 156 of your textbook. Modify this program so that the program outputs the cube of each input (integer) value. Make all necessary name changes.
/* Fig. 5.3: fig05_03.c
Creating and using a programmer-defined function */
#include <stdio.h>
int square( int y ); /* function prototype */
/* function main begins program execution */
int main( void )
{
int x; /* counter */
/* loop 10 times and calculate and output square of x each time */
for ( x = 1; x <= 10; x++ ) {
printf( “%d “, square( x ) ); /* function call */
} /* end for */
printf( “\n” );
return 0; /* indicates successful termination */
} /* end main */
/* square function definition returns square of parameter */
int square( int y ) /* y is a copy of argument to function */
{
return y * y; /* returns square of y as an int */
} /* end function square */
Cevap;
#include <stdio.h>
int cube( int y ); /* function prototype */
/* function main begins program execution */
int main(void)
{
int x; /* counter */
/* loop 10 times and calculate and output cube of x each time */
for ( x = 1; x <= 10; x++ ) {
printf( “%d “, cube( x ) ); /* function call */
} /* end for */
printf( “\n” );
return 0; /* indicates successful termination */
} /* end main */
/* square function definition returns cube of parameter */
int cube( int y ) /* y is a copy of argument to function */
{
return y * y*y; /* returns cube of y as an int */
} /* end function cube */
Kopyalamak degilde , oturup elle bakarak yazmak daha kalıcı ve egitici zaten copy paste yapmaya izin vermiyor site anladıgım kadarıyla…