2) WAP to display all the numbers from 100 to 200 divisible by 4
1 2 3 4 5 |
#include<stdio.h> void main(){ for(int i=100;i<=200;i++) i%4==0? printf("%d ",i):i; } |
3) Create a function int greater(int ,int ) that returns greater number.
1 2 3 |
int greater(int a,int b){ return a>b? a : b; } |
5)check if string is palindrome or not
1 2 3 4 5 6 7 8 9 10 11 12 |
#include<stdio.h> #include<string.h> void main(){ char string[100],temp[100]; printf("enter string"); gets(string); strcpy(temp,string); strrev(string); if(strcmp(string,temp)==0) printf("the string is palindrome"); else printf("the string is not palindrome"); } |
6)A data file contains name ,age ,address,cell number of some students WAP to list all the students who are from”Pokhara”.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 |
#include<stdio.h> void main(){ char name[20],address[20]; int age,number; FILE *ptr; ptr= fopen("stdent.dat","r"); if(ptr==NUll) exit(0); while(!feof(ptr)){ fscanf(ptr,"%s %d %s %d\n",name,&age,&address,&number) if(strcmp(address,"Pokhara")==0) printf("%s %d %s %d\n",name,age,address,number) } fclose(ptr); } |
7)WAP to input 10 integers in an array and find the maximum and minimum.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 |
#include<stdio.h> void main(){ int a[10],max,min,i; printf("enter 10 numbers\n"); for(i=0;i<10;i++) scanf("%d",&a[i]); max = a[0]; min = a[0]; for(i=1;i<10;i++){ if(a[i]>max) max = a[i]; if(a[i]<min) min = a[i]; } printf("the max is %d and min is %d",max,min); } |
8) Create a structure named Employee with data members name,salary and address .take the data of 5 employees and display the number of employee whose salary > 10000.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 |
#include<stdio.h> struct Employee{ char name[20],address[20]; int salary; }s[5]; void main(){ int i; printf("enter records of 5 employees\n"); for(i=0;i<5;i++) scanf("%s %s %d",s[i].name,s[i].address,&s[i].salary); for(i=0;i<5;i++){ if(s[i].salary > 10000) printf("%s",s[i].name); } } |