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

C Assignment

The document contains 6 code snippets that demonstrate different programming concepts in C: 1) A program to find the largest of three numbers using if-else statements. 2) A program that takes a grade as input and displays the equivalent description using a switch statement. 3) A program that reads 10 numbers from the user, calculates their sum and average using a for loop. 4) A program that demonstrates the output of a code with multiple post-increment operations. 5) A program that swaps two numbers by passing them to a function. 6) A program that checks if a given number is even or odd using a function.

Uploaded by

amani
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)
63 views6 pages

C Assignment

The document contains 6 code snippets that demonstrate different programming concepts in C: 1) A program to find the largest of three numbers using if-else statements. 2) A program that takes a grade as input and displays the equivalent description using a switch statement. 3) A program that reads 10 numbers from the user, calculates their sum and average using a for loop. 4) A program that demonstrates the output of a code with multiple post-increment operations. 5) A program that swaps two numbers by passing them to a function. 6) A program that checks if a given number is even or odd using a function.

Uploaded by

amani
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

1.

what a c program to find the largest of three numbers and draw the flow chart
#include<stdio.h>

int main()

int A,B,C,largest;

printf("enter three numbers:\n");

scanf("%d%d%d", &A,&B,&C);

if(A>B&&A>C)

largest=A;

else

largest=C;

if(B>A&&B>C)

largest=B;

else

largest=C;

printf("largest number is:%d\n",largest);

return 0;

2.write a program in c that accept a grade as an input and display the equivalent description
as shown in the table below. (hint: using switch statement)

Input output
E Excellent
V Very good
G Good
A Average
F Fail
#include <stdio.h>
#include <ctype.h>
#include <string.h>
void main()
{
char notes[15];
char grd;
printf("Input the grade :");
scanf("%c", &grd);
grd = toupper(grd);
switch(grd)
{
case 'E':
strcpy(notes, " Excellent");
break;
case 'V':
strcpy(notes, " Very Good");
break;
case 'G':
strcpy(notes, “ Good “);
break;
case ‘A’:
strcpy(notes, “ Average”);
break;
case ‘F’:
strcpy(notes, “ Fails”);
break;
default :
strcpy(notes, “Invalid Grade Found. \n”);
break;
}
printf(“You have chosen : %s\n”, notes);
}
3.write a program in c to read 10 numbers from keyboard and find their sum and average
(hint: use for loop) #include<stdio.h>
#include<stdio.h>
int main()
{
int i,n,sum=0;
float avg;
printf("input the 10 numbers:\n");
for(i=1;i<=10;i++)
{
printf("number -d%:",i);
scanf("%d",&n);
sum+=n;
}
avg=sum/10.0;
printf("the sum of 10 number is%d :\n average is :%f\n",sum,avg);}

4.find the out put of the following program.


#include<stdio.h>
int main()
{
int y=10;
if(y++>20&&y++!=10&&y++<11)
printf("%d",y);
else
printf("%d",y);
}
→the output is 11
5.write a program in c to swap two numbers using function.
#include<stdio.h>
void swap(int x,int y);
void main()
{
int x=12,y=20;
swap(x,y);
printf("before swap\n x=%d y=%d\n",x,y);}
void swap(int x,int y)
{
int temp;
temp=x;
x=y;
y=temp;
printf("after swap\n x=%d y=%d\n",x,y);
}
6.write a program in c to check a given number is even or odd using the function.
#include<stdio.h>
void even(int number);
int main()
{
int num;
printf("Enter an integer:");
scanf("%d", &num);
even(num);
}
void even(int number)
{
if(number%2==0)
printf("%d is an even number\n",number);
else
printf("%d is an odd number\n",number);
}

You might also like