Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <stdio.h>
- int main()
- {
- float a1, d, sum;
- int num, code , i;
- printf("Enter rhe first element (real), the difference (real) and the number of elements:");
- do {
- scanf("%f%f%d", &a1,&d, &num);
- if (scanf("%f%f%d", &a1,&d, &num)==1)
- break;
- else
- printf("iilegal input, try agian");
- } while(1);
- do {
- printf("Enter a code for desired operation from the menu :\n 1-display an aritmetic progression\n 2-display an aritmetic series\n 3 -display a geometric progression\n 4-display a geometric series\n 5 - exit the program\n");
- scanf("%d", &code);
- if (code==1) {
- for(i=0; i<num; i++)
- printf("%f" ,a1+i*d);
- }
- else if (code==2) {
- sum=0;
- for(i=0; i<num; i++)
- sum+= a1+i*d;
- printf("%f", sum);
- }
- else if (code==3) {
- printf("%f" ,a1);
- for (i=1; i<num; i++)
- printf("%f" ,a1*=d);
- }
- else if (code==4) {
- sum=a1;
- for (i=1; i<num; i++) {
- a1*=d;
- sum+= a1; }
- printf("%f", sum);
- }
- else if (code==5){
- printf("bye");
- break; }
- else
- printf("iilegal input, try agian");
- } while (1);
- retuern 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement