0% found this document useful (0 votes)
24 views6 pages

C Prog Week 4

Uploaded by

ssdharshini24
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
24 views6 pages

C Prog Week 4

Uploaded by

ssdharshini24
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 6

join FG Community: https://chat.whatsapp.

com/HWWkzXOgYld0esBGSYmFRT

Admin/ Gang Leader: Kavish

Assignments by: The Hairline

C Prog Week 4:

1. D
2. 8
3. B, E
4. 12
5. 7
6. B, D
7. C
8. C
9. 11
10. 8
11. A
12. 10
13. 10
14. A
15. A

GRPA 1:

#include<stdio.h>

int main(){

int num,numrev=0,i;

scanf("%d",&num);

for(i=num;i!=0;i=i/10){

numrev=numrev*10 + i%10;}

if(num==numrev){

printf("%d is a palindrome number",num);}

else{

printf("%d is not a palindrome number",num);}

return 0;}
GRPA 2:

#include <stdio.h>

int main(){

int num,prime=0,i;

scanf("%d",&num);

if(num<=1){

prime=1;}

else{

for(i=2;i<num;i++){

if(num%i==0){

prime=1;

break;}}}

if(prime==0){

printf("%d is a prime number",num);}

else{

printf("%d is not a prime number",num);}

return 0;}

GRPA 3:

#include <stdio.h>

int main(){

int a,b,c;

scanf("%d %d %d",&a,&b,&c);

if((a*a)==(b*b + c*c) || (b*b)==(a*a + c*c) || (c*c)==(b*b + a*a)){

printf("YES");}

else{

printf("NO");}

return 0;}
GRPA 4:

#include<stdio.h>

int main(){

float a,b;

scanf("%f %f",&a,&b);

if(a==0 && b==0){printf("Origin");}

else if(a==0 && b!=0){printf("y-axis");}

else if(a!=0 && b==0){printf("x-axis");}

else if(a<0 && b<0){printf("Third");}

else if(a>0 && b>0){printf("First");}

else if(a<0 && b>0){printf("Second");}

else{printf("Fourth");}

return 0;

GRPA 5:

#include<stdio.h>

int main(){

int n,sum=0,i,j;

scanf("%d",&n);

for(i=1;i<=n;i++){

for(j=1;j<=i;j++){

sum+=j;}}

printf("%d",sum);

return 0;}
GRPA 6:

#include<stdio.h>

int main(){

double weight,cost;

int zone;

scanf("%lf %d",&weight,&zone);

if(weight>0){

switch(zone){

case 1:

cost=weight*5;

printf("%.2lf",cost);

break;

case 2:

cost=weight*7;

printf("%.2lf",cost);

break;

case 3:

cost=weight*10;

printf("%.2lf",cost);

break;

case 4:

cost=weight*12;

printf("%.2lf",cost);

break;

case 5:

cost=weight*16;

printf("%.2lf",cost);

break;
case 6:

cost=weight*17;

printf("%.2lf",cost);

break;

case 7:

cost=weight*19;

printf("%.2lf",cost);

break;

default:

printf("Invalid Input");}}

else{printf("Invalid Input");}

return 0;}

GRPA 7:

#include<stdio.h>

int main(){

int n,total=0,i=0,num;

scanf("%d",&n);

for(i;i<n;i++){

scanf("%d",&num);

total+=num;}

printf("%d",total);

return 0;}
GRPA 8:

#include<stdio.h>

int main(){

double num,total=0;

char chac='y';

for(chac;chac=='y';scanf("%c",&chac)){

scanf("%lf\n",&num);

total+=num;}

printf("%.2lf",total);

return 0;

You might also like