C programming Lab report
C programming Lab report
Lab Report
Output -
Page|2
3. WAP to do simple arithmetic
operations.
Program - include<stdio.h>
main(){
int a, b, c;
a = 9;
b = 8;
c = a + b;
printf("sum is %d\n",c);
c = a - b;
printf("Diffrence is %d\n",c);
c = a * b;
printf("Product is %d\n",c);
c = a / b;
printf("Quotient is %d\n",c);
c=a%b
}
Output –
Program – #include<stdio.h>
main(){
float a, b ,c;
printf("Enter First value\n");
scanf("%f", &a);
printf("Enter Second value\n");
scanf("%f", &b);
Page|3
c = a + b;
printf("The sum of %.2f and %.2f is %.2f",a ,b ,c);
}
Output-
Page|4
Output –
Page|5
6. Write a program to check a
condition.
Program –
#include<stdio.h>
main(){
float marks;
printf("enter your marks in C Programming\n");
scanf("%f", &marks);
Output -
Page|6
}
else if (b>a && b>c){
printf("b is the greater number");
}
else {
printf("c is the greater number");
}
}
Output -
Page|7
8. WAP to find largest and smallest number from three
numbers.
Program –
#include<stdio.h>
main(){
int a, b, c;
printf("Enter the first no a:\n");
scanf("%d",&a);
printf("Enter the second no b:\n");
scanf("%d",&b);
printf("enter the third no c:\n");
scanf("%d",&c);
if(a>b &&a>c){
printf("a is the largest no.\n");
}
else if(b>a && b>c){
printf("b is the largest no.");
}
else{
printf("c is the largest no.");
}
}
Output –
Page|8
if(marks <=100 && marks >90){
printf("Your Grade is A");
}
else if(marks <=90 && marks >80){
Page|9
printf("Your Grade is A-");
}
else if(marks <=80 && marks >70){
printf("Your Grade is B");
}
else if(marks <=70 && marks >60){
printf("Your Grade is B-");
}
else {
printf("No Grade");
}
}
Output –
Page|10
printf("wait for a while, Thank you!");
Page|11
break; case
405 :
printf("your Sandwitch is getting ready\n");
printf("wait for a while, Thank you!");
break;
default:
printf("Please choose another item\n");
}
}
Output –
Page|12
12. Write a progam to find the sum of n natural
numbers. Program –
#include<stdio.h>
main(){
int n, i, sum = 0;
#include<stdio.h>
main(){
int n;
printf("Enter any whole number\n");
scanf("%d", &n);
if (n %2 != 0)
printf("the number %d is odd", n);
else
printf("The number %d is even", n);
}
Page|13
Output -
Page|14
15. Write a program to find if the given number is prime number or
not. Program –
#include<stdio.h>
main() {
int n, i, x=0;
printf("Enter a Whole number\n");
scanf("%d", &n);
for(i=2; i<n; i++){
if(n % i == 0){
x=1;
break;
}
}
if(x == 0)
printf("The number %d is Prime Number", n);
else
printf("The number %d is Not Prime Number", n);
}
Output –
Page|15
}
Page|16
Output -
Page|17
18. Write a program to create a half pyramid with n number of
rows.Program –
#include<stdio.h>
main(){
int i, j, rows;
printf("Enter number of rows\n");
scanf("%d", &rows);
for(i=1; i<= rows; ++i){
for(j=1; j<=i; ++j){
printf("* ");
}
printf("\n");
}
}
Output –
Page|18
printf("a=%d\n",a);
printf("b=%d",b);
}
#include<stdio.h>
main(){
int i, rev=0,n ,r,a;
printf("Enter the number:");
scanf("%d",&n);
a=n;
while(n!=0){
r=n%10;
rev=rev*10+r;
Page|19
n=n/10;
}
printf("%d\n",a);
printf("%d\n",rev);
if(rev==a){
printf("The given number %d is Palindrime\n",a);
}
else{
printf("The given number %d is not Palindrime\n",a);
}
}
#include<stdio.h>
int sum(int n);
main(){
int s,num;
printf("Enter the number of term you want to sum:\n");
scanf("%d",&num);
s=sum(num);
printf("the sum of %d term is%d",num,s);
}
int sum(int n){
if(n!=0){
return n+sum(n-1);
}else{
return n;
}
Page|20
23. WAP to pass string to the function.
#include<stdio.h>
showString(char str[]);
main(){
char string[10];
printf("Enter the string:\n");
gets(string);
showString(string);
printf("Enter the string:\n");
gets(string);
showString(string);
}
showString(char str[]){
char letter;
Page|21
int islowercasevowel, isuppercasevowel;
if(islowercasevowel||isuppercasevowel){
printf("%c is vowel",letter);
}
else{
printf("%c is consonant", letter);
}
}
25. WAP to count number of consonant vowel and space in given array.
#include<stdio.h>
#include<string.h>
main(){
int v, c,i, s;
v=c=s=0;
char strings[20];
Page|22
printf("The number of consonant letter is %d\n",c);
printf("The number of space is %d\n",s);
}
Page|23
27. WAP to arrange array of numbers in descsending order.
#include<stdio.h>
main(){
int i,j,temp,n;
char arr[20];
printf("Enter how many number you want to enter:\n");
scanf("%d",&n);
//taking array of number
printf("Enter the array of number:\n");
for(i=0;i<n;i++){
printf("Enter number %d:\n",i+1);
scanf("%d",&arr[i]);
}
//display array of number
for(i=0;i<n;i++){
printf("%d,",arr[i]);
}
//sorting array
for(i=0;i<n;i++){
for(j=i+1;j<n;j++){
if(arr[i]<arr[j]){
temp=arr[j];
arr[j]=arr[i];
arr[i]=temp;
}
}
}
Page|24
//display array
printf("\nThe sorted array is:\n");
for(i=0;i<n;i++){
printf("%d,",arr[i]);
}
28. WAP to enter the info of employee and display whose salary is greater thn 50000.
#include<stdio.h>
#include<conio.h>
struct employee{
int emplid;
char name[10];
int salary;
};
main(){
int i;
struct employee E[5];
//to enter info
for(i=0;i<2;i++){
printf("Enter your employee id:\n");
scanf("%d",&E[i].emplid);
printf("Enter your name:\n");
scanf("%s",&E[i].name);
printf("Enter your salary:\n");
Page|25
scanf("%d",&E[i].salary);
}
};
struct student{
int roll;
char name[30];
float marks;
struct date doj;
};
main(){
int n,i;
struct student std[40];
Page|26
scanf("%d",&n);
for(i=0;i<n;i++){
printf("Enter the roll number\n");
scanf("%d",&std[i].roll);
printf("Enter the name\n");
scanf("%s",std[i].name);
printf("Enter the marks\n");
scanf("%f",&std[i].marks);
printf("E")
}
printf("you have entered\n");
for(i=0;i<n;i++){
printf("name:%s\troll:%d\tmarks:%.f\n",std[i].name,std[i].roll,std[i].marks);
}
}
Page|27
int i,n;
FILE *fp;
fp=fopen("thames student.txt","w");
printf("Enter the number of student:\n ");
scanf("%d",&n);
for(i=0;i<n;i++){
printf("enter a roll number \n");
scanf("%d",&std[i].roll);
scanf("%c",&std[i].temp);
printf("enter a name\n");
gets(std[i].name);
printf("enter the marks\n");
scanf("%f",&std[i].marks);
fwrite(&std[i],sizeof(std[i]),1,fp);
}
fclose(fp);
}
Page|28